最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Can %year%%monthnum%%day% structure tags be added to custom post type permalinks?

programmeradmin3浏览0评论

Just wondering if anyone had tried using any of the structure tags available to post permalinks with custom post types... I'm moving my "listings" posts on a site I manage from a category hack under Posts to their own custom post type, but I'd like to still keep some sort of numeric date reference in the permalink structure. How difficult is that to set up?

Just wondering if anyone had tried using any of the structure tags available to post permalinks with custom post types... I'm moving my "listings" posts on a site I manage from a category hack under Posts to their own custom post type, but I'd like to still keep some sort of numeric date reference in the permalink structure. How difficult is that to set up?

Share Improve this question asked Apr 9, 2011 at 17:16 goldenapplesgoldenapples 9,2662 gold badges33 silver badges39 bronze badges 1
  • This process, and other issues related to custom post type permalinks, are described more fully on the Shiba Shake Blog. – MadPress Commented Apr 10, 2011 at 11:19
Add a comment  | 

1 Answer 1

Reset to default 2

Yes, you should be able to use date based URLs by using the permalink_epmask parameter with your register_post_type call..

add_action('init', 'wpse14370_custom_init');
function wpse14370_custom_init() {
    $args = array(
        'public' => true,
        'publicly_queryable' => true,
        'show_ui' => true, 
        'show_in_menu' => true, 
        'query_var' => true,
        'rewrite' => true,
        'capability_type' => 'post',
        'has_archive' => true, 
        'hierarchical' => false,
        'menu_position' => null,
        'permalink_epmask' => EP_DATE,
        'supports' => array('title','editor','author','thumbnail','excerpt','comments')
  ); 
  register_post_type('book',$args);
}

Not sure exactly how custom endpoints work, but it's supported according to the codex page.
http://codex.wordpress/Function_Reference/register_post_type

And because it's not documented, here's all the possible endpoint values(though i don't know specifically which are supported with custom post types)..

EP_NONE
EP_PERMALINK
EP_ATTACHMENT
EP_DATE
EP_YEAR
EP_MONTH
EP_DAY
EP_ROOT
EP_COMMENTS
EP_SEARCH
EP_CATEGORIES
EP_TAGS
EP_AUTHORS
EP_PAGES
EP_ALL

If that doesn't work correctly, maybe just setting with_front to true will be enough if you're already using date based permalinks.

发布评论

评论列表(0)

  1. 暂无评论