S
S
Sept522020-08-05 19:17:07
WordPress
Sept52, 2020-08-05 19:17:07

How to make a section in a slidebar cross-cutting?

5f2adb2fd06ed584563377.jpeg
Popular Posts will be filled with articles BY HANDS. And this section is manual - should be a draft in the sidebar?
how to do it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Litvinenko, 2020-08-05
@Sept52

A sidebar is basically a cross-cutting element on a website.
You can display a widget there in at least two ways - the code that you planned to display as a widget and insert directly from the widget menu, you can directly insert this code into the sidebar
. less i have sample code:

The code

<?php

$actualLoop = new WP_Query(array(
  'posts_per_page' => 5,
  'post_type'      => 'post',
  'orderby'        => 'date',
  'order'          => 'DESC',
  'meta_query'     => array(
    array(
      'key'     => 'is_actual',
      'value'   => '1',
      'compare' => 'LIKE',
    )
  ),
));

if ( $actualLoop->have_posts() ) : ?>

<div class="sidebar-inner-right">
  <h2 class="sidebar-title"><?php _e('Актуально') ?></h2>

  <?php while ( $actualLoop->have_posts() ) : $actualLoop->the_post();
    $is_actual = get_field('is_actual');
  ?>

    <?php if ($is_actual): ?>

    <a href="<?php the_permalink() ?>">
      <div class="news-img-block">
        <div class="img-wrapper">
          <?php if (has_post_thumbnail()) {
            the_post_thumbnail('blog-thumb');
          }else{
            echo '<img class="no-img" src="'. get_bloginfo('template_directory'). '/assets/img/no-thumbnail.jpg' . '" alt="no image">';
          }?>
        </div>
        <h3 class="news-img-block-title"><?php trim_title_words(10, '...'); ?></h3>
        <div class="news-block-info">
          <div class="news-block-info-item news-block-date">
            <?php echo theCustomDate() ?>
          </div>
          <div class="news-block-info-item news-block-views">
            <?php _e('Переглядів:') ?> 
            <?php echo getPostViews(get_the_ID()); ?>
          </div>
          <div class="news-block-info-item news-block-comments">
            <?php echo num_comments() ?>
          </div>
        </div>
        <div class="news-block-excerpt">
          <?php echo kama_excerpt( array('maxchar'=>80) ); ?>
        </div>
      </div>
    </a>

    <?php endif ?>

  <?php endwhile;?>

</div>

<?php endif; wp_reset_query(); ?>


The markup of each item itself is clear that it will have its own.
Here we have the opportunity to set a checkbox in each record, this is a custom field with the is_actual slug, in my case made using ACF. If the checkbox is checked, the entry will be displayed.
I pasted this code directly into the sidebar

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question