泰晓科技 -- 聚焦 Linux - 追本溯源,见微知著!
网站地址:https://tinylab.org

泰晓Linux知识星球:1300+知识点,520+用户
请稍侯

Q and A Focus Plus FAQ 添加随机 FAQ 小工具

Wu Zhangjin 创作于 2014/08/27
  • 问题描述

    WordPress 的 Q & A Focus Plus FAQ 插件默认的 Widget 只能显示最新 FAQ,如果要随机显示 FAQ,怎么办?

  • 问题分析

    经过查找,发现有如下支持 wp_query orderby random not working

    <?php $loop = new WP_Query( array( orderby => 'rand', 'post_type' => 'testimonials', 'posts_per_page' => 1 ) ); ?>
    <?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
    <?php the_permalink();?>
    
  • 解决方案

    通过 插件->编辑 菜单,找到插件名称: Q And A Focus Plus FAQ,找到 q-and-a-focus-plus-faq/inc/widgets.php,发现做如下修改即可:

    //$pq = new WP_Query(array( 'post_type' => 'qa_faqs', 'orderby' => 'post_date', 'showposts' => $instance['numberposts'] ));
    $pq = new WP_Query(array( 'post_type' => 'qa_faqs', 'orderby' => 'rand', 'showposts' => $instance['numberposts'] ));
    


Read Related:

Read Latest: