I’m engaged on a web-based journal in WordPress PHP. I created a customized put up kind (article) with 4 out there customized classes. Within the sidebar I wish to present the latest put up of all of the 4 classes. But when one of the current articles are literally open within the browser, I would like the sidebar to point out the second most up-to-date article within the given class to keep away from recurrence. I acquired to the purpose the place I extracted the slug from the browser url and the slug of the newest put up from the given class, however I finished there. I feel I ought to use an if assertion, however I do not fairly understand how. I respect all assist, thanks.
sidebar-right.php (this is only one question of the 4 within the sidebar, I repeat this code for all 4 classes):
<?php
international $put up;
$post_slug_open = $post->post_name;
?>
<div class="sidebar-preview-container">
<?php
// Outline our WP Question Parameters
$the_query = new WP_Query(array(
'post_type' => 'articles',
'post_status' => 'publish',
'posts_per_page' => 1,
'orderby' => 'date',
'order' => 'DESC',
'tax_query' => array(
array(
'taxonomy' => 'article_category',
'subject' => 'slug',
'phrases' => 'interju',
)
),
));
?>
<?php
// Begin our WP Question
whereas ($the_query->have_posts()) : $the_query->the_post();
// Show the Put up Title with Hyperlink
$article_categories = get_the_terms(get_the_ID(), 'article_category');
$article_title = get_field("article_title");
$article_subtitle = get_field('article_subtitle');
$article_preview_image = get_field('article_preview_image');
$article_slug = get_post_field('post_name', get_post());
setup_postdata($put up);
?>
<div class="sidebar-article-preview">
<?php
if ($article_categories) :
foreach ($article_categories as $article_category) :
?>
<a href="<?php echo get_stylesheet_directory_uri(); ?>/<?php echo $article_category->slug; ?>">
<h6 class="article-category-preview">
<?php echo $article_category->identify; ?>
<?php echo $article_slug; ?>
</h6>
</a>
<?php
endforeach;
endif;
?>
<a href="<?php the_permalink() ?>">
<h4 class="article-title-preview">
<?php the_title(); ?>
</h4>
</a>
<p class="article-subtitle-preview">
<?php echo $article_subtitle; ?>
</p>
<a href="<?php echo get_permalink(); ?>">
<img class="article-preview-img" src="<?php echo $article_preview_image['url']; ?>" alt="<?php echo $article_preview_image['alt']; ?>">
</a>
</div>
````````````````