2017-05-10 2 views
0

Ich versuche, ein Bild als eine bedingte verwenden, um verschiedene Beitragstypen anzuzeigen. Ich habe einen Beitrag mit Bildern und einen anderen ohne Bilder. Also habe ich eine If else-Anweisung und eine while-Schleife erstellt, die den Post aufruft. Am Ende habe ich einen Seitenzahlencode. Aber die Schleife ist unendlich, ich finde nicht, wo ich sie schließe. Jemand kann mir helfen?Verwenden Sie Bild als Wordpress Conditional

<?php if (have_posts()): while (have_posts()) : the_post(); ?> 
    <div class="texto-longo"> 
     <?php the_content(); ?> 
    </div> 
    <?php endwhile; wp_reset_query(); endif; ?> 


    <div class="row-2 w-row"> 
    <?php 
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; 
    $args = array(
     'posts_per_page' => 3, 
     'paged'   => $paged, 
     'cat'   => '3', 
    ); 

    $wp_query = new WP_Query($args); 
    ?> 
    <?php if ($wp_query->have_posts()) : ?> 
     <?php while ($wp_query->have_posts()) : $wp_query->the_post(); ?> 

     <div class="_w-image container-novidades"> 
      <?php if(get_field('imagem_do_evento')): ?> 
     <div class="w-row"> 
     <div class="column w-col w-col-4"><img class="<?php the_field('imagem_do_evento');?>"> 
     </div> 
     <div class="colomn-text-novidades w-col w-col-8"> 
      <h1 class="txt-blue"><?php the_title();?></h1> 
      <h3 class="txt-blue"><?php the_field('imagem_do_evento');?></h3> 
      <p><?php get_the_date('d/m/Y'); ?></p> 
      <p><?php the_field('imagem_do_evento');?></p> 
     </div> 
     </div> 

    </div> 

    <?php wp_reset_query(); else : ?> 

    <p>Ainda não temos novidades :(</p> 

    <?php endif; ?> 
<?php endwhile; ?> 

     <?php if ($wp_query->max_num_pages > 1) { // check if the max number of pages is greater than 1 ?> 
     <nav class="navegacao-paginas"> 
     <div class="paginacao twisted w-inline-block"> 
      <div class="seta-text"><?php echo get_previous_posts_link('&#10230;'); // display newer posts link ?></div> 
      </div> 
      <div class="paginacao w-inline-block"> 
      <div class="seta-text"><?php echo get_next_posts_link('&#10230;', $wp_query->max_num_pages); // display older posts link ?></div> 
      </div> 
     </nav> 
     <?php } ?> 

    </div> 
    <?php wp_reset_query(); else : ?> 
    <?php endif; ?> 

Antwort

0

Versuchen Sie, die endwhile und edn, wenn in der gleichen Zeile zu setzen wie diese <?php endwhile; wp_reset_query(); endif; ?>

0

I figured it out. Es war eine Div-Eröffnung außerhalb der if-Anweisung. Und ich schloss nicht alles, wenn es nicht richtig war. Überprüfen Sie den endgültigen Code.

<?php if (have_posts()): while (have_posts()) : the_post(); ?> 
    <div class="texto-longo"> 
     <?php the_content(); ?> 
    </div> 
<?php endwhile; wp_reset_query(); endif; ?> 


<div class="row-2 w-row"> 
    <?php 
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; 
    $args = array(
     'posts_per_page' => 3, 
     'paged'   => $paged, 
     'cat'   => '4', 
     ); 

    $wp_query = new WP_Query($args); 
    ?> 
    <?php if ($wp_query->have_posts()) : ?> 
     <?php while ($wp_query->have_posts()) : $wp_query->the_post(); ?> 


       <?php if(get_field('foto_novidades')): ?> 
        <div class="_w-image container-novidades"> 
        <div class="w-row"> 
         <div class="column w-col w-col-4"><img class="img-novidades" src="<?php the_field('foto_novidades');?>"> 
         </div> 
         <div class="colomn-text-novidades w-col w-col-8"> 
          <h1 class="txt-blue"><?php the_title();?></h1> 
          <h3 class="txt-blue"><?php the_field('sub_titulo_novidades');?></h3> 
          <p><?php get_the_date('d/m/Y'); ?></p> 
          <p><?php the_field('texto_novidades');?></p> 
         </div> 
        </div> 
        </div> 
      <?php else:?> 

       <div class="container-novidades"> 
        <h1 class="txt-blue"><?php the_title();?></h1> 
        <h3 class="txt-blue"><?php the_field('sub_titulo_novidades');?></h3> 
        <p><?php get_the_date('d/m/Y'); ?></p> 
        <p><?php the_field('texto_novidades');?></p> 
       </div> 
      <?php endif; ?> 
     <?php endwhile; ?> 

     <?php if ($wp_query->max_num_pages > 1) { // check if the max number of pages is greater than 1 ?> 
     <nav class="navegacao-paginas"> 
      <div class="paginacao twisted w-inline-block"> 
       <div class="seta-text"><?php echo get_previous_posts_link('&#10230;'); // display newer posts link ?></div> 
      </div> 
      <div class="paginacao w-inline-block"> 
       <div class="seta-text"><?php echo get_next_posts_link('&#10230;', $wp_query->max_num_pages); // display older posts link ?></div> 
      </div> 
     </nav> 
     <?php } ?> 

    </div> 


    <?php wp_reset_query(); else : ?> 

    <p>Ainda não temos novidades :(</p> 

<?php endif; ?> 
Verwandte Themen