Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #364585

    Hi

    i’m using the Partner/Logo element to display and link our sponsors.
    Is it possible to change the order to random each time the page is loaded?
    Otherwise always the same sponsor is first.

    thanks

    #364614

    Hey Siracher!

    Thank you for using our theme.

    Currently it is not possible out of the box. You have to modify the folllowing core file:

    enfold\config-templatebuilder\avia-shortcodes\logoslider.php

    Locate line 350:

    
    $this->slides = get_posts(array(
    				'include' => $ids,
    				'post_status' => 'inherit',
    				'post_type' => 'attachment',
    				'post_mime_type' => 'image',
    				'order' => 'ASC',
    				'orderby' => 'post__in')
    				);
    

    and replace with:

    
    $this->slides = get_posts(array(
    				'include' => $ids,
    				'post_status' => 'inherit',
    				'post_type' => 'attachment',
    				'post_mime_type' => 'image',
    				'order' => 'ASC',
    				'orderby' => 'rand')
    				);
    

    This is a quick fix.

    I post a filter hook to kriesi, maybe in the next releases it will be integrated:

    Replace the code above with:

    
    $args = apply_filters( 'avf_logoslider_select_args', 
    					array(	'include' => $ids,
    							'post_status' => 'inherit',
    							'post_type' => 'attachment',
    							'post_mime_type' => 'image',
    							'order' => 'ASC',
    							'orderby' => 'post__in' )
    					);
    			
    $this->slides = get_posts( $args );
    

    In functions.php of the theme or childtheme put the following:

    
    add_filter('avf_logoslider_select_args', 'my_logoslider_select_args');
    
    function my_logoslider_select_args ($args)
    		{
    			$args['orderby'] = 'rand';
    			return $args;
    		}
    
    

    If this hook is integrated, you just have to make sure, that you put the code in functions.php.

    Regards,
    Günter

    #364634

    Hi Günter

    thanks a lot for the quick response. I tried the quick fix but the logo stay in the same order as they are ordered in the Editor.
    I refreshed a couple of times and checked also in a private session. Did I missed something?

    thanks
    Siracher

    #364651

    Hi!

    Sorry, I missed that a resorting is taking place a couple of lines below.

    Locate the following just below:

    
    //resort slides so the id of each slide matches the post id
    			$new_slides = array();
    			foreach($this->slides as $slide)
    			{
    				$new_slides[$slide->ID] = $slide;
    			}
    

    and replace with:

    
                            $resort = apply_filters( 'avf_logoslider_resort_slides', true);
    			$new_slides = $this->slides;
    
    			//resort slides so the id of each slide matches the post id
    			if($resort)
    			{
    				$new_slides = array();
    				foreach($this->slides as $slide)
    				{
    					$new_slides[$slide->ID] = $slide;
    				}
    			}
    
    

    In functions.php add the following:

    
    add_filter('avf_logoslider_resort_slides', 'my_logoslider_resort');
    function my_logoslider_resort($resort)
    {
          return false;
    }
    

    As a quick fix replace:

    
     $resort = apply_filters( 'avf_logoslider_resort_slides', true);
    

    with

    
     $resort = false;
    

    Regards,
    Günter

    #364698

    Hi Günter

    the element is now just empty. I’m not sure if I messed up now some code with your first answer.
    Are the changes from you first answer still valid or do I have only to follow the instructions in the second answer.

    I tried different ways now but it never worked.

    thanks

    #364717

    Hey!

    I give you the full code for a quick solution:

    Replace the original code

    
    $this->slides = get_posts(array(
    				'include' => $ids,
    				'post_status' => 'inherit',
    				'post_type' => 'attachment',
    				'post_mime_type' => 'image',
    				'order' => 'ASC',
    				'orderby' => 'post__in')
    				);
    
    //resort slides so the id of each slide matches the post id
    			$new_slides = array();
    			foreach($this->slides as $slide)
    			{
    				$new_slides[$slide->ID] = $slide;
    			}
    
    

    with:

    
    $this->slides = get_posts(array(
    				'include' => $ids,
    				'post_status' => 'inherit',
    				'post_type' => 'attachment',
    				'post_mime_type' => 'image',
    				'order' => 'ASC',
    				'orderby' => 'rand')
    				);
    
                            $resort = false;
    			$new_slides = $this->slides;
    
    			//resort slides so the id of each slide matches the post id
    			if($resort)
    			{
    				$new_slides = array();
    				foreach($this->slides as $slide)
    				{
    					$new_slides[$slide->ID] = $slide;
    				}
    			}
    

    Cheers!
    Günter

    #364745

    again I have now just a blank spot where the element should appear.

    Can you confirm it works on your end?

    thanks

    #365135

    Hey!

    please try to clear browser page and then refresh your page a few times.

    Regards,
    Andy

    #365241

    Hi Andy

    did it a couple of times, also with different browsers, same result, just a blank spot.

    I’m not an expert in php. but can it work properli if $resort is set to false? The if statement below will not run then and
    this block seem to be the key that the logos are not displayed anymore

    if($resort)
    			{
    				$new_slides = array();
    				foreach($this->slides as $slide)
    				{
    					$new_slides[$slide->ID] = $slide;
    				}
    			}
    • This reply was modified 10 years ago by Siracher.
    #365254

    Hey!

    Thank you for coming back.

    I’m sorry to tell you that it is not possible to find a quick solution for your request.

    I found out, that it needs a huge modification in the logic of several functions in this file.

    It is possible to implement, but this is customization and bejond the scope of support.

    Regards,
    Günter

    #365267

    hi Günter

    ah ok, thanks for the info. I’ll wait then and hope it will be implemented in the next release.

    cheers

    #365281

    Hi!

    I hope, you enjoy the theme.

    Feel free to come back with further inquiries.

    Regards,
    Günter

Viewing 12 posts - 1 through 12 (of 12 total)
  • The topic ‘Random order for Partner/Logo Element’ is closed to new replies.