You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

WordPress职位与简历板块故障排查及短代码开发求助

WordPress职位与简历板块故障排查及短代码开发求助

嘿,看起来你已经迈出了很棒的第一步——成功注册了自定义文章类型和相关分类!我来一步步帮你把这个功能跑起来,再搞定短代码的事儿:

一、先确认现有代码的基础功能是否正常

你的代码已经帮你注册了「Jobs & Resumes」自定义文章类型和对应的分类/标签,现在先确保基础功能没问题:

  • 首先检查Code Snippets插件里的这段代码是否处于激活状态:进入后台「Snippets」菜单,找到你添加的代码,确认它的状态是Active。
  • 试试添加测试内容:点击后台的「Jobs & Resumes」→「Add New」,随便填个标题、内容,选个分类,发布后去前台访问 你的域名/job-resume/ 看看归档页能不能正常加载;或者直接点击发布后的内容链接,确认单页能打开。
  • 如果链接打不开,记得刷新固定链接:进入后台「设置」→「固定链接」,不用改任何设置,直接点「保存更改」,让WordPress更新重写规则,自定义文章类型的链接就能正常解析了。

二、开发短代码,把内容展示到页面上

现在给你写一个可以直接用的短代码,添加后就能在任意页面/post里插入标签展示职位/简历列表:

把下面这段代码添加到Code Snippets插件里(可以和你现有的代码放在同一个Snippet,也可以新建一个):

// 注册职位与简历列表短代码
function job_resume_list_shortcode($atts) {
    // 短代码可自定义参数,默认值如下
    $args = shortcode_atts(array(
        'posts_per_page' => 10, // 每页显示数量
        'category' => '', // 指定分类的slug,留空则显示所有分类
        'orderby' => 'date', // 排序依据:date(日期)/title(标题)等
        'order' => 'DESC' // 排序顺序:DESC(降序)/ASC(升序)
    ), $atts);

    // 查询已发布的职位/简历内容
    $query = new WP_Query(array(
        'post_type' => 'job-resume',
        'posts_per_page' => $args['posts_per_page'],
        'job-resume-category' => $args['category'],
        'orderby' => $args['orderby'],
        'order' => $args['order'],
        'post_status' => 'publish'
    ));

    // 没有内容时返回提示
    if (!$query->have_posts()) {
        return '<p>暂无职位或简历信息</p>';
    }

    // 构建列表的HTML结构
    $output = '<div class="job-resume-list">';
    while ($query->have_posts()) {
        $query->the_post();
        
        // 获取并格式化分类标签
        $categories = get_the_terms(get_the_ID(), 'job-resume-category');
        $category_html = '';
        if ($categories && !is_wp_error($categories)) {
            $category_links = array();
            foreach ($categories as $category) {
                $category_links[] = '<a href="' . get_term_link($category) . '">' . $category->name . '</a>';
            }
            $category_html = '<div class="job-resume-category">' . implode(', ', $category_links) . '</div>';
        }

        $output .= '<div class="job-resume-item">
            <h3><a href="' . get_permalink() . '">' . get_the_title() . '</a></h3>
            ' . $category_html . '
            <div class="job-resume-excerpt">' . get_the_excerpt() . '</div>
            <a class="job-resume-read-more" href="' . get_permalink() . '">查看详情</a>
        </div>';
    }
    $output .= '</div>';

    // 重置WordPress查询,避免影响后续内容
    wp_reset_postdata();

    return $output;
}
// 注册短代码,前台用[job_resume_list]调用
add_shortcode('job_resume_list', 'job_resume_list_shortcode');

短代码的使用方法

  • 激活这段代码后,新建或编辑页面,在编辑器里插入短代码:
    • 显示默认10条内容:[job_resume_list]
    • 自定义参数示例:[job_resume_list posts_per_page="5" category="web-developer" order="ASC"](显示分类为web-developer的5条内容,按日期升序排列)
  • 代码里的HTML类名(比如job-resume-list、job-resume-item)你可以根据自己的主题样式修改,方便后续加CSS美化。

三、额外优化建议

  • 如果需要支持简历附件上传,可以在自定义文章类型的supports数组里添加'custom-fields',或者用Advanced Custom Fields插件添加文件上传字段,这样用户提交简历时能上传文件。
  • 要是想做前端提交简历的功能,可以额外写表单处理代码,用wp_insert_post()函数把用户提交的内容保存到自定义文章类型里。

备注:内容来源于stack exchange,提问作者Thiarara

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.23 07:53:07