wordpress分类列表调用该分类置顶文章
wordpress调用该分类下置顶文章代码功能分享,此功能常用在文章列表的顶部推荐中,可以做为热门文章置顶在当前分类的顶部位置,是一个非常好的用户体验功能,而且在现代的h5网站中也越来越重要。下面测速网就给大家介绍一下此功能的代码,使用非常简单,而且在下面提供了如果在该循环中去除置顶文章的代码方法,供大家学习交流。
在当前主题的分类列表模板中添加代码:
12345678910111213<?php query_posts(array("category__in" => array(get_query_var("cat")), "post__in" => get_option("sticky_posts")));while(have_posts()) : the_post(); ?><h2>【置顶】<a href="<?php%20the_permalink();%20?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h2><?php endwhile;wp_reset_query();?>
在正常的分类列表中排除已经设置为置顶的文章:
12345<?php while(have_posts()) : the_post(); ?><?php if(!is_sticky()){?><h2><a href="<?php%20the_permalink();%20?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h2><?php the_excerpt(); ?><?php } endwhile;?>
其实就是在主循环中添加if(!is_sticky())来判断,表示如果不是置顶文章则显示。
上一篇:调用wordpress文章页当前分类名称和链接的代码
webacc.exe是什么文件?webacc.exe是不是病毒
WINSYS.vbs是什么文件?WINSYS.vbs是不是病毒
winssh.exe是什么文件?winssh.exe是不是病毒
wt.exe是什么文件?wt.exe是不是病毒
winsysetm.exe是什么文件?winsysetm.exe是不是病毒
winstrve.exe是什么文件?winstrve.exe是不是病毒
winsysupd7.exe是什么文件?winsysupd7.exe是不是病毒
winsysupd.exe是什么文件?winsysupd.exe是不是病毒
winsysupd2.exe是什么文件?winsysupd2.exe是不是病毒
winsysupd8.exe是什么文件?winsysupd8.exe是不是病毒