wordpress分类列表显示子分类文章cms列表

近日大挖在给客户仿制一款wordpress院校主题时,需要在分类列表页面下面以文章cms模块的形式显示子分类列表,通过搜索获得以下代码,可以灵活运用在不同的分类模版下。把该段代码添加到主题的分类模版文件中调用即可使用。

<?phpglobal $cat;

$cats = get_categories(array(

‘child_of’ => $cat,

‘parent’ => $cat,

‘hide_empty’ => 0

));

$c = get_category($cat);

if(empty($cats)){

?>

<div class=“item”>

<?php if (have_posts()) : while (have_posts()) : the_post(); ?>

<div class=“post”>

<h2><a title=“<?php the_title(); ?>“ href=“<?php the_permalink(); ?>“><?php the_title(); ?></a></h2>

<p><?php the_excerpt(); ?></p>

<p><a href=“<?php the_permalink(); ?>“>全文阅读>></a></p>

<div class=“meta”><?php the_time(‘Y-m-d’); ?> | 标签: <?php the_tags(”, ‘ , ‘, ”); ?></div>

</div>

<?php endwhile; ?>

<?php else: ?>

<div class=“post”><p>文章稍后更新</p></div>

<?php endif; ?>

</div>

<div class=“navigation”>

<span class=“alignleft”><?php next_posts_link(‘&laquo; Older posts’) ?></span>

<span class=“alignright”><?php previous_posts_link(‘Newer posts &raquo;’) ?></span>

</div>

<?php

}else{

foreach($cats as $the_cat){

$posts = get_posts(array(

‘category’ => $the_cat->cat_ID,

‘numberposts’ => 10,

));

if(!empty($posts)){

echo ‘

<div class=”item cat_item”>

<div class=”item_title”><h2><a title=”‘.$the_cat->name.‘” href=”‘.get_category_link($the_cat).‘”>’.$the_cat->name.‘</a></h2></div>

<ul class=”box_list”>’;

foreach($posts as $post){

echo ‘<li><span class=”alignright”>’.mysql2date(‘Y-m-d’, $post->post_date).‘</span>

<a title=”‘.$post->post_title.‘” href=”‘.get_permalink($post->ID).‘”>’.$post->post_title.‘</a></li>’;

}

echo ‘</ul>

</div>’;

}

}

}

?>
1、本站所有资源来源于用户上传和网络,版权争议与本站无关,版权归原创者所有,如有侵权请邮件联系我们!
2、分享目的仅供大家学习和交流,您必须在下载后24小时内删除!
3、不得使用于非法商业用途,商用请购买正版,不得违反国家法律。否则后果自负!
4、本站提供的源码、模板、插件等等其他资源,都不包含技术服务请大家谅解!
5、如有链接无法下载、失效或广告,请联系管理员处理!
6、本站资源售价只是赞助,收取费用仅维持本站的日常运营所需!
7、不保证所有资源都完整可用,不排除存在加密、BUG、需要授权或者残缺的可能,由于资源的特殊性,下载后一律不予退货!
8、本文来自炫客网搜集整理,如有侵权请联系管理员删除,转载请注明出处:https://www.xuankewang.com/314.html

联系我们

173-662-005

在线咨询: QQ交谈

邮件:woowuo@126.com

工作时间:周一至周五,10:30-18:30,节假日休息

关注微信
我已知晓并同意