我的相关帖子不断更改我的Facebook评论框。评论框将根据显示的相关帖子进行更改。它应该只关注当前页面的评论。
以下是我的代码。
<?php
$categories = get_the_category($post->ID);
if ($categories) {
$category_ids = array();
foreach($categories as $individual_category) $category_ids[] = $individual_category->term_id;
$args=array(
'category__in' => $category_ids,
'post__not_in' => $showed_posts,
'showposts'=>3, // Number of related posts that will be shown.
'caller_get_posts' => 1,
'exclude' => '$postID',
'orderby' => 'rand'
);
$my_query = new wp_query($args);
if( $my_query->have_posts() ) {
echo '<ul>';
while ($my_query->have_posts()) {
$my_query->the_post();
?>
<div class="relatedpost">
<a rel="external" href="<? the_permalink()?>"><?php the_post_thumbnail(array(175,98)); ?>
<br />
<center><h6><?php the_title(); ?></h6></center>
</a>
</div>
<?php
}
echo '</ul>';
}
}
?>
<center>
<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script>
<fb:comments href="<?php the_permalink(); ?>" width="640"></fb:comments>
</center>
答案 0 :(得分:0)
您使用the_permalink函数调用评论框,但您的相关帖子查询会影响评论框,因此您需要使用wp_reset_query()
。
我还在列表中添加<li>
并删除php短代码<?
而不是<?php
(对于许多服务器,这不起作用)。
你应该试试这个:
<?php
$categories = get_the_category($post->ID);
if ($categories) {
$category_ids = array();
foreach($categories as $individual_category) $category_ids[] = $individual_category->term_id;
$args=array(
'category__in' => $category_ids,
'post__not_in' => $showed_posts,
'showposts'=>3, // Number of related posts that will be shown.
'caller_get_posts' => 1,
'exclude' => '$postID',
'orderby' => 'rand'
);
$my_query = new wp_query($args);
if( $my_query->have_posts() ) {
echo '<ul>';
while ($my_query->have_posts()) {
$my_query->the_post();
?>
<li>
<div class="relatedpost">
<a rel="external" href="<?php the_permalink()?>"><?php the_post_thumbnail(array(175,98)); ?></a>
<br />
<a rel="external" href="<?php the_permalink()?>"><center><h6><?php the_title(); ?></h6></center></a>
</div>
</li>
<?php
}
echo '</ul>';
}
}
?>
<?php wp_reset_query(); ?>
<center>
<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script>
<fb:comments href="<?php the_permalink(); ?>" width="640"></fb:comments>
</center>