今天碰到一个问题,某栏目下即需要分类文章又需要分类

时间: 2015-08-21 / 分类: wordpress / 浏览次数: 3,382 views / 0个评论 发表评论

联系我们(菜单上主分类,目标是跳转到第一篇文章,ID6)

联系我们(第一篇文章)
技术支持(第二篇文章)
文档下载(分类,其下也有很多文章,ID24)

然后我用原来的程序~一点“文档下载”就自动跳转到“文档下载”的第一篇文章

也就是有错误~看来必须得改进

然后打开category.php,把判断in_category(‘6’) || post_is_in_descendant_category( ‘6’)改为只判断一个栏目$cat==6

然后专门单独弄一份24栏目的模版category-24.php,注意6栏目下多少个子栏目就弄多少份模版,当然也可以用程序判断一下,但是现在只有一个栏目我就懒得弄了

注意它左边的导航,需要有文章也需要分类

<ul id="catlist_box">
<!– 下级文章和分类 –>
<?php
$recentPosts = new WP_Query();
$recentPosts->query(‘showposts=20&cat=’.$thistopid.’&orderby=ID&order=ASC&category__not_in=24′);// cate:栏目ID
?>
<?php while ($recentPosts->have_posts()) : $recentPosts->the_post(); ?>
<li><a href="<?php the_permalink() ?>" ><?php the_title(); ?></a></li>
<?php endwhile; ?>
<?php
wp_reset_query();//所有查询完再恢复默认查询
//但是联系我们6既有文章又有分类,下面要显示这个分类
if( (post_is_in_descendant_category( ‘6’) or is_category( ‘6’ ) or in_category(‘6’))){
if(is_category()) {
$topcat=get_category_root_id($cat);//顶级分类的ID
}else if(is_single()) {
$categories_list = get_the_category();//获取当前类别信息
$cat_ID=$categories_list[0]->cat_ID;//取得第一个类别的id号
$parent_ID= get_category_root_id($cat_ID);//获取顶级类别id号
$topcat= $parent_ID;
$myCat = $cat_ID;//所在子栏目
//echo $myCat;
}
if(is_single()) {$currentcategory = ‘&current_category=’.$myCat;}//修复在POST页面无法获取所在子栏目
wp_list_categories(‘orderby=id&show_count=99
&hide_empty=0&title_li=&show_count=0&use_desc_for_title=0&child_of=’.$topcat.$currentcategory);
}
?>

</ul>

然后那两篇文章的模版可以直接套用single-contact.php的模版~但是左边导航也得修改一下

<?php
$nowid= get_the_ID();
$recentPosts = new WP_Query();
$recentPosts->query(‘showposts=20&cat=’.$thistopid.’&orderby=ID&order=ASC&category__not_in=24′);// cate:栏目ID
?>
<?php while ($recentPosts->have_posts()) : $recentPosts->the_post(); ?>
<li class="<?php if( $nowid==get_the_ID()){echo "current-cat";} ?>"><a href="<?php the_permalink() ?>" ><?php the_title(); ?></a></li>
<?php endwhile; ?>
<?php
wp_reset_query();//所有查询完再恢复默认查询
//但是联系我们6既有文章又有分类,下面要显示这个分类
if( (post_is_in_descendant_category( ‘6’) or is_category( ‘6’ ) or in_category(‘6’))){
if(is_category()) {
$topcat=get_category_root_id($cat);//顶级分类的ID
}else if(is_single()) {
$categories_list = get_the_category();//获取当前类别信息
$cat_ID=$categories_list[0]->cat_ID;//取得第一个类别的id号
$parent_ID= get_category_root_id($cat_ID);//获取顶级类别id号
$topcat= $parent_ID;
$myCat = $cat_ID;//所在子栏目
//echo $myCat;
}
if(is_single()) {$currentcategory = ‘&current_category=’.$myCat;}//修复在POST页面无法获取所在子栏目
wp_list_categories(‘orderby=id&show_count=99
&hide_empty=0&title_li=&show_count=0&use_desc_for_title=0&child_of=’.$topcat.$currentcategory);
}
?>
</ul>

显示文章那里还做了当前栏目的兼容

发表评论

您的昵称 *

您的邮箱 *

您的网站