如何让WordPress显示即将发布的文章列表
- 时间:2020-05-29 14:26:07
- 分类:网络文摘
- 阅读:103 次
通过wordpress自带的定时发布功能,可以让文章的发布更有规律,这对网站的seo是很有好处的。如何让即将发布的文章列表呈现到网站中,让读者看到,以便使你的博客获取更多关注呢?下文介绍的wordpress技巧让你通过两种方法都可以实现此目的。
方法一:复制下列代码到wordpress主题模板的适当位置(看你想要显示到哪里)即可。
- <ul>
- <?php
- $my_query = new WP_Query('post_status=future&order=DESC&showposts=10&ignore_sticky_posts=1');
- if ($my_query->have_posts()) {
- while ($my_query->have_posts()) : $my_query->the_post();
- $do_not_duplicate = $post->ID; ?>
- <li><?php the_time('H:i') ?> <?php the_title(); ?></li>
- <?php endwhile;
- }
- ?>
- </ul>
方法二:复制下列代码到wordpress主题的functions.php文件中:
- function future_posts_function($atts){
- extract(shortcode_atts(array(
- 'poststatus' => 'future',
- 'order' => 'DESC',
- 'showposts' => 10,
- 'ignore_sticky_posts' => 1
- ), $atts));
- $return_string = '<ul>';
- query_posts(array('post_status' => $poststatus, 'order' => $order, 'ignore_sticky_posts' => $ignore_sticky_posts, 'showposts' => $showposts));
- if (have_posts()) :
- while (have_posts()) : the_post();
- $return_string .= '<li>'.get_the_title().'</li>';
- endwhile;
- endif;
- $return_string .= '</ul>';
- wp_reset_query();
- return $return_string;
- }
- add_shortcode('future_posts', 'future_posts_function');
- // 让文本小工具支持短代码
- add_filter('widget_text', 'do_shortcode');
然后添加如下代码到文本小工具中,并拖动文本小工具到合适位置即可:
- [future_posts]
原文链接:http://zmingcx.com/show-the-upcoming-articles.html
推荐阅读:指定 wordpress 默认用户角色后台登陆权限 为 WordPress 主题添加大红灯笼特效 为 wordpress 文章作者在评论留言时显示“本文作者”提示 为 WordPress 主题添加花瓣飘落特效 wordpress插件:WP-China-Yes 切换WP站点与官方通信至国内节点解决后台更新429错误 一段代码轻松解决wordpress定时发布失败的问题 WordPress官网打不开 出现 429 Too Many Request 的原因 下载更新wordpress程序及插件的方法 禁用wordpress4.4+版本自动生成768w像素缩略图功能 自动为wordpress文章图片添加alt属性和title属性
- 评论列表
-
- 添加评论