2017-05-10 1 views
0

이미지를 조건으로 사용하여 다른 유형의 게시물을 표시하려고합니다. 나는 이미지가있는 하나의 포스트와 이미지가없는 포스트를 가지고있다. 그래서 나는 If else 문과 while 루프를 작성하여 게시물을 호출합니다. 마지막에는 페이지 번호 코드가 있습니다. 그러나 루프는 무한합니다. 닫을 위치를 찾지 못했습니다. 어떤 사람이 나를 도울 수 있습니까?이미지를 Wordpress 조건부로 사용하십시오.

<?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; ?> 

답변

0

봅니다 만약 내가 그것을 알아 냈이 <?php endwhile; wp_reset_query(); endif; ?>

0

같은 동일한 행에 ENDWHILE 및 EDN을 넣어. if 문 밖에서 div가 열렸습니다. 그리고 내가 제대로 닫히지 않았다. 최종 코드를 확인하십시오.

<?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; ?> 
관련 문제