用户登录
用户注册

分享至

wordpress多个置顶

  • 作者: 用户50791008
  • 来源: 51数据库
  • 2020-04-21

1.如何在wordpress网站显示最新置顶文章

置顶文章是WordPress中一项很受人欢迎的功能。置顶文章是博客中必将有特点的文章,当你把一篇文章标记为置顶文章时,这篇文章将会在最新文章的顶部显示,但是前提条件是网站主题允许设置置顶文章。我们将通过这篇文章为大家介绍如何在WordPress网站中显示最新置顶文章。

如何在WordPress网站显示最新置顶文章

提示:该教程属于中级教程需要有一定的HTML/CSS基础和WordPress主题的相关知识。

首先需要我们做的是复制并黏贴下述代码到你的WordPress主题的functions.php文件或一个site-specific plugin中。

function wpb_latest_sticky() {

/* Get all sticky posts */

$sticky = get_option( 'sticky_posts' );

/* Sort the stickies with the newest onesat the top.

* Remove this if you want to display oldest posts first

*/

rsort( $sticky );

/* Get the 5 newest stickies (change 5 fora different number) */

$sticky = array_slice( $sticky, 0, 5 );

/* Query sticky posts */

$the_query = new WP_Query( array('post__in' => $sticky, 'caller_get_posts' => 1 ) );

// The Loop

if ( $the_query->have_posts() ) {

$return .= '

2.wordpress文章如何置顶

wordpress文章置顶功能 <?php $args="array(" 'posts_per_page'=""> 3, 'post__in' => get_option( 'sticky_posts' ), 'ignore_sticky_posts' => 1 ); query_posts( $args ); while ( have_posts() ) : the_post();?> //循环内容 <?php endwhile;wp_reset_query();?="">原文地址:。

转载请注明出处51数据库 » wordpress多个置顶

软件
前端设计
程序设计
Java相关