• Hey Everyone.

    I am hung up on something so I wanted to see you had any suggestions.

    1) I am using the wp-postviews plugin
    2) I am on wordpress 2.9
    3) str_img_src() is in the themes functions.php file

    I am using the following code in the sidebar.php template file to pull the 5 most popular posts.

    <?php
    	$most_viewed = new WP_Query('v_sortby=views&v_orderby=desc&show_posts=5');
    		if ( $most_viewed->have_posts() ) : while ( $most_viewed->have_posts() ) : $most_viewed->the_post();
    			$content = get_the_content();
    			$image = str_img_src( get_the_content() );
    			$title = get_the_title();
    ?>
    
    <li>
    	<a href="<?php the_permalink(); ?>"><img src="<?php bloginfo('home'); ?>/thumb.php?src=<?php echo $image ?>&h=50&w=72&zc=1" alt="" />
    <h4><?php echo $title; ?></h4>
    <p><?php echo $content; ?></p>
    	</a>
    </li>
    
    <?php
    	endwhile; endif;
    ?>

    On a single post or page: the code works perfect, title, image, and content.

    On an archive page or the home page: the title shoes up, but there is no content or image.

    Do you see anything that would be making this happen?

Viewing 1 replies (of 1 total)
  • immediately after $content = get_the_content(); add a echo $content; to see if the content retrieved is blank.

    Before $most_viewed = new WP_Query('v_sortby=views&v_orderby=desc&show_posts=5');

    You might want to add a wp_reset_query(); to it.

Viewing 1 replies (of 1 total)
  • The topic ‘most viewed posts on homepage’ is closed to new replies.