• Hi. I’m new to WordPress, so forgive me if this is something obvious. I’m using the dkret3 template, and I would like to only display a few lines of each post on my main page, with a “Read more” link for those who want to read the rest. Is this possible? If so, what do I need to do? Thanks for any help you can give me.

Viewing 13 replies - 1 through 13 (of 13 total)
  • Thread Starter lonsharkin51

    (@lonsharkin51)

    Never mind. I figured it out. It’s amazing what you can find if you just search around a little bit.

    how did you do it??

    i believe this will help

    function the_excerpt_more($text) {
    $url = get_permalink();
    $text = str_replace(“[…]”, “Read More“, $text);
    return $text;
    }
    add_filter(‘the_excerpt’, ‘the_excerpt_more’);

    just use the “more” button above the post editor which will insert this
    <!--more-->
    where you want the post to break

    ?? hell no, i think i give the wrong advice….

    Is there a way of displaying a limited amount of words on the index page and the whole post on the single post page whilst using this code in the function file:

    function my_excerpt_length($text){
    return 19;
    }
    add_filter('excerpt_length', 'my_excerpt_length');
    
    function new_excerpt_more($more) {
    	return '...';
    }
    add_filter('excerpt_more', 'new_excerpt_more');

    and this code in single page:

    <td>
    <?php images('2'); ?>
    </td>
    <td>
    <?php the_excerpt(); ?>
    </td>

    to pull in the images and copy in different locations.

    This won’t allow me to show the full excerpt though…

    Any suggestions? I’m so stuck…

    Has anyone got any suggestions?

    Cheers,
    H

    Hampus I think you need to differentiate the_content() and the_excerpt(), I have no idea why you would want to use the_excerpt() on a single.php page, there is better ways to paginate or limit output for those pages. If you want to control the excerpt you can hardcode it by adding the following in your functions.php (example will display 20 words only when the_excerpt() is used):

    function new_excerpt_length($length) {
    	return 20;
    }
    add_filter('excerpt_length', 'new_excerpt_length');

    you could create a function, which to add to functions.php of your theme, to make a your own excerpt, limited to a certain number of characters, and then reduced to the last full word:

    function intro_text($length) {
    global $post;
    $text = get_the_excerpt($post->ID);
    if (strlen($text) > $length) {
    $text = substr($text,0,strpos($text,' ',$length)) . ' ... <a href="' . get_permalink() . '">[ read more ]</a>'; } ;
    return apply_filters('the_excerpt',$text);
    }

    and in index.php, replace the_excerpt(); with intro_text(150);
    with 150 the desired length of the ‘excerpt’ in characters, which will be rounded down to the last full word.

    alexgraham,
    The reason for using excerpt on the single post pages is that I need to be able to choose where the text will go. If you have a look at https://www.projektinfo.blog and click on one of the posts, that’s how I want it to look. Is there a way of doing this without seperating the images and excerpt and inserting them in a table?

    alchymyth,
    Thanks heaps for that code! Unfortunately I can’t get it to work properly. I’ve inserted the code and all, but no difference at all…

    used

    function intro_text($length) {
    global $post;
    $text = get_the_excerpt($post->ID);
    if (strlen($text) > $length) {
    $text = substr($text,0,strpos($text,' ',$length)) . ' ... <a href="' . get_permalink() . '">[ read more ]</a>'; } ;
    return apply_filters('the_excerpt',$text);
    }

    with

    <?php intro_text(150); ?>

    Have no idea why it’s not working…
    Thanks though!

    Hampus

    my bad:
    the line should be: <?php echo intro_text(150); ?>

    hope it helps ??

    That’s perfect!

    Thank you so much for that!

    H

    Just wonder if there’s a way to make links live in excerpts? And even paragraphs?

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘How do I display only a few lines of a post?’ is closed to new replies.