-
AuthorPosts
-
July 13, 2018 at 10:45 pm #985343
I’ve read all of the posts about the previous/next arrows on portfolio items not showing only items from the same category but I can’t get them to work. I’m using a child theme and the following in functions.php
if(!function_exists(‘avia_post_nav’))
{
function avia_post_nav($same_category = true, $taxonomy = ‘category’)
{
global $wp_version;
$settings = array();
$settings[‘same_category’] = $same_category;
$settings[‘excluded_terms’] = ”;
$settings[‘wpversion’] = $wp_version;//dont display if a fullscreen slider is available since they overlap
if((class_exists(‘avia_sc_layerslider’) && !empty(avia_sc_layerslider::$slide_count)) ||
class_exists(‘avia_sc_slider_full’) && !empty(avia_sc_slider_full::$slide_count) ) $settings[‘is_fullwidth’] = true;$settings[‘type’] = get_post_type();
$settings[‘taxonomy’] = ($settings[‘type’] == ‘portfolio’) ? ‘portfolio_entries’ : $taxonomy;if(!is_singular() || is_post_type_hierarchical($settings[‘type’])) $settings[‘is_hierarchical’] = true;
if($settings[‘type’] === ‘topic’ || $settings[‘type’] === ‘reply’) $settings[‘is_bbpress’] = true;$settings = apply_filters(‘avia_post_nav_settings’, $settings);
if(!empty($settings[‘is_bbpress’]) || !empty($settings[‘is_hierarchical’]) || !empty($settings[‘is_fullwidth’])) return;if(version_compare($settings[‘wpversion’], ‘3.8’, ‘>=’ ))
{
$entries[‘next’] = get_previous_post($settings[‘same_category’], $settings[‘excluded_terms’], $settings[‘taxonomy’]);
$entries[‘prev’] = get_next_post($settings[‘same_category’], $settings[‘excluded_terms’], $settings[‘taxonomy’]);
}
else
{
$entries[‘next’] = get_previous_post($settings[‘same_category’]);
$entries[‘prev’] = get_next_post($settings[‘same_category’]);
}$entries = apply_filters(‘avia_post_nav_entries’, $entries, $settings);
$output = “”;foreach ($entries as $key => $entry)
{
if(empty($entry)) continue;
$the_title = isset($entry->av_custom_title) ? $entry->av_custom_title : avia_backend_truncate(get_the_title($entry->ID),75,” “);
$link = isset($entry->av_custom_link) ? $entry->av_custom_link : get_permalink($entry->ID);
$image = isset($entry->av_custom_image) ? $entry->av_custom_image : get_the_post_thumbnail($entry->ID, ‘thumbnail’);$tc1 = $tc2 = “”;
$class = $image ? “with-image” : “without-image”;But I’m still getting all portfolio items, not just ones in the same category.
July 14, 2018 at 12:28 am #985348can you please try this instead in your functions.php of your child-theme:
add_filter( 'avia_post_nav_settings', 'enfold_customization_same_cat' ); function enfold_customization_same_cat( $s ) { $s['same_category'] = true; return $s; }
July 14, 2018 at 2:06 am #985353No, that doesn’t seem to make any change. I’m still getting arrows to go through all portfolio items. But I also need to reverse the previous/next arrows which is why I’m using the first code snippet.
July 14, 2018 at 11:18 am #985461to have vice-versa post navs you can use this:
add_filter( 'avia_post_nav_entries', 'enfold_customization_postnav', 10, 2); function enfold_customization_postnav($entries, $settings) { $entries['prev'] = get_next_post($settings['same_category']); $entries['next'] = get_previous_post($settings['same_category']); return $entries; }
and sorry i did not read that it is a portfolio:
the portfolio “categories” aren’t real categories – they are ( as for events too) taxonomies:add_filter('avia_post_nav_settings', 'avia_post_nav_settings_mod'); function avia_post_nav_settings_mod($settings) { if(is_singular('portfolio')) { $settings['taxonomy'] = 'portfolio_entries'; $settings['same_category'] = true;} return $settings; }
PS: please use for code the code block element on top of the input field:
click once code – enter your code – click it a second time
or enter your code – activate the whole code you entered with your mouse – press once code button.
the code is therefore difficult to read and to check – in addition, certain characters are converted by Boardsoft. The code in the code block can be copied and inserted directly to your functions.php of your child-theme- This reply was modified 6 years, 5 months ago by Guenni007.
July 14, 2018 at 10:16 pm #985509Hm, no go. When I add just the first snippet, there’s no change. Still getting all portfolio items in the left/right arrows. When I add the second snippet as well, the arrows completely disappeared. If I add just the second one, there are no arrows at all.
July 15, 2018 at 2:36 am #985542hm stange – you see here on Enfold 4.4.1 that portfolio – it has only one other portfolio in the same “category” = frontside
and you see that there is only that other portfolion in the left right navigation: https://webers-testseite.de/portfolio-item/pirol-hifi/July 15, 2018 at 10:23 pm #985769ok – this seems to be not working anymore on the newest enfold:
add_filter( 'avia_post_nav_entries', 'enfold_customization_postnav', 10, 2); function enfold_customization_postnav($entries, $settings) { $entries['prev'] = get_next_post($settings['same_category']); $entries['next'] = get_previous_post($settings['same_category']); return $entries; }
there is something new on Enfold 4.4.1 – so please try:
add_filter( 'avia_post_nav_entries', 'enfold_customization_postnav', 10, 2); function enfold_customization_postnav($entries, $settings) { $entries['prev'] = get_next_post($settings['same_category'], $settings['excluded_terms'], $settings['taxonomy']); $entries['next'] = get_previous_post($settings['same_category'], $settings['excluded_terms'], $settings['taxonomy']); return $entries; }
but this works on my 4.4.1 install:
add_filter('avia_post_nav_settings', 'avia_post_nav_settings_mod'); function avia_post_nav_settings_mod($settings) { if(is_singular('portfolio')) { $settings['taxonomy'] = 'portfolio_entries'; $settings['same_category'] = true;} return $settings; }
July 16, 2018 at 6:38 pm #986036Ok, the snippet to reverse the next/prev buttons works! But still no go on the limiting to the same category. I made a new portfolio item and put it in it’s own category. No other portfolio items with that category at all. And it still shows the next button and just goes through all portfolio items:
I’m using
add_filter('avia_post_nav_settings', 'avia_post_nav_settings_mod'); function avia_post_nav_settings_mod($settings) { if(is_singular('portfolio')) { $settings['taxonomy'] = 'portfolio_entries'; $settings['same_category'] = true;} return $settings; }
The full functions.php is:
<?php add_filter('avf_postgrid_excerpt_length','avia_change_postgrid_excerpt_length', 10, 1); function avia_change_postgrid_excerpt_length($length) { $length = 300; return $length; } add_filter('avia_post_nav_settings', 'avia_post_nav_settings_mod'); function avia_post_nav_settings_mod($settings) { if(is_singular('portfolio')) { $settings['taxonomy'] = 'portfolio_entries'; $settings['same_category'] = true;} return $settings; } add_filter( 'avia_post_nav_entries', 'enfold_customization_postnav', 10, 2); function enfold_customization_postnav($entries, $settings) { $entries['prev'] = get_next_post($settings['same_category'], $settings['excluded_terms'], $settings['taxonomy']); $entries['next'] = get_previous_post($settings['same_category'], $settings['excluded_terms'], $settings['taxonomy']); return $entries; }
July 16, 2018 at 8:11 pm #986083Hey!
Please try this code to limit the next/prev links to the same category/term:
add_filter( 'avia_post_nav_entries', 'enfold_customization_postnav', 10, 2); function enfold_customization_postnav($entries, $settings) { if($settings['type'] == 'portfolio') { $settings['same_category'] = true; $entries['prev'] = get_next_post($settings['same_category'], $settings['excluded_terms'], $settings['taxonomy']); $entries['next'] = get_previous_post($settings['same_category'], $settings['excluded_terms'], $settings['taxonomy']); } return $entries; }
I tested it on my website and it worked.
Regards,
PeterJuly 16, 2018 at 11:08 pm #986138So I used that to replace both previous code snippets and it works to reverse the direction correctly but it doesn’t do anything to limit it to one category. So I know it’s working. If I remove it, the post order reverses to the original. But still shows all portfolio items. We’re talking about the arrows to the right and left of the portfolio items that show up on hover, with the thumbnail of the next portfolio item. Class “avia-post-nav” stuff, right?
July 17, 2018 at 11:56 am #986372yes i know – and you can see on may test-page ( https://webers-testseite.de/portfolio-item/pirol-hifi/ ) that the code above works well for my Enfold 4.4.1
there are a lot of portfolios but- only two with “category” frontside – and only these two are shown.
i do not know why it works on my installtion (4.4.1) and on your setup not.July 17, 2018 at 6:08 pm #986532Hey!
I found the culprit – the “Simple Custom Post Order” plugin which runs on your website breaks the get_next_post() and get_previous_post() functions. As soon as I deactivate the plugin the arrows work as intended. I’d suggest to contact the plugin author because both functions are standard wordpress functions and this seems to be a plugin issue.
Best regards,
PeterJuly 17, 2018 at 7:45 pm #986601Whoa! Thanks man. That’s crazy. I’ll figure it out from here. Amazing work!
July 18, 2018 at 7:09 am #986795Hi,
Great, glad we could help. Please let us know if you should need any further help on the topic or if we can close it.
Best regards,
RikardJuly 18, 2018 at 4:11 pm #987078We can close it.
July 19, 2018 at 6:59 am #987279 -
AuthorPosts
- The topic ‘Previous/Next buttons only same category’ is closed to new replies.