如果声明和连接

时间:2015-02-03 12:11:12

标签: php wordpress

我试图对wordpress模板稍作调整。如果the_content()为空,我基本上只希望打印下面的代码。目前,如果它是空的,它仍会生成文章又名丑陋的白盒子。我一直在尝试将代码放入字符串中,只是对字符串执行if语句,但将所有这些代码连接成一个字符串并不适合我。有什么建议?更简单的方法来做我想做的事情,或者是最好的串联字符串?如果是这样,我可以得到帮助把这一切都变成一个字符串吗?谢谢!

<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
    <?php if ( '' != get_the_post_thumbnail() ) : ?>
        <div class="entry-thumbnail">
            <?php the_post_thumbnail( 'featured-image' ); ?>
        </div><!-- .entry-thumbnail -->
    <?php endif; ?>

    <header class="entry-header">
        <h1 class="entry-title"><?php the_title(); ?></h1>
    </header><!-- .entry-header -->

    <div class="entry-content">
        <?php the_content(); ?>
        <?php
            wp_link_pages( array(
                'before'   => '<div class="page-links">',
                'after'    => '</div>',
                'pagelink' => '<span class="page-link">%</span>',
            ) );
        ?>
    </div><!-- .entry-content -->
    <?php edit_post_link( __( 'Edit', 'singl' ), '<footer class="entry-meta"><span class="edit-link">', '</span></footer>' ); ?>
</article>

1 个答案:

答案 0 :(得分:1)

<?php
$content = get_the_content();
if($content != '') { 
    the_content(); 
} ?>

<?php if( $post->post_content != "" ) {
    //do something or show content
} 
相关问题