Поддержка Проблемы и решения Каким образом реализовать такой вывод записей?

  • Здравствуйте! Помогите решить проблему. Мне нужно реализовать вывод как на картинке:
    http://s017.radikal.ru/i413/1111/24/4e0219aecefc.jpg
    Мне пока что пришла в голову мыль сделать это с помощью двух запросов:

    <div class="cat-block">
        <h3>Новости</h3>
        <ul>
        <?php
     //выводим последний пост
    		$the_query = new WP_Query('showposts=1&orderby=post_date&order=desc&cat=1');
    			while ($the_query->have_posts()) : $the_query->the_post(); ?>
             <div class="latest">
    					<li>
    					<a href="<?php the_permalink(); ?>"><?php the_post_thumbnail(array(250,250), array ('class' => 'alignleft', 'alt' => '', 'title'=>'')); ?></a>
    					<div class="clear"></div>
    					</li>
    			</div>
    					<?php endwhile;?>
         </ul>
         <div class="few_post">
         <ul>
        <?php
    //выводим еще три поста из этой же категории
    		$the_query = new WP_Query('showposts=3&orderby=post_date&order=desc&cat=1');
    			while ($the_query->have_posts()) : $the_query->the_post(); ?>
    
    					<li>
    					<a href="<?php the_permalink(); ?>"><?php the_post_thumbnail(array(75,75), array ('class' => 'alignleft', 'alt' => '', 'title'=>'')); ?></a>
    					<h4><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h4>
    <div class="sidebar-date"><span class="sidebar-day"><?php the_time('d'); ?></span> <?php the_time('F Y'); ?></div>
    					<div class="clear"></div>
    					</li>
    					<?php endwhile;?>
         </ul>
         </div>
         <div class="clear"></div>
        </div>

    Как исключить во втором запросе последнюю запись? Чтобы не показывалась одна и та же картинка? Может кто сталкивался с решением. Мне кажется что есть решение проще. Такое оформление применяется в журнальных темах, увидел здесь, хочу так же реализовать
    http://themeforest.net/theme_previews/154462-london-live-3-in-1-news-magazine-and-blog?index=1

Просмотр 3 ответов — с 1 по 3 (всего 3)
  • Модератор Yuri

    (@yube)

    Мне пока что пришла в голову мыль сделать это с помощью двух запросов:

    Не очень хорошая мысль. Хватит и одного. Логика такая:

    query_posts(параметры);
    the_post();
    /*вывод первого из выборки*/
    while (have_posts()) {
     the_post();
     /*вывод от второго до n-го постов*/
    }

    Нашел в codex вот что

    <?php $my_query = new WP_Query('category_name=featured&posts_per_page=1');
      while ($my_query->have_posts()) : $my_query->the_post();
      $do_not_duplicate = $post->ID;?>
        <!-- Do stuff... -->
      <?php endwhile; ?>
        <!-- Do other stuff... -->
      <?php if (have_posts()) : while (have_posts()) : the_post();
      if( $post->ID == $do_not_duplicate ) continue; ?>
       <!-- Do stuff... -->
      <?php endwhile; endif; ?>

    Написано, что как раз такой реализации, и переменная есть чтобы дублирования не было

    Попробовал перевести на свой вариант:

    <div class="cat-block">
       <h3>Тест</h3>
          <?php
             $the_query = new WP_Query('cat=1&posts_per_page=1');
             while ($the_query->have_posts()) : $the_query->the_post();
             $do_not_duplicate = $post->ID;?>
                <div class="latest">
                   <a href="<?php the_permalink(); ?>"><?php the_post_thumbnail(array(250,250), array ('class' => 'alignleft', 'alt' => '', 'title'=>'')); ?></a>
                </div>
             <?php endwhile; ?>
                <?php $the_query = new WP_Query('cat=1&posts_per_page=3');
                while ($the_query->have_posts()) : $the_query->the_post();
                if( $post->ID == $do_not_duplicate ) continue; ?>
                   <div class="few_post">
                      <ul>
                         <li>
                            <a href="<?php the_permalink(); ?>"><?php the_post_thumbnail(array(75,75), array ('class' => 'alignleft', 'alt' => '', 'title'=>'')); ?></a>
    					<h4><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h4>
    <div class="sidebar-date"><span class="sidebar-day"><?php the_time('d'); ?></span> <?php the_time('F Y'); ?></div>
    					<div class="clear"></div>
                         </li>
                      </ul>
                   </div>
                <?php endwhile; endif; ?>
          <div class="clear"></div>
    </div>

    ругается на строку <?php endwhile; endif; ?>. пишет Parse error: syntax error, unexpected T_ENDIF in Z:\home\…. Что не так, подскажите?

    дел, не прав.

Просмотр 3 ответов — с 1 по 3 (всего 3)
  • Тема «Каким образом реализовать такой вывод записей?» закрыта для новых ответов.