Wordpress Themes - WP Forum at BFA

Wordpress Themes - WP Forum at BFA (http://forum.bytesforall.com/index.php)
-   Montezuma Theme (http://forum.bytesforall.com/forumdisplay.php?f=53)
-   -   related post (http://forum.bytesforall.com/showthread.php?t=19093)

fafa Dec 10, 2012 02:03 PM

related post
 
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' ) ); ?>



All times are GMT -6. The time now is 08:45 AM.

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