Multiple portfolio layout

I have multiple pages with portfolio layout, and I’d like to have all of them on a single page (i.e multiple categories) - but I’d like to split them into groups - i.e with a heading above each group.

I’ve tried the Grid, and Essential Grid as well as recent_posts shortcut (with type=“portfolio” but the formatting I’d like the same as the pages.

Is there a way to do this?

Hi @ashleybassett,

Thanks for writing in.

What do you mean by on a single page? One portfolio index is only applicable to a single group of items. If you wish to have multiple listings of different groups in a single page then you’ll have to customize the portfolio templates, and with that, you’ll have to create multiple WP_Query and templates. Unfortunately, that’s something we can’t cover here in the forum.

OR, are you referring to have one single home page for all portfolio pages (not items)? You could do that by creating a page with static content created by the builder. Or using Essential Grid and selectively choose the pages with portfolio template.

Thanks!

Thanks for writing back.

I think it’s the former. Can you point me in the right direction? I’ve had a look around for some code that might help, but wonder if there is anything specific to Themeco Pro terminology / references etc.

I saw a good example of WP_query and looping, that will add the Category name as a heading and then list the portfolio items in the category - then looping for each category (the code used different taxonomies and belonged to a different theme.)

Any guidance would be valuable and helpful.

Thanks

Ashley

Hello Ashley,

You can start modifying doing the following steps assuming that you have your child theme active and ready:

  • Using Notepad or TextEdit or Sublime Text or any text editor, please create a new file in your local machine.
  • Insert the following code into that new file
<?php

// =============================================================================
// VIEWS/GLOBAL/_PORTFOLIO.PHP
// -----------------------------------------------------------------------------
// Includes the portfolio output.
// =============================================================================

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

global $sitepress;

if ( function_exists( 'icl_object_id' ) && is_callable( array( $sitepress, 'get_current_language' ) ) ) {
	$wpml_post = get_post( icl_object_id( $entry_id, 'page', false, $sitepress->get_current_language() ) );
	$entry_id  = $wpml_post->ID;
}

$paged   = ( is_front_page() ) ? get_query_var( 'page' ) : ( ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1 );
$cols    = get_post_meta( $entry_id, '_x_portfolio_columns', true );
$count   = get_post_meta( $entry_id, '_x_portfolio_posts_per_page', true );
$filters = get_post_meta( $entry_id, '_x_portfolio_category_filters', true );

switch ( $cols ) {
  case 'One'   : $cols = 1; break;
  case 'Two'   : $cols = 2; break;
  case 'Three' : $cols = 3; break;
  case 'Four'  : $cols = 4; break;
}

?>

<?php x_get_view( 'global', '_script', 'isotope-portfolio' ); ?>

<div id="x-iso-container" class="x-iso-container x-iso-container-portfolio cols-<?php echo $cols; ?>">

  <?php

  if ( count( $filters ) == 1 && in_array( 'All Categories', $filters ) ) {

    $args = array(
      'post_type'      => 'x-portfolio',
      'posts_per_page' => $count,
      'paged'          => $paged
    );

  } else {

    $args = array(
      'post_type'      => 'x-portfolio',
      'posts_per_page' => $count,
      'paged'          => $paged,
      'tax_query'      => array(
        array(
          'taxonomy' => 'portfolio-category',
          'field'    => 'term_id',
          'terms'    => $filters
        )
      )
    );

  }

  $wp_query = new WP_Query( $args );

  ?>

  <?php if ( $wp_query->have_posts() ) : ?>
    <?php while ( $wp_query->have_posts() ) : $wp_query->the_post(); ?>
      <?php if ( $stack != 'ethos' ) : ?>
        <?php x_get_view( $stack, 'content', 'portfolio' ); ?>
      <?php else : ?>
        <?php x_ethos_entry_cover( 'main-content' ); ?>
      <?php endif; ?>
    <?php endwhile; ?>
  <?php endif; ?>

</div>

<?php pagenavi(); ?>
<?php wp_reset_query(); ?>

Of course you will have to modify this file and include your custom wp_query to display the group portfolio items.

  • Save the file named as _portfolio.php
  • Upload this file to your server in the child theme’s folder wp-content/themes/x-child/framework/views/global/

Keep in mind that this is just merely a guide to get you started with your modifications. Any modifications you may have added from then on is beyond the scope of our support.

Thanks for your understanding.

Thanks for this - will give it a whirl! Appreciate it!

Ashley

You are most welcome!

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