Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am having a wordpress blog at http://thelazy.info/ . By default, only one post is displayed on the page. I want to increase the default content on the main page to 5-10 posts with a small ting of comments. Is there some plugin or setting to do that in buddypress/wordpress.

share|improve this question
add comment

1 Answer 1

up vote 1 down vote accepted

By default, only one post is displayed on the page

I can see several posts on your main page(6 total), please clarify what you mean.

with a small ting of comments.

Sorry, what?

More details/clarification please. Would have liked to have posted this as a comment but i'm not sure if you can quote properly there.. (feel free to down vote if anyone feels this is a misuse of the answer).

Based on the minimal information provided here's one possible solution.

Show latest comment after each post on the index.

Assumes is_home() is true and applicable for the use case. After the <?php if( have_posts() ) ?> line, but before <?php while( have_posts() ) : ?>..

.. put the following code.

<?php if( is_home() ) $_comment_walk = new Walker_Comment; ?>

Then, just before the closing part of the while loop, that's this part <?php endwhile; ?>, place the following..

<?php if( is_home() ) : ?>

    <div style="border:3px solid #000;padding:10px">

    <?php
    $_last_comment = get_comments( 'number=1&post_id=' . get_the_ID() );
    $_comment_walk->paged_walk( 
        $_last_comment, 0, 1, 1, 
        array( 'style' => 'div', 'avatar_size' => 40, 'max_depth' => 1 ) 
    );
    ?>

    </div>

<?php endif; ?>

NOTE: The div with the big border is just to make the box standout so you can see the result easily, remove or add to the code as you like and of course feel free to re-position it elsewhere inside the post loop if you like..(i assumed after the post was appropriate).

Why did i use the comment walker?

  • The comment gets output the same as it would in a single post instance, and the walker takes care with sanitizing for you.

Why did i set the walker before the while loop?

  • So we reuse that same walker instance, rather then creating a new one with each post iteration

Hope that helps... :)

share|improve this answer
    
I changed the number of posts to 6 from the settings available in the available in the "Reading" panel of the administrative interface. At the comments I think I need some plugin which shows users say a box on the main page for the comments or some preview of the comments on the main page itself. –  Abhishek Gupta Dec 20 '10 at 4:00
    
Have provided a working example for you above.. ;) –  t31os Dec 22 '10 at 12:44
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.