Forums

Styling the Excerpt (11 posts)

  1. Lorelle
    Member
    Posted 4 years ago #

    How do I add CSS to this for the excerpt to look different when displayed on the main pages and <b>not influence</b> the layout of the single post?

    <div class="storycontent">
    <?php
    if ($single) {
    the_content();
    }
    else {
    the_excerpt();
    }
    ?>

    Where does it go inside of this code?

  2. mdawaffe
    Member
    Posted 4 years ago #

    <div class="storycontent">
    <?php
    if ($single) {
    the_content();
    }
    else {
    ?>
    <span class="excerpt">
    <?php the_excerpt(); ?>
    </span>
    <?php
    }
    ?>

  3. Lorelle
    Member
    Posted 4 years ago #

    You are the brilliant one, obo wan knoweverything. Thank you!

    Now, how do I get this to stay clean of "comments", "date posted", and "filed under" when in excerpt style - on the category and main pages?

    The splitting up of the if/then statement is something I have to work on when it includes html in the if.

  4. TechGnome
    Moderator
    Posted 4 years ago #

    To see an interesting markup of the excerpt, take a look at my site:
    http://tannagh.com
    The excerpt is centered on the first post, then runs left, right, left, right, left, right, etc....

    Tg

    btw: this was done in 1.2.2 using a similar technique as mdawaffe's.

  5. Lorelle
    Member
    Posted 4 years ago #

    Very interesting. So it includes the excerpt and then the first part of the content of the post? Wow. That's very neat.

    I'm trying to reproduce what I have on my site in static html at Taking Your Camera on the Road. Scroll down past the announcements and you will see excerpt summaries that feature a picture and they float against each other so they will move with the screen width.

    After looking at this some more, I see that I need to have the photo, title, and excerpt all within the first part of the IF statement. Separating the coding from the if/then statement is something I have to read up on - unless someone can make this easier. Right now, the title, author, filed under, and comments are out of the if/then little loop which escapes the CSS for excerpt. I want them inside....I never want anything really easy.

    But I think when I'm done it will make for a great article examples of what can be done on the index.php!

  6. Lorelle
    Member
    Posted 4 years ago #

    Next day...I still can't figure out how to put the right coding inside of the excerpt style and tag and the other stuff outside of the tag and have it work. I'm getting tons of errors that don't make sense. Some of them are on blank lines, even. I'm missing something, but I can't figure it out.

    Anyone?

  7. mdawaffe
    Member
    Posted 4 years ago #

    Can you post the code somewhere (a pastebin or on a Codex User page?)?

  8. Lorelle
    Member
    Posted 4 years ago #

    Post what? The if/then statement that is the default for 1.5 but with the css excerpt tag added? I don't have anything to post. I'm just trying to remodel the current 1.5 index.php to keep the author and title INSIDE the excerpt (no comments, filed under, etc.) when there is an excerpt and all of it normal (with title, author, filed under, comments, etc) outside of the excerpt for the single post.

    Does that make sense? All I've been doing is moving stuff around the index.

    Thanks for the offer to help with this.

  9. mdawaffe
    Member
    Posted 4 years ago #

    I still don't know what exactly you want.

    My guess:

    If there is an explicitly defined excerpt, show it INSTEAD of the content on every page EXCEPT the single-post-page.

    If there is not an explicitly defined excerpt, do everything normally.

    When the_excerpt is shown, only show a few tags (author, title) instead of the whole nine yards, AND give that post some convenient CSS classes so that posts showing the_excerpt can be styled differently than posts showing the_content.

    Is this what you want?

  10. Lorelle
    Member
    Posted 4 years ago #

    Bingo!

    Understanding exactly where I can divide up the php lines is what is screwing me up. I've played around with some of the code in the if/else statements, putting the css and tags in between where the code can be "ended" and "continued on" (as you mention in the bottom of your codex page in The Loop), but I'm missing something in how I open and close the php to put the html or other php in between the if/else statements. I get page errors that don't seem to connect with the code.

    Breaking up the php if/else statement to allow for "other stuff" is a challenge for new php users. Where is "okay" and where will it break.

    Thanks for helping. You got it right.

  11. mdawaffe
    Member
    Posted 4 years ago #

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.