测速网在接受客户的wordpress仿站中项目中,需要在分类页面调用子分类的文章列表,类似的列表效果在很多cms程序中比较常见,但对于wordpress程序,可以使用下面的分类代码来完全功能的实现。
把以下代码调整后添加到主题的category.php文件:
area data-settings="dblclick" readonly ><?phpglobal $cat;$cats = get_categories(array('child_of' => $cat,'parent' => $cat,'hide_empty' => 0));$c = get_category($cat);if(empty($cats)){?><div ><?php if (have_posts()) : while (have_posts()) : the_post(); ?><div ><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 ><?php the_time('Y-m-d'); ?> | 标签: <?php the_tags('', ' , ', ''); ?></div></div><?php endwhile; ?><?php else: ?><div ><p>文章稍后更新</p></div><?php endif; ?></div><div ><span ><?php next_posts_link('« Older posts') ?></span><span ><?php previous_posts_link('Newer posts »') ?></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 ><div ><h2><a title="'.$the_cat->name.'" href="'.get_category_link($the_cat).'">'.$the_cat->name.'</a></h2></div> <ul >';foreach($posts as $post){echo '<li><span >'.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>';}}}?>area>16171819202122232425262728293031323334353637383940414243444546474849<?phpglobal $cat;$cats = get_categories(array('child_of' => $cat,'parent' => $cat,'hide_empty' => 0));$c = get_category($cat);if(empty($cats)){?><div ><?php if (have_posts()) : while (have_posts()) : the_post(); ?><div ><h2><a title="<?php the_title(); ?>" href="<?php the_permal
ink(); ?>"><?php the_title(); ?></a></h2><p><?php the_excerpt(); ?></p><p><a href="<?php the_permal
ink(); ?>">全文阅读>></a></p><div ><?php the_time('Y-m-d'); ?> | 标签: <?php the_tags('', ' , ', ''); ?></div></div><?php endwhile; ?><?php else: ?><div ><p>文章稍后更新</p></div><?php endif; ?></div><div ><span ><?php next_posts_l
ink('« Older posts') ?></span><span ><?php previous_posts_l
ink('Newer posts »') ?></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 ><div ><h2><a title="'.$the_cat->name.'" href="'.get_category_l
ink($the_cat).'">'.$the_cat->name.'</a></h2></div><ul >';foreach($posts as $post){echo '<li><span >'.mysql2date('Y-m-d', $post->post_date).'</span><a title="'.$post->post_title.'" href="'.get_permal
ink($post->ID).'">'.$post->post_title.'</a></li>';}echo '</ul></div>';}}}?>