-
AuthorPosts
-
June 29, 2020 at 10:26 am #1226345
My Blog page has a Blog Posts element from the Content Elements in ALB. Set to display Blog posts from the Blog category:
– grid layout
– title excerpt and readmore
– display all entries,
– deactivate offset
– always display
– pagination: 4, yesin child theme functions.php:
// breadcrumbs filter for blog posts, stop breadcrumbs showing category for news if(!function_exists('avia_modify_single_post_breadcrumb')) { function avia_modify_single_post_breadcrumb($trail) { if(!is_single()) return $trail; $category = get_the_category(get_the_ID()); if(empty($category)) return $trail; $newtrail = array(); foreach($category as $cat) { if(empty($cat->parent)) { $category_link = get_category_link($cat->term_id); $newtrail[] = '<a href="'.esc_url( $category_link ).'" title="'.$cat->cat_name.'">'.$cat->cat_name.'</a>'; } } if(empty($newtrail)) return $trail; array_unshift($newtrail, $trail[0]); $newtrail['trail_end'] = $trail['trail_end']; return $newtrail; } add_filter('avia_breadcrumbs_trail','avia_modify_single_post_breadcrumb'); }
// Different template for static Blog page (News) in Enfold instead of archive style // The archive pages don’t support an “Advanced Layout” blog template but you can select a different // static blog template if you don’t like the archive page layout. add_filter('avf_blog_style','avia_change_archive_blog_layout', 10, 2); function avia_change_archive_blog_layout($layout, $context){ if($context == 'archive') $layout = 'blog-grid'; return $layout; }
in child theme archive.php:
$atts = array( 'type' => 'grid', 'items' => get_option('posts_per_page'), 'columns' => 3, 'contents' => 'excerpt_read_more', 'class' => 'avia-builder-el-no-sibling', 'paginate' => 'yes', 'use_main_query_pagination' => 'yes', 'custom_query' => array( 'post__in'=>$post_ids, 'post_type'=>get_post_types() ) );
Issue:
Blog item when opened shows the breadcrumb: Home/Blog/Item
“Blog” in breadcrumb points to: Archive for category: Blog
When clicked it shows: Home/Blog/Blog
There the middle “Blog” in the breadcrumb points to the real Blog page again…How can I fix this? Thanks in advance for your help.
Rob
July 1, 2020 at 9:51 am #1227190Hey Rob,
Thank you for the inquiry.
Looks like you’re also using Blog as category and the avia_modify_single_post_breadcrumb filter above includes both the Blog page and Blog category in the breadcrumb trail. What are you trying to do with the filter?
Best regards,
IsmaelJuly 1, 2020 at 10:22 am #1227203Hi Ismael,
Thanks for looking into this.
I would like the breadcrumb to always point to the Page with the Blog category I set up.
So when a Blog post (single) is opened the breadcrumbs “Blog” always points to the “Blog Category Page”, never to the “Archive for category: Blog”. That would remove the whole issue with the breadcrumb on the Archive page from the site and from sight. :-) But I cannot figure out how to get that done.
It is somewhat confusing for me that concerning the blog post WP overrides so many things from the theme, I could not find clear instructions on how to get all settings right when using an archive page susbstitute like I do. But perhaps I’ve looked in the wrong places or did not understand it well enough. Your help is much appreciated (I can see how busy you guys are on the support forum).Kind regards,
RobP.S.
I suspect the issue is with the breadcrumbs filter in my child theme functions.php (described earlier above), called “// breadcrumbs filter for blog posts, stop breadcrumbs showing category for news”
I just don’t have the coding knowledge to adapt that to show the page_id in the trail instead of the category.
I just knew my lack of time spent learning to code would come back to haunt me one day :-))
So if you could help me adapt that to point to the page instead of the category, perhaps that is the solution?
But I’m not quite sure, maybe you have a different idea.Thanks again!- This reply was modified 4 years, 4 months ago by rob2701. Reason: breadcrumbs filter in my child theme idea added
July 5, 2020 at 8:39 pm #1228077Hi,
Thank you for the update.
We can wrap this block of code inside a conditional tag to exclude the category Blog from the breadcrumb trail whe an archive page is in view.
foreach($category as $cat) { if(empty($cat->parent)) { $category_link = get_category_link($cat->term_id); $newtrail[] = '<a href="'.esc_url( $category_link ).'" title="'.$cat->cat_name.'">'.$cat->cat_name.'</a>'; } }
Replace it with:
if(!is_archive()) { foreach($category as $cat) { if(empty($cat->parent)) { $category_link = get_category_link($cat->term_id); $newtrail[] = '<a href="'.esc_url( $category_link ).'" title="'.$cat->cat_name.'">'.$cat->cat_name.'</a>'; } } }
Best regards,
IsmaelJuly 5, 2020 at 9:13 pm #1228087Hi Ismael,
Thanks for looking into this. I have entered the change in the child theme functions.php (starts at line 358).
Unfortunately it doesn’t do what I wanted to achieve, probably I didn’t explain it well enough.
When I have a blog post open from the Blog page, the breadcrumb still shows:
<site>/category/blog
What I want to achieve is that the breadcrumb on an open blog post points to <site>/blog, so to the Blog PAGE, _not_ the Blog category (which is the archive page). I hope I explained it better this time.Thank you for your help and for your patience with my explanations… :-)
Rob
July 7, 2020 at 10:14 pm #1228700Hi,
Do you want to remove the category blog when you’re on the single post page? What happens when you remove the breadcrumb filter above?
You may need to replace is_archive with is_singular(‘post’).
if(!is_archive()) {
.. to:
if(!is_singular('post')) {
This should remove the categories from the breadcrumb, or prevent them from displaying.
A direct link to a post with the breadcrumb issue will help.
Best regards,
IsmaelJuly 7, 2020 at 11:06 pm #1228713Hi Ismael,
This is the Blog Page (Blog Post elements on a page ALB):
<site>/blog/Open ANY blog post on that page, for example:
<site>/screenprint-special-characters/the breadcrumb in the opened post points to:
<site>/category/blog/But I want the breadcrumb “Blog” on an opened blog item to always point to the blog post Page, i.e. <site>/blog
The confusion comes from me making the archive for blog category look exactly like the blog post page. I did that to not make it so obvious that the breadcrumb points to the wrong page on opened blog posts. Hope that explains it better.
I also realise that the title for this thread is wrong, it is about “Breadcrumbs in a Blog element page pointing to the Blog archive page”. It is a bit late to change that now, unless you know how :-)When I take the whole part out in the functions.php the breadcrumb becomes:
You are here: Home / Blog / Blog / Screenprint special characters
The first Blog points to: <site>/blog
The second Blog points to: <site>/category/blog/When I replace is_archive with is_singular(‘post’) in your adapted code it gives this on an opened blog post:
You are here: Home / Blog / Blog / Screenprint special characters
The first Blog points to: <site>/blog
The second Blog points to: <site>/category/blog/Inside the Archive for Category: Blog the breadcrumb becomes:
You are here: Home / Blog / Blog
The first Blog points to: <site>/blog
The second Blog points to: <site>/category/blog/All I am trying to achieve is to get the breadcrumb on opened Blog posts to display just one Blog, which pointS to the Blog page. That’s all.
Thanks for your help!
Rob
July 8, 2020 at 6:27 am #1228764Hi Ismael,
Never mind, I managed to find a good solution in an old thread here :-)
https://kriesi.at/support/topic/remove-category-from-breadcrumb/#post-426142// Remove Blog Category from single post breadcrumbs // Single post shows trail Home/BlogPage/BlogCategory/ItemName // see https://kriesi.at/support/topic/remove-category-from-breadcrumb/ // 1st element is Blog Page, 2nd element is Blog Category, remove #2 add_filter( 'avia_breadcrumbs_trail', 'mmx_remove_element_from_trail', 50, 2 ); function mmx_remove_element_from_trail( $trail, $args ) { if ( is_single() ) { unset ($trail[2]); } return $trail; }
Topic is solved and can be closed.
Kind regards,
Rob- This reply was modified 4 years, 4 months ago by rob2701. Reason: added code to be code
July 8, 2020 at 7:36 pm #1228973Hi,
I’m glad this was resolved. If you need additional help, please let us know here in the forums.
Best regards,
Jordan Shannon -
AuthorPosts
- The topic ‘Breadcrumbs in Blog archive page layout’ is closed to new replies.