예를 들어 5 개의 게시물을 포함하는 일부 카테고리가 있습니다. 게시물을 선택할 때 나머지 카테고리에있는 4 개의 게시물을 표시해야합니다.single.php에이 single.php가있는 카테고리의 모든 게시물을 표시하는 방법
<?php
$categories = get_the_category($post->ID);
if ($categories) {
$category_ids = array();
foreach($categories as $individual_category) $category_ids[] = $individual_category- >term_id;
$args=array(
'category__in' => $category_ids,
'post__not_in' => array($post->ID),
'showposts'=>5 //
);
$my_query = new wp_query($args);
if($my_query->have_posts()) {
echo '<h3>Current category</h3><ul>';
while ($my_query->have_posts()) {
$my_query->the_post();
?>
<a href="<?php the_permalink() ?>" rel="bookmark" title=" <?php the_title_attribute(); ? >"><?php the_title(); ?>
<img src="<?php echo first_image() ?>"title="<?php the_title(); ?>" alt="<?php the_title(); ?>"/>
</a>
<?php
}
echo '</ul>';
}
}
?>
시도한 현재 코드를 알려주십시오. –
전체 게시물 내용을 원하면 the_content()를 추가해야합니다. – enapupe