WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Need PHP help with loop (10 posts)

  1. trmash
    Member
    Posted 3 years ago #

    Hello,

    I'm having trouble with my loop, hoping you can lend a hand. As you'll notice, PHP is NOT my strong suit - so please feel free to refine this code as required.

    Basically, I want to display a featured post with an image in a div, then another div that contains three post excerpts and - below that - four post titles in an unordered list.

    The loop works okay (despite its ugliness), except that I can not figure out where to insert the UL to wrap around the LI tags.

    My current loop can be found at http://pastebin.com/DXVmeATV and my fingers are crossed! Thanks.

  2. Jeremy Pry
    Member
    Posted 3 years ago #

    You can just write an if statement within your elseif statement. Try this out:

    http://pastebin.com/ZMCSMTj2

    I've tweaked a bunch of stuff to make it closer to WordPress Coding Standards. I've also changed some of your function usage to make sure that it actually outputs what you expect (such as using new WP_Query(); instead of query_posts();).

  3. trmash
    Member
    Posted 3 years ago #

    Hi JPry,

    Thank you so much for your assistance - unfortunately there seems to be an issue with line 8:

    Parse error: syntax error, unexpected '<' in loop.php on line 8

    My PHP knowledge is already limited, so if you could advise what might be causing this issue I'd really appreciate it!

    Thanks again.

  4. Jeremy Pry
    Member
    Posted 3 years ago #

    Sorry about that, I missed a closing ?> tag. Should be corrected now.

  5. Jeremy Pry
    Member
    Posted 3 years ago #

    And I actually found one more error (a missing closing brace for the elseif). You may have to refresh and try one more time.

  6. trmash
    Member
    Posted 3 years ago #

    Thanks again. It's sort of working now, except for the part where I want titles only of the last four posts in an unordered list. Instead it's showing all posts (other than category 7) with excerpts.

    Just to clarify - excluding the featured article, there should be seven posts displayed: three with titles and excerpts and four in an unordered list with titles only.

    Appreciating your assistance, JPry. :)

  7. Jeremy Pry
    Member
    Posted 3 years ago #

    Tell me what results this one gives you: http://pastebin.com/fDJsft4X.

  8. Jeremy Pry
    Member
    Posted 3 years ago #

    Looks like I need to check things more thoroughly. I juste edited that new pastebin link. Refresh and try it one more time. I think I finally found where the problem was.

  9. trmash
    Member
    Posted 3 years ago #

    PERFECT! Thank you so much for all your help.

  10. Jeremy Pry
    Member
    Posted 3 years ago #

    No problem! Glad to help out!

Topic Closed

This topic has been closed to new replies.

About this Topic