Title: Need PHP help with loop
Last modified: August 20, 2016

---

# Need PHP help with loop

 *  Resolved [ts](https://wordpress.org/support/users/trmash/)
 * (@trmash)
 * [15 years ago](https://wordpress.org/support/topic/need-php-help-with-loop/)
 * 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](http://pastebin.com/DXVmeATV)
   and my fingers are crossed! Thanks.

Viewing 9 replies - 1 through 9 (of 9 total)

 *  [Jeremy Pry](https://wordpress.org/support/users/jpry/)
 * (@jpry)
 * [15 years ago](https://wordpress.org/support/topic/need-php-help-with-loop/#post-2097146)
 * You can just write an if statement within your elseif statement. Try this out:
 * [http://pastebin.com/ZMCSMTj2](http://pastebin.com/ZMCSMTj2)
 * I’ve tweaked a bunch of stuff to make it closer to [WordPress Coding Standards](http://codex.wordpress.org/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();`).
 *  Thread Starter [ts](https://wordpress.org/support/users/trmash/)
 * (@trmash)
 * [15 years ago](https://wordpress.org/support/topic/need-php-help-with-loop/#post-2097147)
 * 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.
 *  [Jeremy Pry](https://wordpress.org/support/users/jpry/)
 * (@jpry)
 * [15 years ago](https://wordpress.org/support/topic/need-php-help-with-loop/#post-2097152)
 * Sorry about that, I missed a closing `?>` tag. Should be corrected now.
 *  [Jeremy Pry](https://wordpress.org/support/users/jpry/)
 * (@jpry)
 * [15 years ago](https://wordpress.org/support/topic/need-php-help-with-loop/#post-2097154)
 * And I actually found one more error (a missing closing brace for the elseif).
   You may have to refresh and try one more time.
 *  Thread Starter [ts](https://wordpress.org/support/users/trmash/)
 * (@trmash)
 * [15 years ago](https://wordpress.org/support/topic/need-php-help-with-loop/#post-2097158)
 * 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. 🙂
 *  [Jeremy Pry](https://wordpress.org/support/users/jpry/)
 * (@jpry)
 * [15 years ago](https://wordpress.org/support/topic/need-php-help-with-loop/#post-2097160)
 * Tell me what results this one gives you: [http://pastebin.com/fDJsft4X](http://pastebin.com/fDJsft4X).
 *  [Jeremy Pry](https://wordpress.org/support/users/jpry/)
 * (@jpry)
 * [15 years ago](https://wordpress.org/support/topic/need-php-help-with-loop/#post-2097163)
 * 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.
 *  Thread Starter [ts](https://wordpress.org/support/users/trmash/)
 * (@trmash)
 * [15 years ago](https://wordpress.org/support/topic/need-php-help-with-loop/#post-2097164)
 * PERFECT! Thank you so much for all your help.
 *  [Jeremy Pry](https://wordpress.org/support/users/jpry/)
 * (@jpry)
 * [15 years ago](https://wordpress.org/support/topic/need-php-help-with-loop/#post-2097165)
 * 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.

## Tags

 * [excerpt](https://wordpress.org/support/topic-tag/excerpt/)
 * [loop](https://wordpress.org/support/topic-tag/loop/)
 * [php](https://wordpress.org/support/topic-tag/php/)
 * [unordered list](https://wordpress.org/support/topic-tag/unordered-list/)

 * 9 replies
 * 2 participants
 * Last reply from: [Jeremy Pry](https://wordpress.org/support/users/jpry/)
 * Last activity: [15 years ago](https://wordpress.org/support/topic/need-php-help-with-loop/#post-2097165)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
