今天分享大家一段可以快速生成wordpress文章頁面,同分類欄目下面最新文章內(nèi)容的代碼,只要復(fù)制下面的代碼到指定的位置就可以顯示當(dāng)前分類欄目下面的最新文章了,同時(shí)可以通過numberposts的數(shù)據(jù)來控制數(shù)量,通過orderby的值來設(shè)置排序的方式.
1 2 3 4 5 6 7 |
'orderby' => 'date', //按發(fā)布日期排序 'orderby' => 'modified', //按修改時(shí)間排序 'orderby' => 'ID', //按文章ID排序 'orderby' => 'comment_count', //按評(píng)論最多排序 'orderby' => 'title', //按標(biāo)題排序 'orderby' => 'rand', //隨機(jī)排序 'order' => 'desc', // 降序(遞減,由大到小) |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
<?php global $post; $categories = get_the_category(); //函數(shù)獲取分類ID好 foreach ($categories as $category){ ?> <ul> <?php $posts = get_posts('numberposts=80&orderby=rand&category='. $category->term_id); //通過get_posts函數(shù),根據(jù)分類ID來獲取這個(gè)ID下的文章內(nèi)容。 foreach($posts as $post){ ?> <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li> <?php //顯示出該分類下的文章標(biāo)題,以及附加上超鏈接。 ?> <?php } ?> </ul> <?php } ?> |