2017-04-21 40 views
0

我想知道是否能够帮助我进行以下WordPress自定义。我们正在使用WP作业管理器插件(https://wpjobmanager.com/),并且需要一些帮助来进行slu// permalink编辑。需要关于WP作业管理器的代码段的帮助

在文档中有一篇文章解释了以下内容:在当前情况下,链接生成如下:domain.com/job/job-name。但是,我需要以下结构:domain.com/job-category/job-name。

请检查:https://wpjobmanager.com/document/tutorial-changing-the-job-slugpermalink/

的文章解释了这一点。请检查以下代码:示例:将类别添加到基本URL。当我在下面的代码中删除'工作'时,工作清单工作正常,但我的网站的其余部分返回404错误(在保存永久链接之后)。

$args['rewrite']['slug'] = 'job/%category%'; 

$args['rewrite']['slug'] = '%category%'; 

全码:

function job_listing_post_type_link($permalink, $post) { 
    // Abort if post is not a job 
    if ($post->post_type !== 'job_listing') 
     return $permalink; 

    // Abort early if the placeholder rewrite tag isn't in the generated URL 
    if (false === strpos($permalink, '%')) 
     return $permalink; 

    // Get the custom taxonomy terms in use by this post 
    $terms = wp_get_post_terms($post->ID, 'job_listing_category', array('orderby' => 'parent', 'order' => 'ASC')); 

    if (empty($terms)) { 
     // If no terms are assigned to this post, use a string instead (can't leave the placeholder there) 
     $job_listing_category = _x('uncat', 'slug'); 
    } else { 
     // Replace the placeholder rewrite tag with the first term's slug 
     $first_term = array_shift($terms); 
     $job_listing_category = $first_term->slug; 
    } 

    $find = array(
     '%category%' 
    ); 

    $replace = array(
     $job_listing_category 
    ); 

    $replace = array_map('sanitize_title', $replace); 

    $permalink = str_replace($find, $replace, $permalink); 

    return $permalink; 
} 
add_filter('post_type_link', 'job_listing_post_type_link', 10, 2); 

function change_job_listing_slug($args) { 
    $args['rewrite']['slug'] = 'job/%category%'; 
    return $args; 
} 
add_filter('register_post_type_job_listing', 'change_job_listing_slug'); 
+1

志愿者在这里堆栈溢出不收取他们的帮助,所以我编辑您的付款出的报价。只要问题中有足够的细节,并不是太宽泛的问题,你应该在这里得到帮助。 – halfer

+0

谢谢,我没有意识到这一点! – Festinger

回答

-1

嗯,我也陷在某些类型的错误一次。但就我而言,我创造了我自己的一切。所以我相应地更改模板。

但是,在你的情况下,我认为它涉及URL重写。请查看以下链接。我希望那些会有所帮助。

http://www.wpbeginner.com/plugins/how-to-change-custom-post-type-permalinks-in-wordpress/

https://codex.wordpress.org/Rewrite_API/add_rewrite_rule https://paulund.co.uk/rewrite-urls-wordpress

+0

感谢您的建议,但我无法编辑'工作'slu。。请查看此截图:http://imgur.com/4uU7cj3 – Festinger