0
다음 코드를 사용하여 "educationposts"라는 카테고리의 게시물을 표시하는 WordPress 단축 코드 [educationposts]를 만듭니다.단축 코드 변수로 모든 카테고리 게시물을 가져 오는 WordPress 단축 코드 기능을 사용자 정의하는 방법은 무엇입니까?
감사
/*** show post category ***/
function pwp_postsbycategory() {
$the_query = new WP_Query(array('category_name' => 'education', 'posts_per_page' => 5));
if ($the_query->have_posts()) {
$string .= '<ul class="postsbycategory widget_recent_entries">';
while ($the_query->have_posts()) {
$the_query->the_post();
if (has_post_thumbnail()) {
$string .= '<li>';
$string .= '<a href="' . get_the_permalink() .'" rel="bookmark">' . get_the_post_thumbnail($post_id, array(75, 75)) . get_the_title() .'</a></li>';
} else {
// if no featured image is found
$string .= '<li><a href="' . get_the_permalink() .'" rel="bookmark">' . get_the_title() .'</a></li>';
}
}
} else {
// no posts found
}
$string .= '</ul>';
return $string;
/* Restore original Post Data */
wp_reset_postdata();
}
// Add a shortcode
add_shortcode('educationposts', 'pwp_postsbycategory');
/*** show post category ***/