1
는, 아래에서 논의 문제와 제발 도와주세요 다른 카테고리를 쿼리 작동하지 않습니다 :워드 프레스 단축 코드는
나는이 단축 코드를 등록 : [category_post title="world news" category="world news" link="#"]
는 서로 다른 범주를 호출 할 수 있습니다. 그러나 문제는 내가 하나의 카테고리를 게시하고 선택할 때 게시물이 모든 카테고리에 표시된다는 것입니다. 그러나 나는 이것을 원하지 않는다. 짧은 코드에서 언급 된 해당 카테고리에만 해당 게시물을 표시하고 싶습니다. 누구든지이 문제를 해결하도록 도와 줄 수 있습니까? 의 picture에서 참조하시기 바랍니다 또한 내가 여기에 유에게 기능을 준 :
/* Register shortcode for querying custom category post *********/
function category_post_shortcode($atts){
extract(shortcode_atts(array(
'title' => '',
'link' => '',
'category' => '',
), $atts, 'category_post'));
$q = new WP_Query(
array('category' => $category, 'posts_per_page' => '4', 'post_type' => 'post')
);
$list = '<div class="latest_from_category"><h2 class="latest_frm_cat_title">'.$title.'</h2> <a href="'.$link.'" class="latest_more_link">more</a>';
while($q->have_posts()) : $q->the_post();
//get the ID of your post in the loop
$id = get_the_ID();
$post_excerpt = get_post_meta($id, 'post_excerpt', true);
$post_thumbnail= get_the_post_thumbnail($post->ID, 'post-thumbnail');
$list .= '
<div class="single_cate_post floatleft">
<a href="'.get_permalink().'">'.$post_thumbnail.'</a>
<a href="'.get_permalink().'"><h3>'.get_the_title().'</h3></a>
<p>'.$post_excerpt.'</p>
<a href="'.get_permalink().'" class="readmore">বিস্তারিত</a>
</div>
';
endwhile;
$list.= '</div>';
wp_reset_query();
return $list;
}
add_shortcode('category_post', 'category_post_shortcode')
대단히 감사합니다. 문제가 해결되었습니다 –
아무 문제 없습니다, 스택에 오신 것을 환영합니다! –