• Hey guys,

    I just started using WordPress recently and so far I love it. Now, I’m stumbling through the fact that my homepage is getting crowed, and I want to limit the number of posts in it. How would I go about doing this? Thanks

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter adri_ht_

    (@adri_ht_)

    Never mind, I just found the option under Tools. One question thought, how would I go about showing only part of a post on the homepage. In other words, some kind of read more link? Thanks

    There are a couple of ways to accomplish this. Probably the easiest is simply to use the “more” button on the “write post toolbar”. The other option is to use excerpts.

    Your home page currently uses the template tag <?php the_content(); ?> so change that to <?php the_excerpt(); ?>

    When using excerpts WordPress will automatically pull the first 55 characters from your post and display that. If you want to change that add the following to your theme’s functions.php file …

    remove_filter('get_the_excerpt', 'wp_trim_excerpt');
    add_filter('get_the_excerpt', 'custom_trim_excerpt');
    
    function custom_trim_excerpt($text) { // Fakes an excerpt if needed
    global $post;
    if ( '' == $text ) {
    $text = get_the_content('');
    $text = apply_filters('the_content', $text);
    $text = str_replace(']]>', ']]>', $text);
    $text = strip_tags($text);
    $excerpt_length = x;
    $words = explode(' ', $text, $excerpt_length + 1);
    if (count($words) > $excerpt_length) {
    array_pop($words);
    array_push($words, '...');
    $text = implode(' ', $words);
    }
    }
    return $text;
    }

    Look for the line (from the above code) $excerpt_length = x; and change x to whatever you want. This comes with a caveat – you will lose any formatting the post had but its not a big deal. If you want to maintain formatting while using <?php the_excerpt(); ?> then use the Excerpt box below the Write Post box. Anything you enter into this box will be used to display your excerpts.(summaries) Here is a screenshot to show you what I’m talking about.

    More reading on the_content and the_excerpt

    What if I want to keep one HTML tag (the first part of every post on my site is an image) and discard the others?

    (FYI: I’m moving from a Xoops based site to WP …you can see how my site currently works at it’s address below).

    Thanks.

    Kermit Woodall
    Managing Editor
    [ Signature moderated. ]

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Homepage – Limiting number of posts’ is closed to new replies.