wordpress输出指定分类下的所有文章

介绍一种方法:get_posts

<?php $posts = get_posts( "category=1&numberposts=10" ); ?>
<?php if( $posts ) : ?>
    <?php foreach( $posts as $post ) : setup_postdata( $post ); ?>
        <li>
            <a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a>
        </li>   
<?php endforeach; ?>
<?php endif; ?>
  • category=1&numberposts=10:其中的1是指调用分类ID为1的文章,10是指调用该分类下最新的10篇文章

值得注意的是这一句话,当时写的时候写错了,纠错了很久。


<?php $posts = get_posts( "category=1&numberposts=10" ); ?>这一句中的1为分类ID为1的文章,但是带调用的时候不能直接调用他的ID:<?php $posts = get_posts( "1&10" ); ?>这个样子是错误的。参数中的category或者numberposts是必不可少的,不能只写他的ID数字。

当需要调用分下的全部文章的时候,把numberposts=-1即可。如下:

<?php $posts = get_posts( "category=1&numberposts=-1" ); ?>
暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇