0
我想通过使用与当前的帖子/页面相同的标记来查询相关的帖子,但是这也必须在我已经用于生成网格的代码格式内工作。通过标记的Wordpress查询相关的帖子
<?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的高手。
有没有办法让代码动态地找到附加到页面的标签并显示这些标签,所以如果我用测试标记该页面,它会找到测试。但如果我用'test2'标记另一个,它会发现test2?只是想知道这是我想要做的! – Amy