Creating a WordPress Loop for Pages Instead of Posts
On my WordPress site, I'm using a plugin called "Vera Meta Boxes" that lets me add custom meta boxes to pages (not referring to custom开发者_开发技巧 post types).
So now every page has meta box that says, "Show on Home page" with a checkbox, that when selected has the value of "yes".
Now on my homepage, I want to show the titles and featured image of any page that has "Show on Homepage" checked.
The vera meta box plugin says to use:
<?php get_post_custom_values('your_custom_field_key_here'); ?>
So I would use:
<?php get_post_custom_values('show_on_homepage'); ?>
But how do I do the rest? Conceptually, it would be something like:
LOOP Query Pages > if <?php get_post_custom_values('show_on_homepage'); ?>
= yes show title and featured image and repeat loop until all pages with "show_on_homepage" are shown.
Well, I haven't tested this, but according to the docs you should be able to use this query:
array('post_type'=>'page', 'meta_query' => array( array('key' => 'show_on_homepage') ) )
Note that meta_query is an array of arrays
This is 3.1 code, the 3.0 version should look like this:
array('post_type'=>'page', 'meta_key' => 'show_on_homepage')
精彩评论