dongyuan1870 2013-08-26 05:32
浏览 25

相关帖子PHP影响facebook评论框

My related posts keeps changing my facebook comment box. The comment box will change based on the related posts shown. It should just be focusing on comments for the current page.

Here's my code below.

<?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>
  • 写回答

1条回答 默认 最新

  • drctyr2869 2013-08-26 09:29
    关注

    You use the_permalink function to call the comments box, but your related post query affected it, so you need to use wp_reset_query(). I've also add <li> in the list and remove the php shortcode <? instead <?php (For many servers, this not working).

    You should try this :

    <?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>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?