如何在同一个父母的WordPress的不同页面中包含摘录

时间:2011-02-09 07:40:06

标签: php 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>

谢谢Dan,但这仍然无效。第一页的excrept没有显示(标题显示和meta也)。尝试使用相同的结果下面的代码,除了第二次显示内容,第一页的摘录显示。

<?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 个答案:

答案 0 :(得分:1)

posts_per_page更改为3并使用orderby=date&order=DESC获取最近的3个。

如果您在已显示其他帖子/页面/帖子/页面的页面上显示此内容,请使用get_posts代替query_posts

WordPress codex包含所有这些内容的完整文档和示例:

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

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