A
A
Andrey2018-06-22 23:13:54
WordPress
Andrey, 2018-06-22 23:13:54

Add No Posts to Wordpress Ready Loop?

I'm trying to fix the post output code in one plugin:

<?php foreach($posts as $postdata){ ?>

    <?php foreach($postdata as $post){ setup_postdata($post); ?>

      
<div id="post-<?php the_ID(); ?>" <?php post_class('post'); ?>>

  Здесь отображение самого поста
        
</div><!-- /.post -->
      
    <?php } ?>

  <?php } ?>

Now, if there are no records, then nothing is displayed. Tell me what needs to be added so that when there are no records, a certain block is displayed, for example, There are no records yet.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Denis Yanchevsky, 2018-06-22
@dyba

I don't know what's in the variables, but probably something like this:

<?php if($posts) : ?>
<?php foreach($posts as $postdata){ ?>

    <?php foreach($postdata as $post){ setup_postdata($post); ?>

      
<div id="post-<?php the_ID(); ?>" <?php post_class('post'); ?>>

  Здесь отображение самого поста
        
</div><!-- /.post -->
      
    <?php } ?>

  <?php } ?>
<?php else : ?>
<div>Нет записей</div>
<?php endif; ?>

M
Max Medar, 2018-06-23
@MedVedar

Look at reference themes. For example, https://github.com/Automattic/_s

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question