dpw70180 2019-04-26 12:25
浏览 45
已采纳

如何通过wordpress中的短代码在单页上显示所有推荐?

i have created shortcode to show all testimonial on one page. i have created custom post type to add each testimonial. can anybody tell me how to show all testimonial on single page . this code is used to create sshortcode below i m mentioning code :-

function fn_testimonials_block()
{
$args = array(
    'post_type'=> 'testimonials',
    'order'    => 'ASC'
    );              

$the_query = new WP_Query( $args );

$pages              = $the_query->posts;

//echo "<pre>";
//print_r($pages);
//echo "</pre>";

//exit;

$output = '';
$count = 1;

foreach($pages as $page) {

    //-----------------

    $author         = $page->post_title;
    $testimonial    = $page->post_content;
    $page_url       = get_page_link( $page->ID );
    $author_image   = get_the_post_thumbnail_url( $page->ID, 'thumbnail' );

    if ($count%2 == 1)
    {  
         $output .= '<div>';
    } 

    $output .= '<div>
              <p>'.$testimonial.'<br>
              <img src="'.$author_image .'"> <span>'.$author.', </span></p>
            </div>';

    if ($count%2 == 0) 
    {
        $output .= '</div>';
    }

    $count++;

}

if ($count%4 != 1){
    $output .= '</div>';
} 

return $output;
}
  • 写回答

1条回答 默认 最新

  • douwen5681 2019-04-26 13:08
    关注

    I think you will have to pass 'posts_per_page' key in $args array. So your $args array will look like this

    $args = array(
        'post_type'=> 'testimonials',
        'order'    => 'ASC',
        'posts_per_page' => '-1'
    );
    

    I am not sure about the $count variable you are using. I suppose you are trying to implement logic for pagination there but since your question is about showing all testimonials on single page, I won't get into that part.

    Making changes in $args will return all testimonials objects.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 WPF动态创建页面内容
  • ¥15 如何对TBSS的结果进行统计学的分析已完成置换检验,如何在最终的TBSS输出结果提取除具体值及如何做进一步相关性分析
  • ¥15 SQL数据库操作问题
  • ¥100 关于lm339比较电路出现的问题
  • ¥15 Matlab安装yalmip和cplex功能安装失败
  • ¥15 加装宝马安卓中控改变开机画面
  • ¥15 STK安装问题问问大家,这种情况应该怎么办
  • ¥15 关于罗技鼠标宏lua文件的问题
  • ¥15 halcon ocr mlp 识别问题
  • ¥15 已知曲线满足正余弦函数,根据其峰值,还原出整条曲线