I am pretty new at this, so please excuse my ignorance.
I am attempting to order my posts within the web site’s classes with a button, ‘ascending”https://wordpress.stackexchange.com/”descending’.
I am attempting to make use of ‘sortit’ perform as a result of that is the one supply I might discover on-line; been engaged on this all of the previous week.
So what I did right here is;
<li class="dropdown">
<a category="nav-link dropdown-toggle" data-bs-toggle="dropdown" href="#" function="button" aria-expanded="false">Sırala</a>
<ul class="dropdown-menu">
<li class="nav-item"><a href="?sortby=asc" class="nav-link dropdown-item" kind="button" function="tab">Yeniden Eskiye</a></li>
<li class="nav-item"><a href="?sortby=desc" class="nav-link dropdown-item" kind="button" function="tab">Eskiden Yeniye</a></li>
</ul>
</li>
Add a code to the menu, so the URL will likely be ‘?sortby=asc’ or ‘?sortby=desc’
(Website online is in Turkish so ignore the texts)
The following step was including a perform.
perform sortIt($sortType)
{
international $wp_query;
$cat_ID = get_query_var('cat');
if (strcmp($sortType, 'ASC') )
{
$newQuery = new WP_Query( array(
'orderby' => 'date' ,
'order' => 'ASC',
'cat' => $cat_ID,
'posts_per_page' => '10') );
}
if (strcmp($sortType, 'DESC') )
{
$newQuery = new WP_Query( array(
'orderby' => 'date' ,
'order' => 'DESC',
'cat' => $cat_ID,
'posts_per_page' => '10') );
}
return $newQuery;
}
Subsequent step is displaying them when the button is clicked, however it’s going to crash into one another with the present order so and if-else should be created right here. What I did is
<?php if (is_page('echo esc_url( wp_get_current_url()/?sortby=asc')) {
if ( $newQuery->have_posts() ) : whereas ( $newQuery->have_posts() ) : $newQuery->the_post();
} else { if (is_page('echo esc_url( wp_get_current_url()/?sortby=desc')) {
if ( $newQuery->have_posts() ) : whereas ( $newQuery->have_posts() ) : $newQuery->the_post();
} } else { if (have_posts()) : whereas (have_posts()) : the_post();
} ?>
However now I am getting an error, “Parse error: syntax error, surprising ‘}’ in”
Any concepts? Any assist?
Thanks.