Show relative post with specific cagetory wordpress

Currently, it show relative post by the category as WordPress provide. But some categories is not so post, so when we go to single post it will be see relative post by category but some post since 1 year, so I want to update it and show by specific category to replace if the current category no post during 1 month but if other 1 month or 2 month it have post it will show the same category as normal. Ex: I have 3 category (A,B,C) so Category name ( C ) not have post but I have hidden category (D in my problem D = feature post that view on my slideshow but not in Menu) so I want that, when Category (C) no post during 1 month, it will call other post from category (D) but if over 1 month or 2 month and Category (C) have post it will go to show the same category as normal.

Here is related-posts.php

<?php if ( $related_posts->have_posts() ): ?>

have_posts() ) : $related_posts->the_post(); ?>

” title=””>

  <div class="article-content">

     <h3 class="entry-title">
        <a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a>

     <div class="below-entry-meta">
           $time_string = '<time class="entry-date published" datetime="%1$s">%2$s</time>';
           $time_string = sprintf( $time_string,
              esc_attr( get_the_date( 'c' ) ),
              esc_html( get_the_date() )
           printf( __( '<span class="posted-on"><a href="%1$s" title="%2$s" rel="bookmark"><i class="fa fa-calendar-o"></i> %3$s</a></span>', 'colormag' ),
              esc_url( get_permalink() ),
              esc_attr( get_the_time() ),
        <span class="byline"><span class="author vcard"><i class="fa fa-user"></i><a class="url fn n" href="<?php echo esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ); ?>" title="<?php echo get_the_author(); ?>"><?php echo esc_html( get_the_author() ); ?></a></span></span>
        <span class="comments"><i class="fa fa-comment"></i><?php comments_popup_link( '0', '1', '%' );?></span>


And here is in single.php

    <?php get_template_part( 'content', 'single' ); ?>
    <div class="row related-postss">
      <div class="col-md-12 main-relates" style="border-top: 2px solid #000;width: 93%; margin-left: 26px; padding: 1px; margin-top:20px;">
          if ( get_theme_mod( 'colormag_related_posts_activate', 0 ) == 1 ){
            get_template_part( 'inc/related-posts' );
  <?php endwhile; ?>

</div><!-- #content -->

  <?php get_template_part( 'navigation', 'single' ); ?>

  <?php if ( get_the_author_meta( 'description' ) ) : ?>

  <?php endif; ?>

     do_action( 'colormag_before_comments_template' );
     // If comments are open or we have at least one comment, load up the comment template
     if ( comments_open() || '0' != get_comments_number() )
     do_action ( 'colormag_after_comments_template' );

I hope everyone can understand and know what I am needing. If don’t understand some part please comment to me back. Thank for advance!

Read more here: Show relative post with specific cagetory wordpress

Leave a Reply

Your email address will not be published. Required fields are marked *