Answer the question
In order to leave comments, you need to log in
Answer the question
In order to leave comments, you need to log in
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:
<?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(); ?>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question