Wordpress Themes - WP Forum at BFA
Click here to register or to donate.
Auto self-registration is not available here - far too many spammers. This forum has many, many backlinks and because of that there is an intense desire among spammers to drop their links here.

Wordpress Themes - WP Forum at BFA » WordPress Themes » Montezuma Theme »

related post


  #1  
Old Dec 10, 2012, 02:03 PM
fafa
 
39 posts · Dec 2012
hi

I use the code below in single.php of my previuse theme and show related post below of each post . I don't like use plugin .

but the code don't work here

PHP Code:
<?php
/********** CODE BLOCK2 (BASED ON ALL COMMON CATEGORIES) *********
* @Author: Boutros AbiChedid
* @Credit: http://bacsoftwareconsulting.com/blog/
* @Date:   May 24, 2011
* Tested on WordPress version 3.1.2
* @Description: Code that shows other "Related Posts" to a post
* based on ALL COMMON categories.
*******************************************************************/

//Retrieve the list of categories for a post.
$categories get_the_category($post->ID);
 
//If categories exist for the post.
if ($categories) {
    
$category_ids = array();
 
    
//retrieve the category_ids for the post.
    
foreach($categories as $each_category)
        
$category_ids[] = $each_category->term_id;
 
    
//WP_Query arguments.
    
$args = array(
        
'category__in' => $category_ids//An array of category IDs to be included.
        
'post__not_in' => array($post->ID), //An array of post IDs to be excluded from the results.
        
'orderby'=> 'rand'//Lists Related posts Randomly. *** MODIFY IF YOU LIKE ***
        
'showposts' => 7//*** MODIFY TO WHAT YOU LIKE.***  Number of related posts to show.
        //'caller_get_posts' => 1 //*** USE THIS IF YOU ARE RUNNING WordPress Version < 3.1 ***
        
'ignore_sticky_posts' => //*** USE THIS for WordPress Version >= 3.1 ***
    
);

//WP_Query is a class defined in wp-includes/query.php
$query = new WP_Query($args);

    
//If there are related posts.
    
if( $query->have_posts() ) {
        echo 
'<div class="related">';
        echo 
'<h3>پست های مشابه :</h3><ol>'//*** MODIFY TITLE IF YOU LIKE ***

        //loop through the posts and list each until done.
        
while ($query->have_posts()) {
            
$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 
'</ol>';
        echo 
'</div>';
    }
}
//Destroy the previous query. This is a MUST, otherwise you will get the WRONG comments
//(comments assigned to the wrong post), and sometimes categories and tags are for the wrong post.
wp_reset_query();
?>

I want it show in single.php above this line:

PHP Code:
<?php edit_post_link__"Edit"'montezuma' ) ); ?>

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Add related php code to sidebar sidejack Sidebars & Widgets 4 Sep 19, 2011 05:56 PM
[SOLVED] 'Related post by category' widget? taylorefl Sidebars & Widgets 0 Jan 21, 2010 03:56 PM
category pages - with just the linked title, author, date of each related post janey73 Atahualpa 3 Wordpress theme 2 Jun 25, 2009 01:11 PM


All times are GMT -6. The time now is 03:49 PM.


Powered by vBulletin® Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.