威尼斯wnsr888_新葡亰8883ent_威尼斯wns8885556

当前位置: 正汯解答网» 编程语言» WordPress文章页显示当前文章分类下的最新文章

WordPress文章页显示当前文章分类下的最新文章

2022年9月09日 15:17:55 编程语言 0 次浏览

可以快速生成wordpress文章页面,同分类栏目下面最新文章内容的代码,只要复制下面的代码到指定的位置就可以显示当前分类栏目下面的最新文章了,同时可以通过numberposts的数据来控制数量,通过orderby的值来设置排序的方式.
'orderby' => 'date', //按发布日期排序
'orderby' => 'modified', //按修改时间排序
'orderby' => 'ID', //按文章ID排序
'orderby' => 'comment_count', //按评论最多排序
'orderby' => 'title', //按标题排序
'orderby' => 'rand', //随机排序
'order' => 'desc', // 降序(递减,由大到小)

global $post;
$categories = get_the_category(); //函数获取分类ID好
foreach ($categories as $category){
?>


    $posts = get_posts('numberposts=80&orderby=rand&category='. $category->term_id);
    //通过get_posts函数,根据分类ID来获取这个ID下的文章内容。
    foreach($posts as $post){
    ?>


  • }
    ?>

}
?>

标签:
Baidu
sogou