D
D
Denis Vdovin2016-12-05 11:43:41
PHP
Denis Vdovin, 2016-12-05 11:43:41

How to make Wordpress skip the loop when there is no content and load further?

Good day!
There is a code on the WP site that displays a specific taxonomy. This is a poster, and when the event expires, the entry is automatically hidden.

<!--    События-->

    <?php
    if (have_posts()) :

      $args = array(
          'post_type' => 'event',
          'posts_per_page' => 8,
          'meta_query' => array(
              'relation' => 'AND',
              array(
                  'key' => 'event_date',
                  'value' => current_time('Y-m-d'),
                  'compare' => '>='
              ),
              array(
                  'key' => 'event_type',
                  'value' => 'event'
              )
          ),
          'orderby' => 'meta_value',
          'order' => 'ASC'
      );

      query_posts($args);
      ?>
      <?php
      while (have_posts()) : the_post();
        $custom = get_post_custom($post->ID);
        ?>

        <div class="af-block" style="background-image: url('<?php echo get_the_post_thumbnail_url() ?>');">
          <a href="<?php echo $custom["event_link"][0]; ?>" target="_blank">
            <div class="mask"></div>
            <div class="tag_block">
              <div class="date_block">
                <?php
                $meta = get_post_meta($post->ID, 'event_date', true );
                esc_html_e( mysql2date( 'j F' , $meta ) );
                ?>
              </div>
              <div class="place_block">
                <?php if (isset($custom["event_space"][0])) { ?><?php echo $custom["event_space"][0]; ?><?php } ?>
              </div>
            </div>
            <h2><?php the_title()?></h2>
          </a>
        </div>
      <?php endwhile; ?>
      <?php
    endif;
    ?>

    <!--    Фестивали-->
    <?php
    if (have_posts()) :

      $args = array(
          'post_type' => 'event',
          'posts_per_page' => 8,
          'meta_query' => array(
              'relation' => 'AND',
              array(
                  'key' => 'fest_end',
                  'value' => current_time('Y-m-d'),
                  'compare' => '>='
              ),
              array(
                  'key' => 'event_type',
                  'value' => 'fest'
              )
          ),
          'orderby' => 'meta_value',
          'order' => 'ASC'
      );

      query_posts($args);
      ?>
      <?php
      while (have_posts()) : the_post();
        $custom = get_post_custom($post->ID);
        ?>

        <div class="af-block" style="background-image: url('<?php echo get_the_post_thumbnail_url() ?>');">
          <a href="<?php echo $custom["event_link"][0]; ?>" target="_blank">
            <div class="mask"></div>
            <div class="tag_block">
              <div class="date_block">
                C
                <?php
                $meta = get_post_meta($post->ID, 'event_date', true );
                esc_html_e( mysql2date( 'd.n' , $meta ) );
                ?>
                по
                <?php
                $meta = get_post_meta($post->ID, 'fest_end', true );
                esc_html_e( mysql2date( 'd.n' , $meta ) );
                ?>
              </div>
              <div class="place_block">
                <?php if (isset($custom["event_space"][0])) { ?><?php echo $custom["event_space"][0]; ?><?php } ?>
              </div>
            </div>
            <h2><?php the_title()?></h2>
          </a>
        </div>
      <?php endwhile; ?>
      <?php
    endif;
    ?>
  </div>
  </div>
  <div class="row">
    <?php
    if (have_posts()) :
      $array_type = array('post_type' => 'discourse', 'posts_per_page' => 1, 'offset' => 1);
      query_posts($array_type);
      ?>

      <?php
      while (have_posts()) : the_post();
        if ( has_post_thumbnail()) {
          $thumb = wp_get_attachment_image_src( get_post_thumbnail_id(), 'large');
        } else {
          $thumb[0] = get_bloginfo('template_url')."/img/no_thumb.jpg";
        }
        $custom_views= get_post_custom($post->ID);
        ?>

        <div class="item2 col-xs-12 col-md-12">
          <a href="<?php the_permalink(); ?>" class="post_link">
            <div class="txt"> <h2><?php the_title();?> </h2></div>
            <img src="<?php echo $thumb[0]; ?>" alt="">
          </a>
        </div>

      <?php endwhile; ?>
    <?php endif; ?>
  </div>
  <div class="row">
    <?php
    if (have_posts()) :
      query_posts('cat=1,139,140&posts_per_page=8&offset=9');
      ?>

      <?php
      while (have_posts()) : the_post();
        if ( has_post_thumbnail()) {
          $thumb = wp_get_attachment_image_src( get_post_thumbnail_id(), 'medium');
        } else {
          $thumb[0] = get_bloginfo('template_url')."/img/no_thumb.jpg";
        }
        $custom_place = get_post_custom($post->ID);
        ?>

        <div class="item col-lg-3 col-md-4 col-sm-6">
          <div class="item-img">
            <a href="<?php the_permalink(); ?>">
              <img src="<?php echo $thumb[0]; ?>" alt="">
            </a>
          </div>
          <div class="tag_block_2">
            <div class="category_block_news"><?php echo the_category(' '); ?></div>
            <div class="date_block_news">
              <?php
              if ( in_category( array (1,139) )) {
                if (isset($custom_place["news_place"][0])) {  echo $custom_place["news_place"][0]; }
              }
              elseif ( in_category(140)) {
                if (isset($custom_place["local_citylife"][0])) {  echo $custom_place["local_citylife"][0];  }
              }
              ?>
            </div>
          </div>
          <div class="item-txt">
            <div class="title_txt">
              <a href="<?php the_permalink(); ?>">
                <h2><?php the_title()?></h2>
                <p><?php kama_excerpt(); ?></p>
              </a>
            </div>
          </div>
        </div>
      <?php endwhile; ?>
    <?php endif; ?>
  </div>

Periodically, editors do not work fast enough and there are simply no actual records left. Then WP does not load the next blocks - cycles that display different material. How to make sure that in the absence of content, WP shamelessly loads articles further?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
U
unet900, 2016-12-05
@unet900

The question is not entirely clear. Here you have resulted the code posts of category events are deduced. How do you display other blocks? I suspect that they are in the same cycle and are not displayed. This is the template code you have, please provide the code in full and explain which blocks should be displayed.
But in general, you have these blocks somewhere inside the WP post output cycle, so they are not displayed when there are no posts.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question