This topic has 1 reply, 2 voices, and was last updated 9 years by sharmstr.

  • Author
  • #49153

    Hey team,

    I’d really like to make the portfolio load in random order, most specifically under the ‘ALL’ category. Reason being is that I offer a multitude of services and want to show that diversity. Unfortunately after setting up the items in my portfolio, everything is displayed in bulk with the most recent upload appearing first and so on. So each service type is bulked together (Logos, Web Design, Video, etc) and will become scattered as I add new (and random) portfolio items.

    Long story short, how do I arrange portfolio post order in random?

    Thanks in advance!

    #49190
     sharmstr
    Moderator

    You’ll have to edit the portfolio loop query to specify the rand parameter. Put this in your child theme

    COPY CODE
    
    function kleo_portfolio_items( $display_type = 'default', $title_style = 'normal', $columns = 4, $item_count = NULL, $pagination = "no", $filter = 'yes', $excerpt = 'yes', $img_width = '', $img_height = '', $category = '', $exclude_categories = array() ) {
    
            /* OUTPUT VARIABLE
            ================================================== */
            $portfolio_items_output = "";
            $count = 0;
    
            /* CATEGORY SLUG
            ================================================== */
            if ($category == "All" || $category == "all") {
                $category = '';
            }
            $category_slug = str_replace('_', '-', $category);
    
    
            /* PORTFOLIO QUERY
            ================================================== */
            global $post, $wp_query;
    
            if ( get_query_var('paged') ) {
                $paged = get_query_var('paged');
            } elseif ( get_query_var('page') ) {
                $paged = get_query_var('page');
            } else {
                $paged = 1;
            }
    
            if ( $exclude_categories == '' ) {
                $exclude_categories = array();;
            }
            $portfolio_args = array(
                'post_type' => 'portfolio',
                'post_status' => 'publish',
                'paged' => $paged,
                apply_filters( 'kleo_portfolio_cat_slug', 'portfolio-category' ) => $category_slug,
                'posts_per_page' => $item_count,
                'tax_query' => array(
                        array(
                            'taxonomy' => apply_filters( 'kleo_portfolio_cat_slug', 'portfolio-category' ),
                            'field' => 'id',
                            'terms' => $exclude_categories,
                            'operator' => 'NOT IN'
                        )
                    ),
               'orderby' => 'rand'    
            );
    
            $portfolio_items = new WP_Query( $portfolio_args );
    
    
            /* Class config
            ================================================== */
            $classes = '';
    
            $classes .= ' ' . $display_type . '-style';
    
            if ( $display_type == 'overlay' ) {
                if ( $title_style == 'hover' ) {
                    $classes .= ' anim-title';
                }
            }
    
            if ( $excerpt == 'no' ) {
                $classes .= ' hide-excerpt';
            }
    
            $classes .= ' per-row-' . $columns;
    
            /* IMAGE SIZE
             * Set global variables to be availabe in the portfolio template part
            ================================================== */
            if ( $img_width != "" && $img_height != '' ) {
                global $portfolio_img_width, $portfolio_img_height;
                $portfolio_img_width = $img_width;
                $portfolio_img_height = $img_height;
            }
    
            /* ITEMS OUTPUT
            ================================================== */
    
            if ( $filter == 'yes' ) {
                $portfolio_items_output = kleo_portfolio_filter( $category, $exclude_categories );
            }
    
            $portfolio_items_output .= '<ul class="portfolio-items responsive-cols kleo-masonry ' . $classes . '">'. "\n";
    
            while ( $portfolio_items->have_posts() ) : $portfolio_items->the_post();
    
                ob_start();
                get_template_part( 'page-parts/portfolio-masonry');
                $portfolio_items_output .= ob_get_clean();
    
                $count++;
    
            endwhile;
    
            wp_reset_postdata();
    
            $portfolio_items_output .= '</ul>'. "\n";
    
    
            /* PAGINATION OUTPUT
            ================================================== */
            if ($pagination == "yes") {
                $portfolio_items_output .= '<div class="pagination-wrap">';
                $portfolio_items_output .= kleo_pagination( $portfolio_items->max_num_pages, false);
                $portfolio_items_output .= '</div>';
            }
    
    
            /* FUNCTION OUTPUT
            ================================================== */
            return $portfolio_items_output;
        }
    
    
    

    Now, keep in mind that the function you’re copying is the heart and soul of portfolios and will probably be updated in future releases of Kleo. So make sure you always compare the newest function with the one in your child theme so that you get the latest changes. The only thing I added was ‘orderby’ => ‘rand’.

    Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solution

    This support site is not about custom work. If you need custom development please contact cornel@seventhqueen.com

Viewing 2 posts - 1 through 2 (of 2 total)

The forum ‘KLEO’ is closed to new topics and replies.

Log in with your credentials

Forgot your details?