欢迎您光临自学哈网,只为分享网络知识教程,供大家学习参考!

「自学哈网」如何显示WordPress定时发布文章列表?

作者 : 自学哈 本文共1069个字,预计阅读时间需要3分钟 2022-11-26 共107人阅读
也想出现在这里? 联系我们

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

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

本站声明:
本站所有资源来源于网络,分享目的仅供大家学习和交流!如若本站内容侵犯了原著者的合法权益,可联系邮箱976157886@qq.com进行删除。
自学哈专注于免费提供最新的分享知识、网络教程、网络技术的资源分享平台,好资源不私藏,大家一起分享!

自学哈网 » 「自学哈网」如何显示WordPress定时发布文章列表?
也想出现在这里? 联系我们
© 2022 Theme by - 自学哈网 & WordPress Theme. All rights reserved 浙ICP备2022016594号