WordPress教程-显示当前文章分类下的较新文章
今天wordpress痴站长分享给大家一段可以快速生成wordpress文章页面,同分类栏目下面较新文章内容的代码,只要复制下面的代码到指定的位置就可以显示当前分类栏目下面的较新文章了,同时可以通过numberposts的数据来控制数量,通过orderby的值来设置排序的方式.
1234567‘orderby’ => ‘date’, //按发布日期排序‘orderby’ => ‘modified’, //按修改时间排序‘orderby’ => ‘ID’, //按文章ID排序‘orderby’ => ‘comment_count’, //按评论较多排序‘orderby’ => ‘title’, //按标题排序‘orderby’ => ‘rand’, //随机排序‘order’ => ‘desc’, // 降序(递减,由大到小)1234567891011121314151617181920<?php global $post; $categories = get_the_category(); //函数获取分类ID好 foreach ($categories as $category){?><ul> <?php $posts = get_posts(‘numberposts=80&orderby=rand&category=’. $category->term_id); //通过get_posts函数,根据分类ID来获取这个ID下的文章内容。 foreach($posts as $post){ ?> <li><a href=“<?php the_permalink(); ?>“><?php the_title(); ?></a></li> <?php //显示出该分类下的文章标题,以及附加上超链接。 ?> <?php } ?></ul><?php }?>