WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Must the_excerpt start with a line break? (16 posts)

  1. dominoeffect
    Member
    Posted 3 years ago #

    Hi all,

    I wanted to use this code on the front page of my blog:

    <strong><?php the_author(); ?></strong>: <?php the_excerpt(''); ?>

    ...in order to look something like this:

    Joe Bloggs: Lorem Ipsum etc [...]

    But anooyingly the_excerpt text always begins on a new line!

    Is anybody aware of a way this can be changed, a relatively safe hack perhaps?

    Thanks

  2. esmi
    Forum Moderator
    Posted 3 years ago #

    A link to a page demonstrating the problem might help...

  3. dominoeffect
    Member
    Posted 3 years ago #

    Hi emsi,

    It will happen on any website: if you put content before of after the_excerpt, the excerpt puts itself on a new line.

    E.g. the code:

    before<?php the_excerpt(''); ?>after

    will display the following:

    before
    the excerpt content yadda yadda...
    after

    Any help on how to remove this line break would be most appreciated.

    The website in question is being developed on a private server so I'm afraid I can't offer a link.

  4. esmi
    Forum Moderator
    Posted 3 years ago #

    It will happen on any website

    Yes - I'm aware of that. The_excerpt is wrapped in <p></p> tags by design. The obvious solution would be to look at reformatting the display using CSS but, without seeing the page, I can't tell if that's possible.

  5. dominoeffect
    Member
    Posted 3 years ago #

    The obvious solution would be to look at reformatting the display using CSS but, without seeing the page, I can't tell if that's possible.

    I've upped the theme here -- ignore the broken images and so on as this page is contentless, unlike the actual site. How do you think CSS might be used?

    Thank you.

  6. esmi
    Forum Moderator
    Posted 3 years ago #

    You've password protected the page. Does it contain the kind of content you want to display - ie excerpt & author?

  7. dominoeffect
    Member
    Posted 3 years ago #

    Oh sorry, please try again now. 'Latest posts' section is the relevant part. Yep excerpt and author are there.

  8. esmi
    Forum Moderator
    Posted 3 years ago #

    Try adding:

    .postsnippet h2 {
    display:inline-block
    float:left;
    }

    to the bottom of style.css.

  9. dominoeffect
    Member
    Posted 3 years ago #

    Thanks for the response, I've implemented it on the above link but unfortunately it hasn't had an effect.

    Any further ideas are most welcome :)

    (Sorry for the late response, I haven't been at my comp all weekend.)

  10. esmi
    Forum Moderator
    Posted 3 years ago #

    There's a semi-colon missing in the CSS I provided - sorry. Try:

    .postsnippet h2 {
    display:inline-block;
    float:left;
    }
  11. dominoeffect
    Member
    Posted 3 years ago #

    Afraid that still isn't working, thanks though.

  12. esmi
    Forum Moderator
    Posted 3 years ago #

    Sorry - wrong element. Try:

    .postsnippet strong {
    display:inline-block;
    float:left;
    }
  13. dominoeffect
    Member
    Posted 3 years ago #

    That still doesn't work; actually though the previous code did work by wrapping the author name to the title, but it was indeed the wrong element.

  14. esmi
    Forum Moderator
    Posted 3 years ago #

    To be honest, I think you need better markup. Surrounding the author name with generic <strong></strong> tags (especially with the colon being outside of these tags) isn't helping. Something like:

    <div class="the-author"><?php the_author(); ?>:</div> <div class="postcontent"><?php the_excerpt(''); ?></div>

    might be a lot easier to style.

  15. dominoeffect
    Member
    Posted 3 years ago #

    Thanks, I'll give that a shot and post the results.

  16. dominoeffect
    Member
    Posted 3 years ago #

    This turned out to be quite easy actually. If I were more experienced with css I might have got it sooner. I code I went with, (which worked perfectly), was this:

    <span style="display:inline-block;float:left;"><a href="<?php the_permalink() ?>"><?php the_author(); ?>:&nbsp;</span><?php the_excerpt(''); ?></a>

    Thanks again for your help.

Topic Closed

This topic has been closed to new replies.

About this Topic