【发布时间】:2016-10-25 15:48:02
【问题描述】:
我会知道如何在 Wordpress 类别页面 (category.php) 上获取子类别和该子类别的帖子?
我现在下面有这段代码,我想在“echo 'test';”的位置显示父类别的帖子。
<?php
$args = array('child_of' => get_query_var('cat') );
$categories = get_categories( $args );
$numOfItems = 20; // Set no of category per page
$page = isset( $_GET['cpage'] ) ? abs( (int) $_GET['cpage'] ) : 1;
$to = $page * $numOfItems;
$current = $to - $numOfItems;
$total = sizeof( $categories );
echo '<ul class="cat-content">';
for( $i=$current; $i<$to; ++$i ) {
$category = $categories[$i];
if( $category->name ) {
echo '<li><h2>'. $category->name.'</h2>';
echo 'test';
echo '</li>';
}
}
echo '</ul>';
unset( $category );
?>
【问题讨论】:
标签: php wordpress categories posts