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 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
  • ¥50 STM32单片机传感器读取错误
  • ¥15 (关键词-阻抗匹配,HFSS,RFID标签天线)
  • ¥15 机器人轨迹规划相关问题
  • ¥15 word样式右侧翻页键消失