WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Excerpt and 'read more' on the same line? (9 posts)

  1. robolist
    Member
    Posted 3 years ago #

    I am having a small problem with the excerpt and 'read more' function.

    My theme is a custom theme and i am trying to fix this problem without using a plugin (but if i have to use a plugin then i will)...

    My 'read more' link must sit on the same line as my excerpt, but my excerpt is totally separate to the post copy which is why i cant use the 'more' tag on the posts.

    So instead i am placing;
    <a href="<?php echo get_permalink(); ?>"> Read more &raquo; <?php echo get_the_title(); ?></a>

    directly after;
    <?php the_excerpt(); ?>

    The problem i am facing now is that the 'read more' link comes on the next line, but i really want it to be placed on the same line as the excerpt...

    I understand this is not easy because the excerpt function is automatically placed into a <p>...

    I am wondering if there is any way round this? That is without changing the core functions of wordpress.. of course there might be a way to do it there, but when i upgrade i will have to do it again..

    I would be very grateful if anyone out there has a solution for this, because i have search everywhere without luck...

    Cheers

  2. esmi
    Forum Moderator
    Posted 3 years ago #

    This can probably be fixed with CSS.

  3. robolist
    Member
    Posted 3 years ago #

    Hi esmi,

    thanks for replying to me :)

    I am trying a few things out with CSS, but that might make it a bit messy (I guess that shouldn't matter, as long as the outcome is to the desired effect)... Also this would always give me IE compatibility issues... Which is why I was hoping for a better solution... :)

  4. inhouse
    Member
    Posted 2 years ago #

    @robolist, did this solve your issue? I understand what you're saying where the More link is not part of the excerpt text paragraph and therefore, it's difficult to use CSS to make it appear in line. The link provided by alchymyth to the Codex doesn't solve the issue as far as I can see when I test.

    Whether I manually enter in the more link to my template or use the functions code the more link is added after the paragraph closes.

    <a href="<?php echo get_permalink(); ?>"> Read More...</a>

    What CSS could be used? If I try to treat the more link like an image and float it right I can't get the text to wrap. And even then it's not as good as the link appearing inline.

    The only way I think it can work is using <?php the_content('Read on...'); ?> instead of excerpt. Is this true?

  5. if the codex suggestion does not work, there is likely something else the reason; possibly another filter function (?);

    alternatively, try this (without the filter function from the quoted codex chapter):

    <?php echo apply_filters('the_excerpt',get_the_excerpt().'<a href="'.get_permalink().'"> read more </a>'); ?>

    have you checked the html in the browser that the actual paragraph tag is (wrongly) closed before the link?

    what theme are you using?

  6. inhouse
    Member
    Posted 2 years ago #

    alchmyth, that did it. Thanks for your help. I had been around and around with this and yes I had verified that the paragraph was indeed closing before the more link. Theme is custom.

  7. robolist
    Member
    Posted 2 years ago #

    @alchymyth & @inhouse

    alchymyth was right, it was closing the paragraph tag, so after apply the function pretty much the same as he suggested it worked.

    My apologies i should have closed this thread a while ago but totally forgot i had it open. Thanks for your help guys :)

  8. gopalb123
    Member
    Posted 2 years ago #

    <?php echo apply_filters('the_excerpt',get_the_excerpt().'<a href="'.get_permalink().'"> read more </a>'); ?>
    It's working.. but i want limit the excerpt length in 40 words...
    any help appreciated...

Topic Closed

This topic has been closed to new replies.

About this Topic