Comments (6)
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(); ?>
from bs-grid.
I'm sorry to post as an issue but there are not discussions tabs for this plugin.
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 single.php
:
<!-- 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?
from bs-grid.
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 Warning : Object of class WP_Term could not be converted to int in C:\xampp\htdocs\wp-includes\functions.php
I followed : https://developer.wordpress.org/reference/classes/wp_query/#tag-parameters
Do you have an idea why ? I know it's a bit out of scope, I'm sorry.
from bs-grid.
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?
from bs-grid.
👍 You‘re welcome!
from bs-grid.
We will create related posts by the next bS Swiper plugin release.
from bs-grid.
Related Issues (9)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bs-grid.