本文是《wordpress(共168篇)》专题的第 86 篇。阅读本文前,建议先阅读前面的文章:
使用WordPress搭建网站的朋友应该都知道可以将文章置顶,那么如何在主题开发中调用它,今天小编也用到了调用置顶文章和排除置顶文章的相关代码,有需要的朋友可以一起来看看。

调用置顶文章
| 1 2 3 4 5 6 7 8 9 10 11 12 |
<?php $sticky = get_option(‘sticky_posts’); rsort( $sticky ); $sticky = array_slice( $sticky, 0, 5); // 调用5条 query_posts( array( ‘post__in’ => $sticky, ‘caller_get_posts’ => 1 ) ); if (have_posts()) :while (have_posts()) : the_post(); ?> <li><a href="<?php the_permalink(); ?>" target="_blank"><?php the_title(); ?></a></li> <?php endwhile; wp_reset_query(); // 必填 endif; ?> |
排除置顶
| 1 2 3 4 5 6 7 8 |
<?php $the_query = new WP_Query( array( ‘post__not_in’ => get_option( ‘sticky_posts’ ) ) ); if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post();?> <div class="post" id="post-<?php the_ID(); ?>"> <p> <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></p> <?php the_post_thumbnail(‘thumbnail’); ?> </div> <?php endwhile; ?> <?php endif; ?> |
您已阅读完《wordpress(共168篇)》专题的第 86 篇。请继续阅读该专题下面的文章:
本站模板没有任何后门,也不会和我们服务器有任何通信,请您放心使用。
本源码一次性买断,没有二次费用,并享受免费更新。
在使用本站模板时,请不要使用我们的产品从事违反中华人民共和国法律、违反公序良俗的活动,否则我们有权拒绝服务,并配合有关单位予以处置。如果您不符合条件,请勿购买。
售后是指通过QQ与客服联系处理问题,售后过期不影响您对主题的使用和更新。免费三个月售后服务。售后服务时间为工作日早9点到晚5点。如果不在线可以QQ留言,我们会尽快给您答复。
售后服务包括程序的使用、BUG的处理、意见建议等。不包括技术服务、网站优化、二次开发、环境配置、服务器运维等。
代码类商品属于数字化商品,具有可复制性,不支持退款,详见《网络交易管理办法》第二章 第16条 第三类。
请仔细阅读我们的用户协议:用户协议



