Created
November 15, 2012 09:31
-
-
Save onishiweb/4077638 to your computer and use it in GitHub Desktop.
A for loop putting 2 posts in an li - with WordPress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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