How work related articles on post page?

March 2014 WordPress Theme
GK User
Wed Apr 15, 2015 8:04 pm
How work related articles on post page? What rules? Tags,Categories, Other?
User avatar
Junior Boarder

GK User
Thu Apr 16, 2015 8:13 am
Hi,
Related articles are based on Tags.
User avatar
Moderator

GK User
Thu Apr 16, 2015 9:43 am
Ok thx!
User avatar
Junior Boarder

GK User
Mon Jun 15, 2015 9:40 am
How to change related articles to "Categories" ?
User avatar
Fresh Boarder

GK User
Mon Jun 15, 2015 9:54 am
It requires theme modifications - unfortunately beyond our technical support.
User avatar
Moderator

GK User
Mon Jun 15, 2015 12:13 pm
Hi;

Please let us know what to update in Theme. We will try ourself
User avatar
Fresh Boarder

GK User
Tue Jun 16, 2015 7:24 am
Sure, please check News2/layouts/content.post.footer.php file (lines from 52 to 91)
User avatar
Moderator

GK User
Mon Jun 22, 2015 11:50 am
Thanks. We did the updated content.post.footer.php

1. Now its showing related posts based on Categories
2. And it will show 10 related Posts (not just 4)

Code: Select all
<?php

/**
 *
 * The template fragment to show post footer
 *
 **/

// disable direct access to the file   
defined('GAVERN_WP') or die('Access denied');

global $gk_tpl, $post;



$tag_list = get_the_tag_list( '', __( ' ', GKTPLNAME ) );

$params = get_post_custom();
$params_aside = isset($params['gavern-post-params-aside']) ? $params['gavern-post-params-aside'][0] : false;
$params_image = isset($params['gavern-post-params-image']) ? esc_attr( $params['gavern-post-params-image'][0] ) : 'Y';

$param_aside = true;
$param_tags = true;

if($params_aside) {
  $params_aside = unserialize(unserialize($params_aside));
  $param_aside = $params_aside['aside'] == 'Y';
  $param_tags = $params_aside['tags'] == 'Y';
}
?>

   <?php if(is_singular()) : ?>
      
      <?php do_action('gavernwp_after_post_content'); ?>
      
      <?php if(get_post_meta(get_the_ID(), "_gavern-featured-video", true) != '' && has_post_thumbnail() && $params_image ) : ?>
         <?php echo '<h3 class="video-block">' . __('Media', GKTPLNAME) . '</h3>'; ?>
         <div class="gk-video-wrap">
         <?php echo get_post_meta(get_the_ID(), "_gavern-featured-video", true); ?>
         </div>
      <?php endif; ?>
      
      <?php gk_post_fields(); ?>
   
      <?php if($tag_list != '' && $param_tags): ?>
      <dl class="tags">
         <dt><?php _e('Tagged under', GKTPLNAME); ?></dt>
         <dd><?php echo $tag_list; ?></dd>
      </dl>
      <?php endif; ?>      
      
      <?php if (is_single()) : ?>
         <?php if(get_option($gk_tpl->name . '_show_related', 'Y') == 'Y') : ?>
         <?php
         $category_id = wp_get_post_categories( $post->ID, array( 'fields' => 'ids' ) );
         $exclude = array($post->ID);
         $args = array(
               'category__in' => $category_id,
               'post__not_in' => $exclude,
               'posts_per_page' => 10
               );
         $related = new WP_Query($args);      
         ?>
         
         <?php if ( $related->have_posts() ) : ?>
            <div class="gk-related-posts">
            <h3><?php _e('Related Posts', GKTPLNAME); ?></h3>
            <?php while ( $related->have_posts() ) : $related->the_post(); ?>
               <div>
                  <?php if(has_post_thumbnail()) : ?>
                  <figure class="featured-image">
                     <a href="<?php the_permalink(); ?>">
                        <?php the_post_thumbnail('medium'); ?>
                     </a>
                  </figure>
                  <?php endif; ?>
                  <header>
                     <h3>
                        <a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', GKTPLNAME ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark">
                           <?php the_title(); ?>
                        </a>
                     </h3>
                  </header>
               </div>
            <?php endwhile; ?>
            </div>
         <?php else : ?>
            <p><?php _e( 'Apologies, but no related posts were found.', GKTPLNAME ); ?></p>
         <?php endif; ?>
         <?php wp_reset_query(); ?>
         <?php endif; ?>
         
         <?php if(get_option($gk_tpl->name . '_show_author_posts', 'Y') == 'Y') : ?>
         <?php
         $args_author = array(
               'author' => get_the_author_meta( 'ID' ),
               'posts_per_page' => 5
               );
         $author_posts = new WP_Query($args_author);      
         ?>
         
         <?php if ( $author_posts->have_posts() ) : ?>
            <div class="gk-author-posts">
            <h3> <?php printf( __( 'Latest from %s ', GKTPLNAME ), get_the_author_meta('display_name', get_the_author_meta( 'ID' )) ); ?></h3>
            <ul>
            <?php while ( $author_posts->have_posts() ) : $author_posts->the_post(); ?>
               <li>   
                  <a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', GKTPLNAME ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark">
                     <?php the_title(); ?>
                  </a>
               </li>
            <?php endwhile; ?>
            </ul>
            </div>
         <?php else : ?>
            <p><?php _e( 'Apologies, but no posts were found.', GKTPLNAME ); ?></p>
         <?php endif; ?>
         <?php wp_reset_query(); ?>
         <?php endif; ?>
      <?php endif; ?>
         
      <?php if(gk_author(false, true)): ?>
      <footer>
         <?php gk_author(); ?>
      </footer>
      <?php endif; ?>
   <?php endif; ?>
   </div>
</div>
User avatar
Fresh Boarder

GK User
Mon Jun 22, 2015 2:34 pm
Great, thank you for sharing the solution with other users.
User avatar
Moderator


cron