使用WordPress搭建网站的朋友应该都知道可以将文章置顶,那么如何在主题开发中调用它,今天小编也用到了调用置顶文章和排除置顶文章的相关代码,有需要的朋友可以一起来看看。调用置顶文章 123456789101112<?php $sticky = get_option\'sti

使用WordPress搭建网站的朋友应该都知道可以将文章置顶,那么如何在主题开发中调用它,今天小编也用到了调用置顶文章和排除置顶文章的相关代码,有需要的朋友可以一起来看看。
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; ?>
温馨提示:本文最后更新于 2023-12-09 15:46 ,某些文章具有时效性,若有错误或已失效,请在下方留言或联系QQ115904045
声明:
1.本站大部分内容均收集于网络!若内容若侵犯到您的权益,请发送邮件至:[email protected],我们将第一时间处理!
2.资源所需价格并非资源售卖价格,是收集、整理、编辑详情以及本站运营的适当补贴,并且本站不提供任何免费技术支持
3.所有资源仅限于参考和学习,版权归原作者所有,更多请阅读网站声明

给TA打赏
共{{data.count}}人
人已打赏
wordpress教程

WordPress调用友情链接函数wp_list_bookmarks()

2023-12-9 15:46:25

wordpress教程

WordPress文章添加阅读次数统计

2023-12-9 15:46:27

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

    夕阳无别事,等风也等你

    联系我们