有站长问到如何添加置顶功能。今天小编就以WordPress版本的 Mnews 主题为例添加首页和列表页的置顶功能,其他主题请参考折腾即可。
1、修改首页 index.php 文件
直接编辑 Mnews 主题的 index.php 文件,找到以下代码
在它下方添加以下代码:
$sticky,'showposts'=>3) );
?>
2、修改列表页 archive.php 文件
直接编辑 Mnews 主题的 archive.php 文件,找到以下代码
在它下方添加以下代码:
array(get_query_var("cat")),
"post__in" => get_option("sticky_posts"),
'showposts' => 3,
)
);
while(have_posts()) : the_post();
?>
array(get_query_var("cat")),
'post__not_in' => $sticky,
'paged' => $paged
);
query_posts( $args );
?>
3、修改 inc\content.php 文件
直接编辑 inc\content.php 文件,找到文章标题代码:
修改为:
至此,已经为 WordPress 版本的 Mnews 主题添加了置顶文章功能,接下来只需要在后台编辑文章的时候,在公开度 >> 公开中勾选“将文章置于首页顶端”或快速编辑勾选“置顶这篇文章”即可。