WordPress最新文章列表中置顶文章靠前显示
发布:WordPress教程网 发布时间:
2023-02-16 游览次数:32次
在做网站时,有些版块需要调用某个栏目的文章列表,并且要求后台设置的置顶文章靠前显示。如下图:

怎么实现在调用最新文章列表中置顶文章靠前显示呢?代码如下:
<?php
$sticky = get_option('sticky_posts');
query_posts( array('post__in' => $sticky,'caller_get_posts' =>1,'cat'=>25,'showposts'=>6));
static $case_num=0;
while (have_posts()) : the_post(); ?>
<!--置顶文章-->
<li><a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></li>
<?php $case_num++;
endwhile; wp_reset_query();
$case_num=6-$case_num;//
query_posts( array( 'post__not_in' => get_option( 'sticky_posts'),'cat'=>25,'showposts'=>$case_num ));
while (have_posts()) : the_post();
?>
<!--非置顶文章-->
<li><a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></li>
<?php endwhile; wp_reset_query(); ?>
代码解释:
'cat'=>25 设置调用的分类目录ID号;'showposts'=>6 设置调用文章的总数量;
代码放置好之后,可以在网站后台设置置顶文章。
标签 : wordpress教程 , 文章 , 置顶
本文版权归原作者所有,转载请注明原文来源出处, WordPress教程网 感谢您的支持!
本文链接: http://www.wpcn.net/877.html
推荐内容
热点阅读
相关内容
- WordPress手动升级详细步骤
- WordPress手动安全升级
- WordPress后台无插件显示文章和分类ID
- WordPress优化:wp_head和remove_action函数
- query_posts函数把你的wordpress博客变成CMS
- Bootstrap替换WordPress的get_search_form()…
- WordPress 函数:register_sidebar()创建主…
- wp_list_comments()使用回调函数自定义评论…
- WordPress过滤器(Filters):apply_filters和…
- WordPress函数:comments_template(加载评…
- WordPress函数:comment_form( )个性化评论…
- 无处不在的WordPress的主循环
- WordPress 函数do_action()详解和应用举例
- WordPress函数:add_menu_page()后台添加顶…
- WordPress函数:add_theme_page()后台添加设…
- WordPress函数:add_submenu_page()后台为顶…
- WordPress 函数:get_template_part()调用你…
- WordPress函数:load_theme_textdomain()(…
- WordPress 3D旋转彩色标签云
- WordPress文本小工具运行PHP
- WordPress无插件实现主题彩色标签云的N种方…
- WordPress函数:wp_tag_cloud(标签云)详解和…
- WordPress函数:register post type (自定义…
- WordPress使用register_post_type 函数创建…