Forum
How to exclude blog post I'm reading from aside column
Hi
On our blog posts we have an aside column which shows the latest 5 blog posts, using perch_blog_custom
I'm trying to exclude the post your currently viewing from displaying in the aside list. I've got so far...
$postID = PerchSystem::get_var('postID');
perch_blog_custom(array(
'sort' => 'postDateTime',
'sort-order' => 'DESC',
'count' => 5,
'template' => 'blog-post-aside.html',
'filter' => 'postID',
'match' => 'neq',
'value' => $postID,
));
...but it's not working.
How do I pass postID
to perch_blog_custom
so it can filter out the current post you're reading from the aside column.
Many thanks
Hello Glen,
Assuming you already know the slug of the current post (perhaps you're getting it with
perch_get('s')
), it would be easier to use it for your filter:Spot on, thanks Hussein
Hi Hussein Al Hammad
I don't suppose you also know how to only show posts from the same category of the main post?
I've currently got...
...but it's not showing anything.
catDept
is the category ID of the main post that I wish to show other posts that have the same category. There are 2 categories for each post if that makes a difference, department and office?Many thanks
I believe you need to use the category path for filtering. If you want to filter for multiple categories, you need to use an array
'category' => ['blog/category1', 'blog/category2']
.Since you already know the post's slug, I'd use
perch_blog_post_categories()
to get the post's categories.templates/blog/cat_path.html
:Then you should be able to use
'category' => $cat_paths
.Thanks very much for your help Hussein.
Unfortunately, that's showing all posts from all categories.
My aim is to only show other posts that are in the same category as the main post you're reading.
I'm only filtering by one category ID
catDept
but the path needs to be dynamic, depending on what post your viewing.Here's what I've got so far...
I thought you wanted to display posts that belong to any category which the current post belongs to!
If you already know the category ID, you can get the path with
perch_categories()
:The
cat_path.html
template needs to be intemplates/categories
Sorry for any confusion with my explanation.
Thank you for all your help, but unfortunately, nothing is displaying, here's my code so far...
and then
/perch/templates/categories/cat_path.html
looks like..what am I missing???
How are you setting the value of
$catID
? Did you confirm you're getting the correct category path?Also, make sure
cat_path.html
doesn't have any whitespace.perch_blog_category()
outputs the title of a category.What does
perch_get('cat')
get you? Do you have a URL parameter calledcat
?No, the blog URLs are
blog/[slug:s]
.To be honest I'm just guessing now.
From the docs:
So...
I understand each post belongs to 2 categories and you want to filter on only one of these categories. How are you assigning which category is the "main" category?
It might be a good idea to open a new thread so others can help too (this is marked as solved so they may not check it)
Hi Hussein
Many thanks.
Yes, the blog posts have 2 category sets, "department" and "office".
On the blog post page, my aim was in the
aside
column to have the latest posts from the same "department" category as the post itself.Can you show us your blog post template?
/perch/templates/pages/blog/post.php
looks like this...and here is
/perch/templates/blog/post_aside.html
I actually wanted to see your
templates/blog/post.html
Still work in progress but looks like this...
ALL WORKING - thanks your all your help Hussein
Great!