2011-02-09 55 views
0

我希望从三个不同的页面获得标题,摘录和一些元素,它们都具有相同的父项。如何在包含ul的页面中使用相同的父项包含不同的页面 - Wordpress

我不想指定这三个页面来显示,而是显示上次编辑/发布的三个页面。

我的目标是在三条水平线上显示内容。

正如我无法得到的代码工作:

<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> 

谢谢丹,这仍然没有工作,虽然。第一页的内容不显示(标题显示和元也)。尝试下面的代码,除了第二次显示内容之外,第一页的摘录显示了相同的结果。

<?php get_header(); the_post(); ?> 
<div id="main-content"> 
<?php 
$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(); ?>` 

回答

1

更改posts_per_page 3和使用orderby=date&order=DESC得到3最近。

如果您在已显示一些其他帖子/页面/帖子/页面的页面上显示此信息,请使用get_posts而不是query_posts

WordPress的抄本对所有的这些事情完整的文档和例子:

http://codex.wordpress.org/Function_Reference/query_posts

http://codex.wordpress.org/Function_Reference/get_posts

+0

你需要一个循环。看看链接页面的示例代码。不要只复制并粘贴您的代码3次。 – 2011-03-03 09:55:15