I wish to put a drop-down button on my WordPress category page. This drop-down button will have two choices; 'Ascending' and 'Descending'. After clicking the choice, posts on that page will re-order accordingly.
Can anyone help? Right now, the theme is using years. But it doesn't work properly.
Below, the theme is displaying post years in a drop-down menü.
<li class="dropdown">
<a class="nav-link dropdown-toggle" data-bs-toggle="dropdown" href="#" role="button" aria-expanded="false">Sırala</a>
<ul class="dropdown-menu">
<?php
$terms_year = array(
'post_type' => array('post'),
);
$years = array();
$query_year = new WP_Query( $terms_year );
if ( $query_year->have_posts() ) :
while ( $query_year->have_posts() ) : $query_year->the_post();
$year = get_the_date('Y');
if(!in_array($year, $years)){
$years[] = $year;
}
endwhile;
wp_reset_postdata();
endif;
foreach ($years as $year) {
?>
<li class="nav-item"><a class="nav-link dropdown-item" data-bs-toggle="tab" data-bs-target="#year-<?php echo $year; ?>" type="button" role="tab"><?php echo $year; ?></a></li>
<?php } ?>
</ul>
</li>
I want to change that, as I have mentioned.
And here is how posts are displayed (but it doesn't work).
<?php
foreach( $years as $year ) {
?>
<div class="tab-pane fade" id="year-<?php echo $year; ?>">
<div class="items">
<div class="container">
<div class="row">
<?php wp_reset_query(); if (have_posts()) : while (have_posts()) : the_post(); $date = get_the_date('Y'); ?>
<?php if($date == $year) { ?>
<div class="col-12 col-sm-12 col-md-12 col-lg-4 col-xl-4 column">
<div class="item">
<a href="<?php the_permalink(); ?>" style="color: <?php echo $rl_category_color; ?>;" class="d-flex align-items-center">
<div class="in">
<div class="d-flex justify-content-between author">
<div class="author-name col-7">
<?php
$author = get_post_meta( get_the_ID(), 'postAuthor', true );
if(!empty($author)) {
foreach ($author as $author_item => $item) {
echo get_the_title($item).'<br>';
}
}
?>
</div>
<div class="rank col-5 text-end">
<?php
$konu = get_the_category( get_the_ID() );
foreach ($konu as $item) {
$konu_name = $item->name;
}
echo $konu_name;
?>
</div>
</div>
<div class="title"><?php echo title_limit(40); ?></div>
<p><?php echo icerik_limit(get_the_content(), 150); ?></p>
</div>
</a>
</div>
</div>
<?php } ?>
<?php endwhile; endif; ?>
</div>
</div>
</div>
</div>
<?php } ?>
Related Page: https://www.mgc.com.tr/haberler/