Skip to content

Instantly share code, notes, and snippets.

@Prroffessorr
Last active September 29, 2021 08:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Prroffessorr/8a91dfee3bf52c94ce2833e234d18b3b to your computer and use it in GitHub Desktop.
Save Prroffessorr/8a91dfee3bf52c94ce2833e234d18b3b to your computer and use it in GitHub Desktop.
Retrieving a list of posts by tag_id (wordpress)
<?php
function show_posts_by_tags($tag_id, $post_id, $post_per_page, $orderby, $order){
$params = array(
'post_type' => 'post',
'post_status' => 'publish',
'orderby' => $orderby,
'order' => $order,
'posts_per_page' => $post_per_page,
'tag_id' => $tag_id,
'post__not_in' => array($post_id),
);
$query = new WP_Query($params);
if($query->have_posts()): ?>
<div class="container">
<ul class="article-section__list">
<?php
while ($query->have_posts()):
$query->the_post();
get_template_part('template-parts/custom/releated-post');
endwhile; ?>
</ul>
</div>
<?php
endif;
wp_reset_postdata();
}
<li>
<article class="article-card">
<div class="article-label
<?php
//Если метка не равная метке "Статья" то меняем цвет заднего фона на зеленый
if(get_the_tags(get_the_ID())[0]->term_id != apply_filters('wpml_object_id', 26, 'post')): ?>
article-label--green
<?php endif;?> ">
<?php echo get_the_tags(get_the_ID())[0]->name; ?>
</div>
<time class="article-card__date" datetime="<?php echo get_the_date("Y-m-d"); ?>">
<?php echo get_the_date("d F Y"); ?>
</time>
<h2 class="article-card__title">
<span title="<?php echo get_the_title(); ?>">
<?php echo get_the_title(); ?>
</span>
</h2>
<div class="article-card__des">
<?php echo get_the_excerpt(); ?>
</div>
<a href="<?php echo get_the_permalink(); ?>" class="link-more article-card__more">
<?php _e("More details", "biorich"); ?>
</a>
</article>
</li>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment