Palych_tw
@Palych_tw
Типа веб-разработчик

Поможете с циклами wordpress?

Есть проблема в теме WP. Что-то криво написал. Есть шаблон записи и сайдбара. В сайдбаре анонсы последних новостей, в т.ч. есть дата публикации. При переходе на последнюю(верхнюю) новость в сайдбаре там пропадает дата и отображается только в самом посте. привожу код single.php
<?php get_header(); ?>
<main>
<div class="container">
    <div class="row">
        <div class="col-md-9 page-content">
            <article>
            <?php if (have_posts()) : ?>
            <?php while (have_posts()):the_post(); ?>
                <h1><? the_title();?></h1>
                <span><?php the_date('j F Y');?></span>
                <?php the_content();?>
                    <?php endwhile;?>
                    <?php else : ?>
                    <?php endif; ?>
            </article>
        </div>
         <div class="col-md-3">
            <?php get_sidebar();?>
        </div>
    </div>
</div> 
</main>
<?php get_footer(); ?>


и sidebar.php (второй цикл get_posts выводит новости)

<aside>
 <?php if (!function_exists('dynamic_sidebar') || !dynamic_sidebar() ) : ?>
 <?php endif; ?>
  <div class="events-list-sidebar list-sidebar">
    <?php $args = array(
     'post_type'        => 'event',
     'suppress_filters' => false 
      );
    $event_posts = get_posts( $args ); 
    foreach( $event_posts as $post ){ setup_postdata($post);?>
    <div class="sidebar-list-item clearfix">
     <a href="<?php esc_url(the_permalink()) ?>">
      <figure class="item-img"><?php the_post_thumbnail(array(70,70),true); ?></figure>
      <span class="item-date"><?php echo eo_get_the_start('j F Y');?></span>
      <h4><?php the_title(); ?></h4>
     </a>
     </div>
    <?php }
    wp_reset_postdata(); ?>
   </div>
 <?php echo do_shortcode('[do_widget id=text-3]');?>
  <div class="list-sidebar">
   <?php $args = array(
     'category' => '6' 
      );
    $news_posts = get_posts( $args ); 
    foreach( $news_posts as $post ){ setup_postdata($post);?>
    <div class="sidebar-list-item clearfix">
     <a href="<?php esc_url(the_permalink()) ?>">
      <figure class="item-img"><?php the_post_thumbnail(array(70,70),true); ?></figure>
      <span class="item-date"><?php echo the_date('j F Y');?></span>
      <h4><?php the_title(); ?></h4>
     </a>
    </div>
   <?php }
    wp_reset_postdata(); ?>
   </div>
</aside>


UPD: Если сайдбар поставить слева, то дата не выводится у первой(нижней) записи, НО не в анонсе, а в странице.
  • Вопрос задан
  • 148 просмотров
Решения вопроса 1
HeadOnFire
@HeadOnFire
PHP, Laravel & WordPress Evangelist
Читайте документацию:

SPECIAL NOTE: When there are multiple posts on a page published under the SAME DAY, the_date() only displays the date for the first post (that is, the first instance of the_date()). To repeat the date for posts published under the same day, you should use the Template Tag the_time() or get_the_date() (since 3.0) with a date-specific format string.

Use <?php the_time( get_option( 'date_format' ) ); ?> to add the date set in the admin interface.
Ответ написан
Пригласить эксперта
Ответы на вопрос 1
@SergZay
Покажите сайт.
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы
YCLIENTS Москва
от 200 000 до 350 000 ₽
Ведисофт Екатеринбург
от 25 000 ₽
ИТЦ Аусферр Магнитогорск
от 100 000 до 160 000 ₽
23 апр. 2024, в 15:45
10000 руб./за проект
23 апр. 2024, в 15:42
5000 руб./за проект
23 апр. 2024, в 15:34
10000 руб./за проект