如何显示相对 post 差异类别?

How to show relative post difference category?

目前,我可以按类别显示亲戚 post。有些分类我不是那么post,所以当我们点击文章时它会显示相关的post,但是那个分类中的post我不是那么更新,所以我想让用户看到other post 来自其他类别。 请看图清楚。Click here image for detail. 我想将 YOU ALSO MAY LIKE 上的文章更改为更新的文章,如果该类别没有 post.

,至少那些与其他类别的文​​章在 3 个月内

以下代码仅在您创建自定义分类法和自定义 post 类型时才有效。

希望对您有所帮助。

<div class="tab-content" id="tab-1">
<ul class="product_list sub_cat list_view02">
    <?php
    $postterms = wp_get_post_terms($post->ID, 'Your_Custom_Taxonomy_Name');   // get post terms
    $parentId = $postterms[0]->parent; 
    $term_id = $parentId;
    $taxonomy_name = 'Your_Custom_Taxonomy_name';
    $termchildren = get_term_children( $term_id, $taxonomy_name );
    foreach ( $termchildren as $child ) {
    $term = get_term_by( 'id', $child, $taxonomy_name );
    $args = array(
    'post_type' => 'Your_Custom_Post_Type_Name',
    'order' => 'desc',
    'tax_query' => array(
    array(
    'taxonomy' => 'Your_Custom_Taxonomy_Name',
    'field' => 'slug',
    'terms' => $term->slug,
    )
    )
    );
    $loop = new WP_Query( $args );
    $count=1;
    while ( $loop->have_posts() ) : $loop->the_post();
    $url = wp_get_attachment_url( get_post_thumbnail_id($loop->ID) );
    ?>
        <li><img alt="<?php the_title(); ?>" src="<?php echo $url?>" style="height: 150px; width: 150px;">
        <p><?php the_title(); ?></p>
        <div><?php echo get_the_content(); ?> </div>
        <a class="view_more pull-right" href="<?php the_permalink(); ?>">View Details</a>
        </li> 
    <?php endwhile;  
    }
    ?>
</ul>
</div>