Support » Themes and Templates » Need PHP help with loop

  • Resolved trmash



    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 and my fingers are crossed! Thanks.

Viewing 9 replies - 1 through 9 (of 9 total)
  • You can just write an if statement within your elseif statement. Try this out:

    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();).

    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.

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

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

    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. 🙂

    Tell me what results this one gives you:

    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.

    PERFECT! Thank you so much for all your help.

    No problem! Glad to help out!

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Need PHP help with loop’ is closed to new replies.