WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Tech Blue Theme - setting post length on front page (3 posts)

  1. Urmas
    Member
    Posted 4 years ago #

    Hi!

    I can't send you the link to the blog because it's under development and front page has been declared accordingly. Still, this is the theme I am working on currently: http://www.themelab.com/2008/02/29/free-release-15-tech-blue/

    The question:
    On front page where I see latest posts I can't seem to find a place to manually set the limit of post length. Sure I can set it "Limit post length" on options, but it does not seem to work.

    In index.php I have this line:
    <?php the_content('<br />Read rest of the post... &raquo;'); ?>
    but it does not limit the size.

    Where/How can I set the post length manually?

  2. vacmedia
    Member
    Posted 4 years ago #

    function the_content_limit($max_char, $more_link_text = '(more...)', $stripteaser = 0, $more_file = '') {
    $content = get_the_content($more_link_text, $stripteaser, $more_file);
    $content = apply_filters('the_content', $content);
    $content = str_replace(']]>', ']]>', $content);
    $content = strip_tags($content);

    if (strlen($_GET['p']) > 0) {
    echo "<p>";
    echo $content;
    echo " <a rel='nofollow' href='";
    the_permalink();
    echo "'>".__('Read More', 'studiopress')." →";
    echo "</p>";
    }
    else if ((strlen($content)>$max_char) && ($espacio = strpos($content, " ", $max_char ))) {
    $content = substr($content, 0, $espacio);
    $content = $content;
    echo "<p>";
    echo $content;
    echo "...";
    echo " <a rel='nofollow' href='";
    the_permalink();
    echo "'>".$more_link_text."";
    echo "</p>";
    }
    else {
    echo "<p>";
    echo $content;
    echo " <a rel='nofollow' href='";
    the_permalink();
    echo "'>".__('Read More', 'studiopress')." →";
    echo "</p>";
    }
    }

    Put the above code in functions.php and replace the funnction in index.php with

    <?php the_content_limit('200'); ?>

  3. Urmas
    Member
    Posted 4 years ago #

    It works perfectly. Thank you!

Topic Closed

This topic has been closed to new replies.

About this Topic