我想要显示与页面类似的帖子。这是我的代码(只是重要的PHP部分,而不是HTML)?有什么问题?
<?php $pages = get_pages(array('child_of' => 13)); ?>
<?php foreach ($pages as $page): ?>
<?php echo $page->post_title; ?>
<?php echo $page->post_excerpt; ?>
<?php echo $page->post_content; ?>
<?php $categories = get_the_category($page->ID);?>
<?php query_posts('post_type=projekt&category_name=$categories&showposts=1');?>
<?php while (have_posts()) : the_post(); ?>
<?php the_title(); ?></a>
<?php endforeach; ?>
感谢名单!
答案 0 :(得分:2)
试
<?php $pages = get_pages(array('child_of' => 13));
foreach ($pages as $page) {
echo $page->post_title;
echo $page->post_excerpt;
echo $page->post_content;
$categories = get_the_category($page->ID);
query_posts('post_type=projekt&category_name='.$categories.'&showposts=1');
while (have_posts()) : the_post(); ?>
<a><?php the_title(); ?></a>
<?php endwhile;
endforeach; ?>
答案 1 :(得分:0)
未经测试,此行看起来不正确:
<?php query_posts('post_type=projekt&category_name=$categories&showposts=1');?>
由于单引号
,$categories
变量按字面解释
<?php query_posts('post_type=projekt&category_name=' . $categories . '&showposts=1');?>