add_shortcode( 'cpostgridelement', 'cpostgridelementFunc' );
function cpostgridelementFunc( $atts ) {
extract(shortcode_atts(array( 'cpttypee' => 'member','templatetypee'=>'memberTemplate','postsidd'=>2 ), $atts));
// if($postsid){
$args = array(
'posts_per_page' => 2, // id of a page, post, or custom type
'post_type' =>$cpttypee,
'order' => 'Desc',
);
$custom_query = new WP_Query($args);
if ( $custom_query->have_posts() ) :
while ( $custom_query->have_posts()) :
$custom_query->the_post();
$title = get_the_title();
$postLink = get_permalink();
$f_page_images = get_field('image');
$board_member_title = get_field('board_member_title');
$board_member_email = get_field('email');
$board_member_phone = get_field('phone');
$board_member_description = get_field('board_member_description');
$imgId = wp_get_attachment_image($f_page_images,'thumbnail');
$collectInfoo = array();
$collectInfoo[]="<div class='annual_cntct vc_staff_addon'>
<div class='annual_top brd_membr'><div class='annual_top_inr stf_mmbr_inr'>
<div class='lft_annual_sdbr col'>".$imgId."
</div>
<div class='rght_annual_sdbr col'>
<h4 class='bld_anul'>".$title."</h4>
<h4 class='vc_gry'>".$board_member_title."</h4>
<h4 class='vc_gry'>".$board_member_phone."</h4>
<h4 class='vc_gry'>".$board_member_email."</h4>
</div>
<div class='clear'></div>
</div></div></div>";
endwhile;
return $collectInfoo;
endif;
// }
// else{
//no post id entered
// echo "No Post Id entered";
// }
}
我想获得2个帖子。但问题是,如果我使用返回它只给我一个帖子,这里不能使用echo。
答案 0 :(得分:1)
试试这个:
修改强> 我继续并删除了你在数组中返回的HTML。只需在调用此函数时回显循环中的HTML。
虽然你解决了自己的问题,但我会考虑使用这样的东西。
add_shortcode( 'cpostgridelement', 'cpostgridelementFunc' );
function cpostgridelementFunc( $atts ) {
extract(shortcode_atts(array( 'cpttypee' => 'member','templatetypee'=>'memberTemplate','postsidd'=>2 ), $atts));
// if($postsid){
$args = array(
'posts_per_page' => 2, // id of a page, post, or custom type
'post_type' =>$cpttypee,
'order' => 'Desc',
);
$custom_query = new WP_Query($args);
if ( $custom_query->have_posts() ) :
$collectInfoo = array();
while ( $custom_query->have_posts()) :
$custom_query->the_post();
$title = get_the_title();
$postLink = get_permalink();
$f_page_images = get_field('image');
$board_member_title = get_field('board_member_title');
$board_member_email = get_field('email');
$board_member_phone = get_field('phone');
$board_member_description = get_field('board_member_description');
$imgId = wp_get_attachment_image($f_page_images,'thumbnail');
$collectInfoo[]= array("thumbnail"=>$imgId,"board_member_title"=>$board_member_title,"phone"=>$board_member_phone,"board_member_description"=>$board_member_description);
endwhile;
return $collectInfoo;
endif;
// }
// else{
//no post id entered
// echo "No Post Id entered";
// }
}