• I have a “Most commented” thing on my sidebar. The posts with the most comments get displayed there like this:

    Title of post (5)

    5 is the number of comments. Is there a way to add the word “replies” after the number so that it looks like this:

    Title of post (5 replies)

    ??

Viewing 5 replies - 1 through 5 (of 5 total)
  • If this is a widget you need to check the properties, maybe you can say that there.
    if not it seems you have to manipulate the source code of that widget.

    Therefor the name of the widget would be helpfull.

    Mog

    Thread Starter giantman

    (@giantman)

    Yes it’s a widget. Came with the “Fazio” theme. It’s titled “Top Commented Posts” but there are no settings for adding anything.

    Alright so I have to find out where the code for the widget is, find the place where it returns the number of comments for the top posts, and then add “Replies” so that it results as:

    Title of post (5 replies)

    I have no idea what I’m looking for though.

    Thread Starter giantman

    (@giantman)

    Found it.

    // TopCommentedPosts widget
    class topCommented_Widget extends WP_Widget
    {
    
    	function topCommented_Widget()
    	{
    		parent::WP_Widget(false, $name = __('Top Commented Posts', 'fazio'));
    	}
    
    	/** @see WP_Widget::widget */
    	function widget($args, $instance)
    	{
    		extract( $args );
    
    		// Extract config vars
    		$title = apply_filters('widget_title', $instance['title']);
    		$quantity_to_show = $instance['quantity_to_show'];
    		if(!is_numeric($quantity_to_show) OR $quantity_to_show == '0')
    		{
    			$quantity_to_show = 5;
    		}
    
    		// Make the widget
    		echo $before_widget;
    
    		echo $before_title;
    
    		if($title) {
    			echo $title;
    		} else {
    			_e('Top Commented Posts', 'fazio');
    		}
    
    		echo $after_title;
    
    		$top = new WP_Query();
    		$top->query('showposts=' . $quantity_to_show . '&orderby=comment_count');
    
    		if($top->have_posts())
    		{
    		?>
    			<ul>
    				<?php
    				while ($top->have_posts())
    				{
    					$top->the_post();
    				?>
    					<li>
    						<a href="<?php the_permalink();?>"><?php the_title(); ?></a> (<?php echo get_comments_number(); ?>)
    					</li>
    		<?php
    				}
    		}
    		?>
    			</ul>
    
    		<?php
    		echo $after_widget;
    	}

    The “quantity to show” is the number of posts. So if quantity = 5 then it will show the top 5 posts, if quantity = 10 then it shows the top 10 most commented posts.

    I don’t know where the actual comment number value is…anyone?

    toward the bottom, this line here:

    <a href="<?php the_permalink();?>"><?php the_title(); ?></a> (<?php echo get_comments_number(); ?>)

    change it to

    <a href="<?php the_permalink();?>"><?php the_title(); ?></a> (<?php echo get_comments_number(); ?> Replies)
    Thread Starter giantman

    (@giantman)

    ahh there we go it worked.

    thanks rev. voodoo

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Number of comments’ is closed to new replies.