WordPress.org

Ready to get started?Download WordPress

Forums

Help with 'Most Commented' and post images plugin.... (2 posts)

  1. NeilC
    Member
    Posted 6 years ago #

    Hi everyone

    I'm working on a new WordPress theme for my blog. It uses the http://guff.szub.net/post-image
    plugin for pulling up an image with each post.

    However, I'm now trying to incorporate this feature with a 'Most Commented' plugin, i.e. taking something like http://mtdewvirus.com/code/wordpress-plugins/ and some how fitting the call to the database for the post_image() somewhere in the script.

    Or, maybe we could re-do the following script, which I already use for a list of recent posts, so that it calls the three most commented posts, rather than the three most recent...

    <?php
    $imgposts = new WP_Query('showposts=3');
    if($imgposts->have_posts()) : while($imgposts->have_posts()) : $imgposts->the_post(); ?>
    	<ul class="recentposts">
    		<li class="recent_post clearfix" id="post-<?php the_ID(); ?>">
    			<div class="posttitle clearfix">
    				<a class="postimagelink" href="<?php the_permalink(); ?>"><img alt="Post icon" class="postimage" src="<?php post_image('shared/images/post_default.png', false, false); ?>" width="35" height="35" /></a>
     				<h2><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h2>
    				<p class="meta">
    				Posted <?php the_date('d-m-y'); ?> under <?php the_category(' &amp; ') ?> | <?php comments_popup_link('Comments (0)', 'Comments (1)', 'Comments (%)', 'commentlink', ''); ?> </p>
    			</div>
    		</li>
    	</ul>
    <?php endwhile; endif; ?>

    If you can help me with this - you're a superstar!

  2. NeilC
    Member
    Posted 6 years ago #

    Found the fix. I read through the mountains of comments left on the authors post for the plugin, and 'Reid Beels' suggested altering a 'couple of the global calls' at the top of the plugin file (didn't say which exactly).

    I've replaced these lines (51 & 52);

    `global $post, $posts, $wp_version, $wpdb;
    global $post_image_attachments;`

    With these;

    `global $post, $wp_version, $wpdb, $wp_query;
    global $post_image_attachments;

    if($wp_query->posts!=$posts)
    $post_image_attachments='';

    $posts = $wp_query->posts;`

    As you've seen in my previous comment, I've been using $imgposts = new WP_Query('showposts=5'); to pull up the 'Recent Post' images, whereas Reid Beel says that he uses query_posts()

    So I changed my calls to WordPress to use the following;

    <?php query_posts('showposts=3'); ?>
    
    			  <?php while (have_posts()) : the_post(); ?>
    				<ul class="recentposts">
    					<li class="recent_post clearfix" id="post-<?php the_ID(); ?>">
    						<div class="posttitle clearfix">
    							<a class="postimagelink" href="<?php the_permalink(); ?>"><img alt="Post icon" class="postimage" src="<?php post_image('/shared/images/post_default.jpg', false, false); ?>" width="35" height="35" /></a>
    			 				<h2><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h2>
    							<p class="meta">
    							Posted <?php the_date('d-m-y'); ?> under <?php the_category(' &amp; ') ?> | <?php comments_popup_link('Comments (0)', 'Comments (1)', 'Comments (%)', 'commentlink', ''); ?> 
    
    						</div>
    					</li>
    				</ul>
    			<?php endwhile; ?>

    And if you check the 'Recent Posts' section on my homepage, http://dotneil.com you'll see that all the icons and the commentlinks show! I've been working on this one for ages, so I'm very pleased!

Topic Closed

This topic has been closed to new replies.

About this Topic