Support » Fixing WordPress » Need help with related posts php

  • Hello!
    I’m using this code to show related posts by category.

    <?php
    $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),
    		'showposts'=>5, // Number of related posts that will be shown.
    		'caller_get_posts'=>1
    	);
    	$my_query = new wp_query($args);
    	if( $my_query->have_posts() ) {
    		echo '<h3>See also</h3><ul>';
    		while ($my_query->have_posts()) {
    			$my_query->the_post();
    		?>
    			<li><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></li>
    		<?php
    		}
    		echo '</ul>';
    	}
    }
    ?>

    The problem is that it shows also the post I’m currently viewing. How to change this code to make it show only other posts in that category?

    And another problem:
    I know how to change font size of that same recent posts widget but not sure how to change line height. Tried hours to find it from css but without results.

    Thanks!

  • The topic ‘Need help with related posts php’ is closed to new replies.