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.

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

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效