Tagged: logo element, order, partner element, random
-
AuthorPosts
-
December 8, 2014 at 12:36 pm #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
December 8, 2014 at 2:20 pm #364614Hey 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ünterDecember 8, 2014 at 2:58 pm #364634Hi 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
SiracherDecember 8, 2014 at 3:20 pm #364651Hi!
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ünterDecember 8, 2014 at 4:20 pm #364698Hi 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
December 8, 2014 at 4:37 pm #364717Hey!
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ünterDecember 8, 2014 at 5:01 pm #364745again I have now just a blank spot where the element should appear.
Can you confirm it works on your end?
thanks
December 9, 2014 at 4:10 am #365135Hey!
please try to clear browser page and then refresh your page a few times.
Regards,
AndyDecember 9, 2014 at 9:59 am #365241Hi 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 anymoreif($resort) { $new_slides = array(); foreach($this->slides as $slide) { $new_slides[$slide->ID] = $slide; } }
- This reply was modified 10 years ago by Siracher.
December 9, 2014 at 10:57 am #365254Hey!
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ünterDecember 9, 2014 at 11:56 am #365267hi Günter
ah ok, thanks for the info. I’ll wait then and hope it will be implemented in the next release.
cheers
December 9, 2014 at 12:25 pm #365281 -
AuthorPosts
- The topic ‘Random order for Partner/Logo Element’ is closed to new replies.