If 语句和串联

If statement and concatenation

我正在尝试对 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>
<?php
$content = get_the_content();
if($content != '') { 
    the_content(); 
} ?>

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