小编Sta*_*us4的帖子

Wordpress自定义帖子类型类别

嘿.我在wordpress中使用自定义帖子类型.我注册这样的自定义帖子类型:

        register_post_type("lifestream", array(
            'label' => 'Lifestream',
            'public' => true,
            'hierarchical' => true,
            'menu_position' => 5,
            'supports' => array('title','editor','author','thumbnail','comments','custom-fields'),
            'taxonomies' => array('category','post_tag'),
            'query_var' => true,
            'publicly_queryable' => true,
            'exclude_from_search' => false,
            'caller_get_posts' => 1

        ));
        register_taxonomy_for_object_type('category', 'lifestream');
        register_taxonomy_for_object_type('post_tag', 'lifestream');
Run Code Online (Sandbox Code Playgroud)

在主题(循环模板)中我喜欢组合帖子和我的自定义帖子类型,因为我使用query_posts()与这些参数:

$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array(
    'post_type' => array('post', 'lifestream'),
    'paged' => $paged,
    'cat' => $wp_query->get('cat'),
    'tag' => $wp_query->get('tag'),
    'year' => $wp_query->get('year'),
    'monthnum' => $wp_query->get('monthnum'),
    'post_status' => 'publish',
    'showposts' => 3
);
query_posts($args); 


# the loop     
while …
Run Code Online (Sandbox Code Playgroud)

php wordpress themes categories custom-post-type

6
推荐指数
1
解决办法
2318
查看次数

标签 统计

categories ×1

custom-post-type ×1

php ×1

themes ×1

wordpress ×1