跳至主要內容
  • Hostloc 空間訪問刷分
  • 售賣場
  • 廣告位
  • 賣站?

4563博客

全新的繁體中文 WordPress 網站
  • 首頁
  • 有没有可以随机文章的wordpress模板介绍?
未分類
1 10 月 2020

有没有可以随机文章的wordpress模板介绍?

njav 大佬有话说 :

有没有可以随机文章的wordpress模板介绍?

本帖最后由 njav 于 2020-10-1 03:10 编辑

有没有可以随机文章的wordpress模板介绍?

市面上挺少这类的模板

或者有没有相关的外挂? 可以在一个分类/页面可以做到随机展示文章

5000000 大佬有话说 :

多的是,随便百度学一下 修改下模板添加个函数钩子就行

shc 大佬有话说 :

function wpb_rand_posts() {

$args = array(
    ‘post_type’ => ‘post’,
    ‘orderby’   => ‘rand’,
    ‘posts_per_page’ => 5,
    );

$the_query = new WP_Query( $args );

if ( $the_query->have_posts() ) {

$string .= ‘<ul>’;
    while ( $the_query->have_posts() ) {
      $the_query->the_post();
      $string .= ‘<li><a href="’. get_permalink() .’">’. get_the_title() .'</a></li>’;
    }
    $string .= ‘</ul>’;
    /* Restore original Post Data */
    wp_reset_postdata();
} else {

$string .= ‘no posts found’;
}

return $string;
}

add_shortcode(‘insert-random-post’,’wpb_rand_posts’);
add_filter(‘widget_text’, ‘do_shortcode’);

然后在需要放随机文章的地方插短代码

文章導覽

上一篇文章
下一篇文章

AD

其他操作

  • 登入
  • 訂閱網站內容的資訊提供
  • 訂閱留言的資訊提供
  • WordPress.org 台灣繁體中文

51la

4563博客

全新的繁體中文 WordPress 網站
返回頂端
本站採用 WordPress 建置 | 佈景主題採用 GretaThemes 所設計的 Memory
4563博客
  • Hostloc 空間訪問刷分
  • 售賣場
  • 廣告位
  • 賣站?
在這裡新增小工具