WordPress如何调用置顶文章
1.找到你需要显示置顶文章的代码位置,插入如下代码:
(1)指定分类
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); query_posts( array( 'post__in' => $sticky, 'caller_get_posts' => 1,'showposts' => 4,'cat' =>5) ); ?> <?php if (have_posts()) : ?> <?php while (have_posts()) : the_post(); ?> 显示内容代码,可以自己设置。 <?php endwhile; ?> <?php else : ?><p class="center">没有数据。</p> <?php endif; ?> |
(2)全站
1 2 3 4 5 6 7 8 9 10 11 | <?php $args = array( 'posts_per_page' => -1, 'post__in' => get_option( 'sticky_posts' ) ); $sticky_posts = new WP_Query( $args ); while ( $sticky_posts->have_posts() ) : $sticky_posts->the_post();?> <li> <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a> </li> <?php endwhile; wp_reset_query();?> |
2.调整显示内容的代码样式等,最终效果如图。
来源:邦林织梦(微信/QQ号:909912499),欢迎分享本文,转载请保留出处!部分内容来自网络,如有侵权请联系删除处理!
相关信息
本站提供代码修改,dedecms,WordPress仿站二次开发 / PHP网站建设以及SEO优化等网络营销推广等服务。
如有需要请加QQ: 909912499