在wordpress模板中的elseif

时间:2013-10-10 11:48:12

标签: wordpress if-statement

如果没有帖子,如何添加一些回显来呈现一个段落?

            <?php query_posts('cat=1'.get_the_title().'&post_status=publish,future');?>
            <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
                <div class="thumb"><?php the_post_thumbnail('thumbnail'); ?></div>                  
            <h1><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
            <p><?php $content = get_the_content();
            echo substr($content, 0, 20000); ?>...
            <span class="more"><a href="<?php the_permalink(); ?>">czytaj więcej...</a></span>
            </p>
            <?php endwhile; ?>
            <?php endif; ?>

2 个答案:

答案 0 :(得分:0)

您可以在else循环之后放置while

        <?php endwhile; ?>

    <?php else: ?>    

    <p> no posts found</p> 

<?php endif; ?>

答案 1 :(得分:0)

<?php query_posts('cat=1'.get_the_title().'&post_status=publish,future');?>

<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    <div class="thumb"><?php the_post_thumbnail('thumbnail'); ?></div>                  
    <h1><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
    <p><?php $content = get_the_content();
    echo substr($content, 0, 20000); ?>...
    <span class="more"><a href="<?php the_permalink(); ?>">czytaj więcej...</a></span>
    </p>
    <?php endwhile; ?>
<?php else : ?>
    <!-- Content to show when there are no posts. -->
<?php endif; ?>