如何php if else语句并返回不同的div?

tok*_*owp 0 php if-statement

我正在尝试创建一个 if-else 语句,它将返回不同的 div。我认为它失败了,因为'else 语句中的内容太多。

<?php $blogentryid = get_the_ID(); 

if ($blogentryid=="1572") {
echo '<div>Hello</div>'
}

else {
echo '<div class="socialnews2"><!-- start div social-->

                                <div class="twitternews2">
                                <a href="http://twitter.com/share" class="twitter-share-button" data-count="horizontal" data-text="<?php the_title(); ?>" d
ata-url="<?php the_permalink() ?>" data-via="giantmangocom">Tweet</a>
                                <script type="text/javascript">
                                //async script, twitter button fashiolista.com style
                                (function() {
                                var s = document.createElement('SCRIPT');
                                var c = document.getElementsByTagName('script')[0];
                                s.type = 'text/javascript';
                                s.async = true;
                                s.src = 'http://platform.twitter.com/widgets.js';
                                c.parentNode.insertBefore(s, c);
                                 })();
                                </script>
                                </div>
                        </div>
                                <div class="facebooknews2">
<iframe src="http://www.facebook.com/plugins/like.php?href=<?php echo urlencode(get_permalink($post->ID)); ?>&amp;layout=button_count&
amp;show_faces=false&amp;width=80&amp;action=like&amp;colorscheme=light;height=21"" scrolling="no" frameborder="0" style="border:none; overflow:hidden; wid
th:80px; height:21px;" allowTransparency="true"></iframe>
                                </div>'

}

?>
Run Code Online (Sandbox Code Playgroud)

mel*_*okb 5

当您想要显示条件内容时,请打开和关闭<?php标签而不是使用 echo 语句。

<?php if ($blogentryid == "1572") { ?>

<div>Hello</div>

<?php } else { ?>

<div class="socialnews2"><!-- start div social-->
... rest of content here

<? } ?>
Run Code Online (Sandbox Code Playgroud)

它还将确保您在 div 中的 php 代码按照您的意图进行评估。