对于WordPress说,WordPress定时文章也是有大部分人群使用的,特别是一些时间原因和SEO从业人员他们都喜欢把文章定时发布,以便SEO优化和时间管理,但是这样定时的文章对于普通的文章用户来说是根本无法看到的,也不知道网站即将发布什么,今天给大家带来个WordPress显示即将发布文章列表,希望帮助由此需求的用户解决问题。
1、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>
2、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]

