如何显示WordPress定时发布文章列表?

很多站长想要在显著的位置放一个提示,告诉读者马上会有什么文章发布,如何实现呢?我们就一起看看如何显示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>

方法二、将下面的代码添加到当前主题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]

用户添加上述代码就更简单了,直接将方法一的代码放到增强文本小工具中即可,无需修改主题。

小车博客下载必看

给TA打赏
共{{data.count}}人
人已打赏
WP教程

WordPress如何获取一定天数内发表的文章?

2020-9-28 11:18:04

WP教程

使用免费网站模板建站的特点是什么?

2020-9-29 9:31:14




重要声明

本站资源来自会员发布以及互联网收集,不代表本站立场,如有侵犯你的权益请联系管理员-车车站内发信联系 我们会第一时间进行审核删除。站内资源为网友个人学习或测试研究使用,未经原版权作者许可,禁止用于任何商业途径!请用户仔细辨认内容的真实性,避免上当受骗!本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。请在下载24小时内删除!


如果遇到付费才可观看的文章,建议升级终身VIP。全站所有资源任意下免费看”。本站资源少部分采用7z压缩,为防止有人压缩软件不支持7z格式,7z解压,建议下载7-zip,zip、rar解压,建议下载WinRAR

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索