• I’m trying to pull out the first image from a specific page to a specific div. The div is on top of the page (out of the loop).

    pls help ppl 🙂

    Thanks

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    You need to cue up the first post in the loop so you can extract the required information, then use rewind_posts() to reset the loop to the start to run the normal loop. A good example of this technique is on the author.php templates of the default themes. In this case the post is cued up to determine the author.

    After first checking if there are any posts at all with if (have_posts()), the_post() is called to cue up the first post. You can do anything you can do in a loop now, except there is no while of a true loop. Instead rewind_posts() is called to cancel the first post and enable the real loop to start.

Viewing 1 replies (of 1 total)

The topic ‘get the first image from a page (outside loop)’ is closed to new replies.