如何让WordPress显示即将发布的文章列表

  • 时间:2020-05-29 14:26:07
  • 分类:网络文摘
  • 阅读:154 次

通过wordpress自带的定时发布功能,可以让文章的发布更有规律,这对网站的seo是很有好处的。如何让即将发布的文章列表呈现到网站中,让读者看到,以便使你的博客获取更多关注呢?下文介绍的wordpress技巧让你通过两种方法都可以实现此目的。

方法一:复制下列代码到wordpress主题模板的适当位置(看你想要显示到哪里)即可。

  1. <ul>
  2. <?php
  3. $my_query = new WP_Query('post_status=future&order=DESC&showposts=10&ignore_sticky_posts=1');
  4. if ($my_query->have_posts()) {
  5.     while ($my_query->have_posts()) : $my_query->the_post();
  6.         $do_not_duplicate = $post->ID; ?>
  7.         <li><?php the_time('H:i') ?> <?php the_title(); ?></li>
  8.     <?php endwhile;
  9. }
  10. ?>
  11. </ul>

方法二:复制下列代码到wordpress主题的functions.php文件中:

  1. function future_posts_function($atts){
  2.     extract(shortcode_atts(array(
  3.         'poststatus' => 'future',
  4.         'order'         => 'DESC',
  5.         'showposts' => 10,
  6.         'ignore_sticky_posts' => 1
  7.     ), $atts));
  8.     $return_string = '<ul>';
  9.     query_posts(array('post_status' => $poststatus, 'order' => $order, 'ignore_sticky_posts' => $ignore_sticky_posts, 'showposts' => $showposts));
  10.     if (have_posts()) :
  11.         while (have_posts()) : the_post();
  12.             $return_string .= '<li>'.get_the_title().'</li>';
  13.         endwhile;
  14.     endif;
  15.     $return_string .= '</ul>';
  16.     wp_reset_query();
  17.     return $return_string;
  18. }
  19. add_shortcode('future_posts', 'future_posts_function');
  20. // 让文本小工具支持短代码
  21. add_filter('widget_text', 'do_shortcode');

然后添加如下代码到文本小工具中,并拖动文本小工具到合适位置即可:

  1. [future_posts]

原文链接:http://zmingcx.com/show-the-upcoming-articles.html

推荐阅读:
Blog On The Go With These Mobile Apps  Here’s Why Your Content is Struggling  Cloud Hosting vs. Traditional Hosting: Why Hosting Your Blog in   How to Compute the N-th Tribonacci Number using Iterative Dynami  How to Find the Largest Unique Number in Array (C++)?  How to Find the K-diff Pairs in an Array with Two Pointer or Has  String Algorithm: Reverse the first k characters for every 2k ch  How to Generate Parentheses using Bruteforce or Depth First Sear  Algorithm to Construct Binary Tree from Preorder and Inorder Tra  The 24 Game Algorithm using Depth First Search 
评论列表
添加评论