doudieyou5209 2011-07-19 09:48
浏览 56
已采纳

函数将html放在预期的span标签之外

Here you'll see I have two functions set up for "fb_comment_count" and "my_post_gallery": Pastebin.

Around line 123, you'll see that I am using "fb_comment_count". The trouble is that the generated markup does not place the comment count number within those span tags but rather somewhere else.

Below is the generated markup to show you what I mean. All of the comment counts (the a tags) are pushed to the top and the span tags (<span class="comment-number"></span>) are empty. Can anyone help me figure out why this happens?

<section class="tab_content" id="tab1" style="display: block;"> 
    <a title="Comments for Photos" href="http://mysite.com/test/photos/#comments">0</a>
    <a title="Comments for Photos" href="http://mysite.com/test/photos/#comments">0</a>
    <a title="Comments for Photos" href="http://mysite.com/test/photos/#comments">0</a>
    <a title="Comments for Photos" href="http://mysite.com/test/photos/#comments">0</a>
    <a title="Comments for Photos" href="http://mysite.com/test/photos/#comments">0</a>
    <a title="Comments for Photos" href="http://mysite.com/test/photos/#comments">0</a>
    <a title="Comments for Photos" href="http://mysite.com/test/photos/#comments">0</a>
    <a title="Comments for Photos" href="http://mysite.com/test/photos/#comments">0</a>
    <style type="text/css">
        #gallery-1 {
            margin: auto;
        }
        #gallery-1 .gallery-item {
            float: left;
            margin-top: 10px;
            text-align: center;
            width: 33%;           }
        #gallery-1 img {
            border: 2px solid #cfcfcf;
        }
        #gallery-1 .gallery-caption {
            margin-left: 0;
        }
    </style>
        <!-- see gallery_shortcode() in wp-includes/media.php -->
        <div class="gallery galleryid-818" id="gallery-1"><div class="gallery-item"><span class="photos-comment-number-wrap"><span class="comment-number"></span></span>
            <span class="gallery-icon">
                <a title="fff" href="http://mysite.com/test/photos/attachment/fff/"><img width="150" height="150" title="fff" alt="fff" class="attachment-thumbnail" src="http://mysite.com/test/wp-content/uploads/2011/06/fff-150x150.gif"></a>
            </span></div><div class="gallery-item"><span class="photos-comment-number-wrap"><span class="comment-number"></span></span>
            <span class="gallery-icon">
                <a title="plate with 5" href="http://mysite.com/test/photos/attachment/plate-with-5/"><img width="150" height="150" title="plate with 5" alt="plate with 5" class="attachment-thumbnail" src="http://mysite.com/test/wp-content/uploads/2011/06/plate-with-5-150x150.jpg"></a>
            </span></div><div class="gallery-item"><span class="photos-comment-number-wrap"><span class="comment-number"></span></span>
            <span class="gallery-icon">
                <a title="reference" href="http://mysite.com/test/photos/attachment/reference/"><img width="150" height="150" title="reference" alt="reference" class="attachment-thumbnail" src="http://mysite.com/test/wp-content/uploads/2011/06/reference-150x150.png"></a>
            </span></div><br style="clear: both"><div class="gallery-item"><span class="photos-comment-number-wrap"><span class="comment-number"></span></span>
            <span class="gallery-icon">
                <a title="test" href="http://mysite.com/test/photos/attachment/test/"><img width="150" height="150" title="test" alt="test" class="attachment-thumbnail" src="http://mysite.com/test/wp-content/uploads/2011/06/test-150x150.jpg"></a>
            </span></div><div class="gallery-item"><span class="photos-comment-number-wrap"><span class="comment-number"></span></span>
            <span class="gallery-icon">
                <a title="test-24" href="http://mysite.com/test/photos/attachment/test-24/"><img width="150" height="150" title="test-24" alt="test-24" class="attachment-thumbnail" src="http://mysite.com/test/wp-content/uploads/2011/06/test-24-150x150.gif"></a>
            </span></div><div class="gallery-item"><span class="photos-comment-number-wrap"><span class="comment-number"></span></span>
            <span class="gallery-icon">
                <a title="test-pilot" href="http://mysite.com/test/photos/attachment/test-pilot/"><img width="150" height="150" title="test-pilot" alt="test-pilot" class="attachment-thumbnail" src="http://mysite.com/test/wp-content/uploads/2011/06/test-pilot-150x150.png"></a>
            </span></div><br style="clear: both"><div class="gallery-item"><span class="photos-comment-number-wrap"><span class="comment-number"></span></span>
            <span class="gallery-icon">
                <a title="its-hackin-christmas" href="http://mysite.com/test/photos/attachment/blah"><img width="133" height="133" title="its-hackin-christmas" alt="its-hackin-christmas" class="attachment-thumbnail" src="http://mysite.com/test/wp-content/uploads/2011/06/blah.jpg"></a>
            </span></div><div class="gallery-item"><span class="photos-comment-number-wrap"><span class="comment-number"></span></span>
            <span class="gallery-icon">
                <a title="who-wants-to-party" href="http://mysite.com/test/photos/attachment/who-wants-to-party/"><img width="133" height="133" title="who-wants-to-party" alt="who-wants-to-party" class="attachment-thumbnail" src="http://mysite.com/test/wp-content/uploads/2011/06/who-wants-to-party.jpg"></a>
            </span></div>
            <br style="clear: both;">
        </div>
</section>
  • 写回答

1条回答 默认 最新

  • douyan2470 2011-07-19 10:01
    关注

    In your PHP function use return instead of echo. so, for example, instead of having this on line 26:

    echo $comments;
    

    change it to:

    return $comments;
    

    Same thing goes for other lines with echo.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?