WordPress调用指定分类下的文章

调用WordPress指定分类的文章代码如下:

<ul>
    <?php query_posts('cat=15&posts_per_page=10'); while(have_posts()): the_post(); ?>  
    <li><a href="<?php%20the_permalink();?>"><?php the_title();?></a></li>  
    <?php endwhile; wp_reset_query(); ?>  
</ul>

其中:

“cat=15”表示ID为15的分类
“posts_per_page=10”表示显示数量为该分类下最新10篇文章

而首页显示时排除(此例为排除ID为5和6的分类)某些分类的源码(替换掉主题中index.php文件中的)

<?php while (have_posts()) : the_post(); ?>

即可):

<?php if ( have_posts() ) : query_posts($query_string .'&cat=-5,-6'); while ( have_posts() ) : the_post(); ?>

 

wordpress网站建站

wordpress开启子目录多站点模式并给子站绑定独立域名

2022-1-15 19:17:57

wordpress网站建站

WordPress自定义查询:WP_Query的使用

2022-1-15 20:54:18

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索