Skip to content

Instantly share code, notes, and snippets.

@onishiweb
Created November 15, 2012 09:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save onishiweb/4077638 to your computer and use it in GitHub Desktop.
Save onishiweb/4077638 to your computer and use it in GitHub Desktop.
A for loop putting 2 posts in an li - with WordPress
<?php
// Define the arguements as you would for a WP_Query
$args = "whatever";
// Run get_posts instead of WP_Query, does a similar thing but now $slide_posts
// will contain the query results in an array...
$slide_posts = get_posts($args);
// FOR LOOP!
// 3 arguments (counter), (the test to see how many loops to run - for as long as i < the count of the array) (increment counter)
for ( i=0; i<count($slide_posts); i++ ): ?>
<li>
<?php
// return the first post - look up the $post object and see how it returns
// access things like title with $slide_posts[i]->post_title;
echo $slide_posts[i];
// increment the counter (i)
i++;
// return the second post - look up the $post object and see how it returns
echo $slide_posts[i];
?>
</li>
<?php endfor; ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment