我有一個我正在寫wordpress的短代碼問題。我正在嘗試使用get_the_content()
函數,但不是拉取自定義帖子類型的內容,而是創建它,它將拉取簡碼所在頁面的內容。其他功能都正常工作,例如get_the_title()
和g et_the_post_thumbnail()
。我在函數中傳遞了ID,它對於其他所有方面都非常有用,而不是get_the_content
。get_the_content在短代碼內不起作用
get_the_content($testimonial_item->ID);
簡碼包含分頁和其他所有工作正常的元素,它只是這一個導致我悲傷的功能。完整的代碼如下,任何幫助將不勝感激。
function ncweb_display_testimonial_items($atts, $content = null) {
extract(shortcode_atts(array(
'per_page' => 6
), $atts));
/* pagination parameters */
// check what page we are on
if (isset ($_GET['testimonial-page'])) $page = $_GET['testimonial-page']; else $page = 1;
// default number of pages
$total_pages = 1;
// portfolio offset. Used in the get_posts() query to show only portfolio for the current page
$offset = $per_page * ($page-1);
// setup the portfolio args for retrieving the total number of portfolio items
$testimonial_count_args = array(
'post_type' => 'ncweb-testimonials',
'posts_per_page' => -1
);
$testimonial_count = count(get_posts($testimonial_count_args));
// calculate the total number of pages
$total_pages = ceil($testimonial_count/$per_page);
/* end pagination parameters */
// main image query
$testimonial_args = array(
'post_type' => 'ncweb-testimonials',
'numberposts' => $per_page,
'offset' => $offset
);
$testimonial_items = get_posts($testimonial_args);
// start our output buffer
ob_start();
if($testimonial_items) :
/*** main portfolio loop ***/
$counter = 1;
echo '<div class="testimonial-items" id="testimonial-items">';
foreach($testimonial_items as $testimonial_item) :
$testimonial_company = get_post_meta($testimonial_item->ID, 'ncweb_testimonial_company', true);
$testimonial_client = get_post_meta($testimonial_item->ID, 'ncweb_testimonial_client_name', true);
echo '<aside class="testimonial-list-item row">';
echo '<div class="col-xs-12 testimonial-list-item-info">';
echo '<div class="testimonial-image">'. get_the_post_thumbnail($testimonial_item->ID) .'</div>';
echo '<div class="testimonial-client"><span class="testimonial-client-name">'. $testimonial_client .'</span><br/><span class="testimonial-company">'. $testimonial_company .'</span></div>';
echo '</div>'; //end of testimonial-list-item-info
echo '<div class="col-xs-12 testimonial-item-content">'. get_the_content($testimonial_item->ID); .'</div>';
echo '</aside>';
$counter++;
endforeach;
echo '</div>';
/*** display pagination ***/
// pagination base
echo '<div id="testimonial-pagination">';
$base = get_permalink(get_the_ID()) . '%_%';
echo paginate_links(array(
'base' => $base,
'format' => '?testimonial-page=%#%',
'prev_text' => __('Previous', 'ncweb'),
'next_text' => __('Next', 'ncweb'),
'total' => $total_pages,
'current' => $page,
'end_size' => 1,
'mid_size' => 5
));
echo '</div>';
/*** end pagination display ***/
else :
echo '<p>' . __('No testimonial items found.', 'ncweb') . '</p>';
endif; // end if($images)
return ob_get_clean();
}
add_shortcode('testimonial-items', 'ncweb_display_testimonial_items');