如果不想附加默认的帖子类别分类法,可以始终为页面创建一个新的专门分类法。将此插入到functions.php
文件:
add_action( \'init\', \'create_page_taxonomies\' );
function create_page_taxonomies() {
register_taxonomy(\'page_category\', \'page\', array(
\'hierarchical\' => true,
\'labels\' => array(
\'name\' => _x( \'Page Category\', \'taxonomy general name\' ),
\'singular_name\' => _x( \'page-category\', \'taxonomy singular name\' ),
\'search_items\' => __( \'Search Page Categories\' ),
\'all_items\' => __( \'All Page Categories\' ),
\'parent_item\' => __( \'Parent Page Category\' ),
\'parent_item_colon\' => __( \'Parent Page Category:\' ),
\'edit_item\' => __( \'Edit Page Category\' ),
\'update_item\' => __( \'Update Page Category\' ),
\'add_new_item\' => __( \'Add New Page Category\' ),
\'new_item_name\' => __( \'New Page Category Name\' ),
\'menu_name\' => __( \'Page Categories\' )
),
\'public\' => true,
\'rewrite\' => array(
\'slug\' => \'page-category\',
\'with_front\' => false,
\'hierarchical\' => true
)
));
}
这是一个非常简单的新分类法,还有很多其他选项可用,其中有一个完整的列表
in the WP Codex.
UPDATE:
我相信这就是整个循环的样子:
<?php
wp_reset_query();
$query = new WP_Query(
array(
\'post_type\' => \'page\',
\'tax_query\' => array(
array(
\'taxonomy\' => \'page_category\',
\'field\' => \'term_id\',
\'terms\' => 541
)
)
)
);
if ( $query->have_posts() ) :
while ( $query->have_posts() ) : $query->the_post(); ?>
<div>
<?php
if ( has_post_thumbnail() ) :
the_post_thumbnail( array(150,150) );
else : ?>
<img class="alignleft" src="<?php echo get_bloginfo("template_url"); ?>/images/empty_150_150_thumb.gif" width="150" height="150" />
<?php
endif; ?>
<div class="entry">
<h3 class="blog_header"><a href="<?php echo get_permalink(); ?>" rel="bookmark" title="Permanent Link: <?php the_title(); ?>"><?php the_title(); ?></a></h3>
<?php the_excerpt(); ?>
<a class="button_link" href="<?php the_permalink(); ?>"><span>Read More</span></a>
</div>
</div>
<?php
endwhile;
endif; ?>