【问题标题】:How to show relative post difference category?如何显示相对职位差异类别?
【发布时间】:2017-05-08 05:08:14
【问题描述】:

目前,我可以按类别显示相关帖子。某些类别我不是那么发布,所以当我们点击文章时它会显示相关帖子,但是该类别的帖子我没有那么更新,所以我希望用户看到其他类别的其他帖子。 请看图片清楚。Click here image for detail. 我想将您也可能喜欢的文章更改为更新文章,如果该类别没有帖子,至少在 3 个月内来自其他类别。

【问题讨论】:

  • 到目前为止您尝试过什么吗?那些部分是如何显示在那里的?使用自定义代码?还是wordpress插件?请更新您的问题并提供更多详细信息。像现有的代码和所有

标签: wordpress wordpress-theming custom-wordpress-pages


【解决方案1】:

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

我希望这会对你有所帮助。

<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>

【讨论】:

  • 好的,谢谢您的精彩回答,但是如果我不使用自定义分类法和自定义帖子类型,那么如何解决这个问题?
  • 因为通常情况下,我们已经有帖子,所以如果我们创建自定义分类和自定义帖子类型,我们也需要将所有帖子移至该位置。但我会先尝试。谢谢你尽力解决我。 :)
猜你喜欢
  • 1970-01-01
  • 2018-05-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-04-23
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多