Results 1 to 10 of 10

Thread: Related Posts in Single Page - how are they related?

  1. #1
    pschena
    Guest

    Related Posts in Single Page - how are they related?

    I have checked 'Enable related posts in Single page' which is handy, just a little unclear as to what the relationship is between the posts.

    What logic is employed to generate the 'related' posts?
    Doesn't look like posts from the same category, so just a little unsure.

    Thanks in advance.

  2. #2
    Junior Member
    Join Date
    Jul 2011
    Posts
    1
    Quote Originally Posted by pschena View Post
    I have checked 'Enable related posts in Single page' which is handy, just a little unclear as to what the relationship is between the posts.

    What logic is employed to generate the 'related' posts?
    Doesn't look like posts from the same category, so just a little unsure.

    Thanks in advance.
    I would also like to know this, if it is possible I'd like to use related posts by category rather than tag

  3. #3
    Junior Member
    Join Date
    Jan 2012
    Posts
    4
    I'm also trying to figure this out

  4. #4
    Junior Member
    Join Date
    Feb 2012
    Posts
    12
    Found a useful post here. I integrated the code and it works!

  5. #5
    Junior Member
    Join Date
    Nov 2011
    Posts
    8
    Hi tlai , Thanks for the suggestion! Did you copy the exact text and did you add it in loop-single.php or in single.php
    So were you able to integrate the code in the existing structure with the boxes? If so can you please let me know what code you used and maybe a link to the outcome? Thanks in advance!

  6. #6
    Junior Member
    Join Date
    Feb 2012
    Posts
    12
    The code provided by the wpbeginner post styles the related posts to display in list style format. So to display the related posts in the same box structure I made a few changes to the code. I am currently using it on my site http://www.tina-lai.com. If you want to see the outcome just click on any post and see at the bottom the related posts are from the same category.


    The code is to be placed in loop-single.php
    replace from where <div class="recent clear"> begins, through to the last div
    Code:
    <div class="recent clear">
    	    <?php $orig_post = $post;
        global $post;
        $categories = get_the_category($post->ID);
        if ($categories) {
        $category_ids = array();
        foreach($categories as $individual_category) $category_ids[] = $individual_category->term_id;
    
        $args=array(
        'category__in' => $category_ids,
        'post__not_in' => array($post->ID),
        'posts_per_page'=> 4, // Number of related posts that will be shown.
        'caller_get_posts'=>1
        );
    
        $my_query = new wp_query( $args );
        if( $my_query->have_posts() ) {
        echo '<div id="related">';
        while( $my_query->have_posts() ) {
        $my_query->the_post();?>
    
       
    	
    	<div class="box">
    		<div class="rel">
    			<a href="<?php the_permalink(); ?>"><?php the_post_thumbnail('homepage-thumb', array('alt' => '', 'title' => '')) ?></a>
    	<?php if ($imbalance2_theme_options['images_only'] == 0): ?>
        		<h1><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
    			<div class="categories"><?php imbalance2_posted_in(); ?></div>
    	<?php endif ?>
    			<div class="texts">
    	<?php if ($imbalance2_theme_options['images_only'] == 1): ?>
    				<a class="transparent" href="<?php the_permalink(); ?>"><?php the_post_thumbnail('homepage-thumb', array('alt' => '', 'title' => '')) ?></a>
    	<?php endif ?>
    				<div class="abs">
    	<?php if ($imbalance2_theme_options['images_only'] == 0): ?>
    				<a href="<?php the_permalink(); ?>"><?php the_post_thumbnail('homepage-thumb', array('alt' => '', 'title' => '')) ?></a>
    	<?php endif ?>
        				<h1><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
    					<div class="categories"><?php imbalance2_posted_in(); ?></div>
    				</div>
    			</div>
    		</div>
    	</div>
    	
    	
    	
        <?
        }
        echo '</div>';
        }
        }
        $post = $orig_post;
        wp_reset_query(); ?>
    	
    	
    </div>

  7. #7
    Junior Member
    Join Date
    Feb 2012
    Posts
    2
    Hello, tiai!

    I looked zt your website and I found out that you have managed to solve a problem that I can't solve: how to remove the comments, the "share in facebook / twitter" and "written by" next to the posts? How to keep just images and text without dates or comments?

    here is my website, I am really struggling to make it work:
    http://montaneinberga.com/WordPress3/
    Thanks a lot for any advice!

  8. #8
    Junior Member
    Join Date
    Feb 2012
    Posts
    12
    To remove social networks see this other post. Remove "Social Network" + "No comment" in every page and article

    To get rid of the dates, posted by, etc. You need to delete few lines in loop-single.php.
    This is the previous / next navigation bar.
    Code:
    <div id="nav-above" class="navigation">
    						<div class="nav-previous">
    	<?php if (get_previous_post(false) != null): ?>
    							<?php previous_post_link( '%link', ' Previous' ); ?>
    	<?php else: ?>
    							 Previous
    	<?php endif ?>
    						</div>
    						<span class="main_separator">/</span>
    						<div class="nav-next">
    	<?php if (get_next_post(false) != null): ?>
    							<?php next_post_link( '%link', 'Next ' ); ?>
    	<?php else: ?>
    							Next 
    	<?php endif ?>
    						</div>
    					</div><!-- #nav-above -->


    This shows the published date, author, comments, etc.
    Code:
    <div class="entry-meta">
    						<?php imbalance2_posted_by() ?>
    						<span class="main_separator">/</span>
    						<?php imbalance2_posted_on() ?>
    						<span class="main_separator">/</span>
    						<?php imbalance2_posted_in() ?>
    						<span class="main_separator">/</span>
    	<?php if ( get_comments_number() != 0 ) : ?>
    						<a href="#comments"><?php printf( _n( 'One Comment', '%1$s Comments', get_comments_number(), 'imbalance2' ),
    							number_format_i18n( get_comments_number() )
    						); ?></a>
    	<?php else: ?>
    						<a href="#comments">No Comments</a>
    	<?php endif ?>
    					</div><!-- .entry-meta -->

  9. #9
    Junior Member
    Join Date
    Feb 2012
    Posts
    2
    thanks tlai, it worked like a charm!!

  10. #10
    I've applied your code and it works beautifully, but can you point out what I would need to change in order to show posts related by tag instead of category? Thanks so much!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •