-
-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Related posts #8
Comments
Don't say sorry when open an issue. That's why they are there and we'd love to solve them. Discussions are a new feature and only enabled at the main-theme's repo, because it's much more going on there. Issues for plugins are fine. However, a shortcode is to select what you want to show and not to deselect. See here bootscore/bs-swiper#4 (comment) as well why the deselecting is an edge case and does not fit to the plugin. So, bS Grid is not well suited to create "related posts". Use a snippet for related posts and add it to <!-- related posts -->
<div class="related-posts mb-4">
<h2 class="h4 mb-3">You may interested in</h2>
<div class="row">
<?php
$related = get_posts( array( 'category__in' => wp_get_post_categories($post->ID), 'numberposts' => 6, 'post__not_in' => array($post->ID) ) );
if( $related ) foreach( $related as $post ) {
setup_postdata($post); ?>
<div class="col-md-6 mb-4">
<div class="card h-100">
<div class="row h-100">
<div class="col-5">
<?php the_post_thumbnail('medium', array('class' => 'related-post-card-img h-100')); ?>
</div>
<div class="col-7">
<div class="card-body ps-0 d-flex flex-column h-100">
<h3 class="h5 mb-0"><a class="stretched-link text-dark" href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a></h3>
<div class="mt-auto">
</div>
</div>
</div>
</div>
</div>
</div>
<?php }
wp_reset_postdata(); ?>
</div>
</div>
<!-- related posts End --> This snippet shows six related-posts from the same category. Used for example here https://intelligent-heizen.info/bundesministerium-fuer-wirtschaft-und-klimaschutz-passt-beliebte-beg-foerderung-fuer-heizungstechnik-ab-15-august-2022-an/ Change HTML as you want or simply copy the loop content cards from bS Grid template to it. Does this help? |
Hello @crftwrk ! As always, thank you for your answer. Your solution is a good approach, I'll use this ! I prefer to use tag instead of category but I can't display the tag, I tried: $related = get_posts( array( 'tag__in' => wp_get_post_tags($post->ID), 'numberposts' => 2, 'post__not_in' => array($post->ID) ) ); but it returns Do you have an idea why ? I know it's a bit out of scope, I'm sorry. |
There are several approaches for related posts in the web. Maybe this one https://www.hongkiat.com/blog/wordpress-related-posts-without-plugins/ is what you are searching for? |
Perfect ! I reused most of the bs-grid template and adapted to my case. Thank you basti. If it can help anyone in the future: <?php
$tags = wp_get_post_tags($post->ID);
$tag_ids = array();
foreach($tags as $individual_tag) $tag_ids[] = $individual_tag->term_id;
$args=array(
'tag__in' => $tag_ids,
'post__not_in' => array($post->ID),
'posts_per_page'=>4, // Number of related posts to display.
'caller_get_posts'=>1
);
$query = new WP_Query( $args );
if ($query->have_posts()) { ?>
<div class="row">
<?php while ($query->have_posts()) : $query->the_post(); ?>
<div class="col-md-6 col-lg-4 col-xxl-3 mb-4">
<div class="card h-100">
<!-- Featured Image-->
<?php the_post_thumbnail('medium', array('class' => 'card-img-top')); ?>
<div class="card-body d-flex flex-column">
<!-- Category badge -->
<?php bootscore_category_badge(); ?>
<!-- Title -->
<h2 class="blog-post-title">
<a href="<?php the_permalink(); ?>">
<?php the_title(); ?>
</a>
</h2>
<!-- Meta -->
<?php if ('post' === get_post_type()) : ?>
<small class="text-muted mb-2">
<?php
bootscore_date();
bootscore_author();
bootscore_comments();
bootscore_edit();
?>
</small>
<?php endif; ?>
<!-- Excerpt & Read more -->
<div class="card-text">
<?php the_excerpt(); ?>
</div>
<div class="mt-auto">
<a class="read-more" href="<?php the_permalink(); ?>"><?php _e('Read more »', 'bootscore'); ?></a>
</div>
<!-- Tags -->
<?php bootscore_tags(); ?>
</div>
</div>
</div>
<?php endwhile;
wp_reset_postdata(); ?>
</div><!-- .row -->
<?php }
wp_reset_postdata(); ?> |
👍 You‘re welcome! |
We will create related posts by the next bS Swiper plugin release. |
Hello,
I'm sorry to post as an issue but there are not discussions tabs for this plugin.
Is it possible to exclude a specific ID from the shortcode ? I'm using this plugin as related posts on each post. But it displays also the current post. In my specific case, I find this not very useful.
My current shortcdode:
<?php echo do_shortcode('[bs-grid type="post" tax="post_tag" terms="'.tag_solo().'" order="desc" orderby="date" posts="4"]'); ?>
Thank you !
The text was updated successfully, but these errors were encountered: