腾讯云服务器优惠活动华纳云香港服务器

WordPress分类列表页怎么置顶本分类文章?

WordPress主题推荐

将下面的代码添加到主题 archive.php 或者 category.php 模板主循环上面: 

  1. <?php
  2.     query_posts(array(
  3.         “category__in” => array(get_query_var(“cat”)),
  4.         “post__in” => get_option(“sticky_posts”),
  5.         ‘showposts’ => 3,
  6.         )
  7.     );
  8.     while(have_posts()) : the_post();
  9. ?>
  10. <h1>置顶<a href=“<?php the_permalink(); ?>” title=“<?php the_title(); ?>”><?php the_title(); ?></a></h1>
  11. <?php
  12.     endwhile;
  13.     wp_reset_query();
  14. ?>

其中: ‘showposts’ => 3, 是显示数量。

答案内容来自知更鸟

本文地址:https://boke112.com/post/4095.html

赞 (0) 打赏
版权声明:本文为原创文章,版权归 boke112百科 所有,欢迎分享本文,转载请保留出处!发布此文是出于传递更多信息之目的,若有来源标注错误或侵犯了您的合法权益,请联系我们,确认后马上更正或删除,谢谢!
香港云主机55元/年
wu