我一直在查询相关帖子。我需要相关的职位,以显示任何深度从主家长。我的网站上有以下结构类别:
- Category level 1
-- Category level 2
--- Category level 3
*---- Post in level 3*
--- Category level 3
*--- Post in level 3*
-- Category level 2
-- Category level 2
当我们看到*---- Post in level 3*
我们必须从*-- Category level 2*
ie所有包含此级别的帖子,包括child。这是我的代码:
<div class="related_goods">
<span>Related posts:</span>
<?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\'=>3,
\'orderby\'=>title,
\'post_parent\'=> array(),
\'caller_get_posts\'=>1);
$my_query = new wp_query($args);
if( $my_query->have_posts() ) {
while ($my_query->have_posts()) {
$my_query->the_post();
?>
<div class="block-related-item">
<div class="preview-wrap">
<div class="preview">
<? $thumb_url = wp_get_attachment_url(get_post_thumbnail_id($post->ID)); ?>
<a href="<?php the_permalink() ?>"><? the_post_thumbnail(\'category_thumbs\'); ?>
</a>
</div>
<a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a>
</div>
</div>
<?php
}
}
wp_reset_query();
}
?>
</div>
如何修改它以获得上述效果?提前多谢!