I wish to get the title, the excerpt and some meta from three different pages that all have the same parent.
I do not wish to specify wich three pages to show but rather show the three that was last edited/published.
I aim to display the content as three blocks on a horizontal line.
As I was unable to get the code to work:
<ul id="">
<?php query_posts("posts_per_page=1&post_type=page&post_parent=4"); the_post(); ?>
<li>
<img src="<?php echo get_post_meta($post->ID, "image", true); ?>" alt="<?php the_title(); ?>" />
<h2><?php the_title(); ?></h2>
<?php the_excerpt(); ?>
</li>
</ul>
Thank you Dan, this still does not work though. The excrept of the first page does not show (the title shows and the meta also). Tried the code below with the same result except that the second time the content is displayed, the excerpt of the first page shows.
<?php get_header(); the_post(); ?>
<div id="main-content">
<?php开发者_StackOverflow中文版
$categoriesCF = get_post_meta($post->ID, "categories", true);
$allCategories = explode(",", $categoriesCF);
foreach ($allCategories as $category) {
$pieces = explode("|", $category);
$link = get_permalink($pieces[1]);
echo "<div class='product-group group'>";
echo "<h3><a href='$link'>" . $pieces[0] . "</a></h3>";
query_posts("posts_per_page=-1&post_type=page&post_parent=$pieces[1]");
while (have_posts()) : the_post(); ?>
<a href="<?php the_permalink(); ?>" class="product-jump" title="<?php the_title(); ?>" data-large="<?php get_post_meta($post->ID, "image", true); ?>">
<?php echo "<img src='" . get_post_meta($post->ID, "image", true) . "' />"; ?>
<span class="product-title"><?php the_title(); ?></span>
<span class="product-title"><?php the_excerpt(); ?></span></a>
<?php endwhile; wp_reset_query();
echo "</div>";
};
?>
</div>
<?php get_sidebar(); ?>
<?php get_footer(); ?>`
Change posts_per_page
to 3 and use orderby=date&order=DESC
to get the 3 most recent.
If you are displaying this on a page that already shows some other post/page/posts/pages, use get_posts
instead of query_posts
.
The WordPress codex has full documentation and examples for all of these things:
http://codex.wordpress.org/Function_Reference/query_posts
http://codex.wordpress.org/Function_Reference/get_posts
精彩评论