@v_katunin

Wordpress. Как обернуть блок со статьей в ссылку на эту статью?

Здравствуйте. Подскажите, есть вывод записей на главной странице, сейчас кликабельны тоолько название статьи и изображение. Что нужно изменить в коде, чтобы кликабельным был весь блок записи?
<section class="newsfeed">
  <div class="container">
    <div class="row">    
      <?php

        $count_posts = wp_count_posts();
        $count_posts_1 = $count_posts - 1;

        $args = array( 
          'post_type' => 'post',
          'posts_per_page' => $count_posts_1
        );

        $query = new WP_Query( $args );
        while ( $query->have_posts() ) {
          $query->the_post();

          echo '<div class="col-md-4 col-sm-6 item box-hidden">
                  <div class="post-img">' . 
                    '<a href="' . get_the_permalink() . '">' . get_the_post_thumbnail() . '</a>' . 
                    '<div class="cat-name">' . 
                      get_the_category_list(',') . 
                    '</div>
                  </div>
                  <div class="post-description">
                    <h3>
                      <a href="' . get_the_permalink() . '">' .  
                        get_the_title() . 
                      '</a>
                    </h3>
                    <div class="post-meta">
                      <span class="date">' . get_the_date('j F') . '</span>
                      
                      <span class="comment-number">
                        <i class="fa fa-comment-o" aria-hidden="true"></i> ' . get_comments_number() . 
                      '</span>
                      
                    </div>
                  </div>
                </div>';
        }
        wp_reset_postdata(); 
        
      ?>
    </div>

    <button id="loadMore" class="primary-button">Показать еще</button>

    
  </div>
</section>
  • Вопрос задан
  • 347 просмотров
Пригласить эксперта
Ответы на вопрос 2
HeadOnFire
@HeadOnFire
PHP, Laravel & WordPress Evangelist
...
echo '<div class="col-md-4 col-sm-6 item box-hidden">
    <a href="' . get_the_permalink() . '">
        <div class="post-img">' . get_the_post_thumbnail() . '
            <div class="cat-name">' . get_the_category_list(',') . '</div>
        </div>
        <div class="post-description">
            <h3>' . get_the_title() . '</h3>
            <div class="post-meta">
                <span class="date">' . get_the_date('j F') . '</span>      
                <span class="comment-number"><i class="fa fa-comment-o" aria-hidden="true"></i> ' . get_comments_number() . '</span>
            </div>
        </div>
    </a>
</div>';
...
Ответ написан
deniscopro
@deniscopro Куратор тега WordPress
WordPress-разработчик, denisco.pro
Здравствуйте.

А так?
<section class="newsfeed">
  <div class="container">
    <div class="row">    
      <?php

        $count_posts = wp_count_posts();
        $count_posts_1 = $count_posts - 1;

        $args = array( 
          'post_type' => 'post',
          'posts_per_page' => $count_posts_1
        );

        $query = new WP_Query( $args );
        while ( $query->have_posts() ) {
          $query->the_post();

          echo '<a href="' . get_the_permalink() . '" class="col-md-4 col-sm-6 item box-hidden">
                  <div class="post-img">' . 
					get_the_post_thumbnail() . 
                    '<div class="cat-name">' . 
                      get_the_category_list(',') . 
                    '</div>
                  </div>
                  <div class="post-description">
                    <h3>' . get_the_title() . '</h3>
                    <div class="post-meta">
                      <span class="date">' . get_the_date('j F') . '</span>

                      <span class="comment-number">
                        <i class="fa fa-comment-o" aria-hidden="true"></i> ' . get_comments_number() . 
                      '</span>

                    </div>
                  </div>
                </a>';
        }
        wp_reset_postdata(); 

      ?>
    </div>

    <button id="loadMore" class="primary-button">Показать еще</button>


  </div>
</section>
Ответ написан
Комментировать
Ваш ответ на вопрос

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

Войти через центр авторизации
Похожие вопросы