duanlu4371 2014-05-25 07:55
浏览 49
已采纳

语法错误,Single.php文件上的意外文件结束

My single.php file has no error before I add this code :

<?php $orig_post = $post;
                global $post;
                $tags = wp_get_post_tags($post->ID);
                if ($tags) {
                $tag_ids = array();
                foreach($tags as $individual_tag) $tag_ids[] = $individual_tag->term_id;
                $args=array(
                'tag__in' => $tag_ids,
                'post__not_in' => array($post->ID),
                'posts_per_page'=>10, // Number of related posts that will be displayed.
                'caller_get_posts'=>1,
                'orderby'=>'rand' 
                );
                $my_query = new wp_query( $args );
                if( $my_query->have_posts() ) {
                echo '<div id="related_posts" class="clear"><h3>Related Posts</h3><ul>';
                while( $my_query->have_posts() ) {
                $my_query->the_post(); ?>
                <li>
                     <a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>">
                     <?php the_post_thumbnail( 'related-posts' ); ?>
                     </a>
                     <div class="related_content">
                     <a href="<?php the_permalink()?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a>
                     </div>
                </li>
                <?php
                };
echo '</ul></div>'; ?>

,piece of code to get Related posts based on Category inside single file which I found here : http://www.webadvice.osvojito.com/wordpress-related-posts-without-plugin-with-thumbnails/

when I add this, I get this error : "syntax error, unexpected end of file"

I checked my code syntax several times, nothing's missing !!

  • 写回答

1条回答 默认 最新

  • duanluo9369 2014-05-25 08:01
    关注

    You are missing 2 } on your code.

    The last few lines of your code should be:

                    <?php
                    }
                    }
                    }
    echo '</ul></div>';
    
    ?>
    

    instead of:

                    <?php
                    };
    echo '</ul></div>'; ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用