我需要一些帮助。我创建了此代码以按子类别显示相关帖子,但如果没有子类别,我需要按类别显示相关帖子。
<?php
$categories = get_the_category(); foreach( $categories as $category ){
if( 0 != $category->parent )
$child_cat = $category; } else
{ $child_cat = get_the_category(); }
$args = array(
'post_type' => 'post',
'cat' => $child_cat->term_id,
'posts_per_page' => 3, //cantidad
'orderby' => 'post_date',
'post__not_in' => array( get_the_ID() )
);
$related = new WP_Query( $args ); if( $related->have_posts() ) :
while( $related->have_posts() ) :
$related->the_post();
$thumb_id = get_the_post_thumbnail( $page->ID, 'medium' );
?>
我知道我做错了什么,但我不明白。
谢谢!