调用5条置顶文章
<?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; ?>
排除置顶文章
<?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; ?>
龙哥 发表于 1年前 (2021-03-20),共716字
版权声明:①欢迎转载但请注明出处。②如涉及版权联系(izhailong#qq.com)删除!
转载请注明:wp/wordpress调用置顶文章及排除置顶文章 || https://www.izhailong.com/270.html
本文由:版权声明:①欢迎转载但请注明出处。②如涉及版权联系(izhailong#qq.com)删除!
转载请注明:wp/wordpress调用置顶文章及排除置顶文章 || https://www.izhailong.com/270.html
暂无评论