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 개의 게시물을 얻으려고합니다. 하지만 문제는 만약 내가 그것을 사용하여 하나의 게시물을 제공하고 여기에 에코를 사용할 수 없습니다 반환을 사용합니다.php 함수에서 두 개의 값을 루프로 반환합니다.
'$ collectInfoo'는'while '외부에서 정의되어야합니다. –
개인적으로, 나는 이제 함수에서 HTML을 반환하는 것이 좋지 않다고 생각합니다. 값을 반환하고 필요할 때 HTML을 추가해야합니다. 기능을 다시 사용해야 할 경우를 대비하여 –