【发布时间】:2011-09-09 21:38:58
【问题描述】:
我正在尝试使用与当前帖子/页面相同的标签来查询相关帖子,但这也必须在我已经用于生成网格的代码格式内工作。
<?php
$c = 1; //init counter
$bpr = 3; //boxes per row
if(have_posts()) : while (have_posts()) : the_post(); ?>
<div class="postgrid" id="post-<?php the_ID(); ?>">
<div class="postthumb">
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_post_thumbnail('grid-post-image'); ?></a><div class="borderthumb"></div><div class="posttitle"><h1><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h1>
<p><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">Click for more</a></p></div>
</div>
</div>
<?php
if($c == $bpr) :
?>
<?php
$c = 0;
endif;
?>
<?php
$c++;
endwhile;
endif;
?>
我发现了这个: Wordpress Querying Related Posts by tag
这看起来很有希望,但是当我尝试将它集成时......
<?php
$c = 1; //init counter
$bpr = 3; //boxes per row
$test = "";
$posttags = get_the_tags();
$test = '';
$sep = '';
if ($posttags) {
foreach($posttags as $tag) {
$test .= $sep . $tag->name;
$sep = ",";
}
}
query_posts('tag=' .$test . '&showposts=-1'); if(have_posts()) : while (have_posts()) : the_post(); ?>
不幸的是,它什么也没产生。有什么帮助吗?
谢谢!我认为这两个脚本有冲突,我不是 php 高手。
【问题讨论】: