Portfolio and categories

In the portfolio section I have 3 categories.

  • Artists
  • Artist Worldwide
  • Projects

If I enter a portfolio of “Artists” and I’m clicking on the top posts arrows … I end up showing portfolios of “Artists worldwide” and “Projects”.

The logical thing would be that it would only show those of its same category … no?

Hey Mauro,

Regretfully, no. The Entry Navigation currently cycles through all posts. That function uses the WordPress get_adjacent_post function though so if you’re interested in modifying it, copy the x_entry_navigation inside the content.php file under the theme’s \framework\functions\frontend folder.

Paste the function in your child theme’s functions.php and modify it. If you haven’t setup a child theme yet, please see https://theme.co/apex/forum/t/setup-how-to-setup-child-themes/57

Please note that theme modification or custom development requires WordPress development knowledge and we do not provide the service as part of our product support so I’d recommend that you consult with a third party developer if you have a tight deadline.

Thanks.

How can I recover the category of the post of the portfolio?

Hi Mauro,

Check this guide please:

https://developer.wordpress.org/reference/functions/get_the_terms/

get_the_terms( get_the_ID(), 'portfolio-category' );

Hope this helps.

In case someone needs it this works well as long as a portfolio item is not in two categories …

The question is: can you know from which portfolio page you are calling?

For example: Cat1, Cat2 and item porfolio Item1

If from the portfolio page that groups all the items from cat1 we call the item1 that is in two categories, I can know that I come from Cat1?

function x_entry_navigation() {

$stack = x_get_stack();
$entry_id = get_the_ID();

if ( $stack == 'ethos' ) {
	$left_icon  = '<i class="x-icon-chevron-left" data-x-icon-s="&#xf053;"></i>';
	$right_icon = '<i class="x-icon-chevron-right" data-x-icon-s="&#xf054;"></i>';
} else {
	$left_icon  = '<i class="x-icon-arrow-left" data-x-icon-s="&#xf060;"></i>';
	$right_icon = '<i class="x-icon-arrow-right" data-x-icon-s="&#xf061;"></i>';
}

/* Terms */
$terms = get_the_terms( get_the_ID(), 'portfolio-category' );

/* Slugs */
$slugs = array();
foreach ( $terms as $term ) {
    $slugs[] = $term->slug;
}

$wp_query = new WP_Query( array(
	'post_type' => 'x-portfolio',
	'posts_per_page' => -1,
	'tax_query' => array(
    	array (
        	'taxonomy' => 'portfolio-category',
        	'field' => 'slug',
    	    'terms' => $slugs,
    	)
	),
) );

/* Save ID's same slugs */
$ids = array();
while ( $wp_query->have_posts() ) {
	$wp_query->the_post();
	$ids[] = get_the_ID();
}
wp_reset_postdata();

$thisindex = array_search( $entry_id, $ids );
$prev_post    = isset( $ids[ $thisindex - 1 ] ) ? $ids[ $thisindex - 1 ] : 0;
$next_post    = isset( $ids[ $thisindex + 1 ] ) ? $ids[ $thisindex + 1 ] : 0;

$is_ltr    = ! is_rtl();
//$prev_post = get_adjacent_post( false, '', false );
//$next_post = get_adjacent_post( false, '', true );
$prev_icon = ( $is_ltr ) ? $left_icon : $right_icon;
$next_icon = ( $is_ltr ) ? $right_icon : $left_icon;

?>

<div class="x-nav-articles">
	<?php if ( $next_post ) : ?>
		<a href="<?php echo get_permalink( $prev_post ); ?>" title="<?php __( 'Previous Post', '__x__' ); ?>" class="prev">
			<?php echo $prev_icon; ?>
		</a>
	<?php endif; ?>

	<?php if ( $next_post ) : ?>
		<a href="<?php echo get_permalink( $next_post ); ?>" title="<?php __( 'Next Post', '__x__' ); ?>" class="next">
			<?php echo $next_icon; ?>
		</a>
	<?php endif; ?>

</div>
<?php } ?>

Glad you’ve sorted it out.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.