Tagged: indentation
-
AuthorPosts
-
March 2, 2018 at 1:07 pm #920306
On content elements such as Icon Box where a specific page can be selected, all pages are listed alphabetically.
While this might be fine smaller sites, larger sites that have a structure likeThing 1
– Sub Thing A
– Sub Thing B
Thing 2
– Sub Thing A
– Sub Thing BWill display the Select list like:
- Thing 1
- Thing 2
- Sub Thing A
- Sub Thing A
- Sub Thing B
- Sub Thing B
This makes it a pain to know exactly which page we are linking to.
To fix this, we have modified the subtype loop in html-helper.class.php found under:
config-templatebuilder/avia-template-builder/php/html-helper.class.php
near line 1249 from this:else if(!is_array($element['subtype'])) { $id = $entry->ID; $title = $entry->post_title; }
To this:
else if(!is_array($element['subtype'])) { $id = $entry->ID; $parent_str = ''; $parents = array_reverse( get_post_ancestors( $id ) ); foreach($parents as $parent_id){ $parent = get_post( $parent_id ); $parent_str .= $parent->post_name.' - '; } $title = $parent_str.$entry->post_title; }
Would be very interested in smarter way to make this modification than overriding the parent theme.
March 3, 2018 at 5:01 pm #920844Hey Switzer,
Thank you for using our theme.
This is a good suggestion to display the hierarchical structure of posts and pages in the select box.
One way would be that we add a filter so you can change the output.
I will check, if it is possible to integrate this in core.As soon as we have a solution I will let you know.
Best regards,
GünterMarch 3, 2018 at 5:03 pm #920845Thank you for the response Günter.
I look forward hearing how best to filter the results.
All the best!March 5, 2018 at 10:43 am #921385Hi!
Please edit the same file then go to line 1117.
$prepare_sql = "SELECT distinct ID, post_title FROM {$table_name} WHERE post_status = 'publish' AND post_type = '".$element['subtype']."' ORDER BY post_title ASC LIMIT {$limit}"; $prepare_sql = apply_filters('avf_dropdown_post_query', $prepare_sql, $table_name, $limit, $element); $entries = $wpdb->get_results($prepare_sql);
Add a new filter called “avf_sql_query_function”.
$prepare_sql = "SELECT distinct ID, post_title FROM {$table_name} WHERE post_status = 'publish' AND post_type = '".$element['subtype']."' ORDER BY post_title ASC LIMIT {$limit}"; $prepare_sql = apply_filters('avf_dropdown_post_query', $prepare_sql, $table_name, $limit, $element); $sql_function = apply_filters('avf_sql_query_function', 'sql_query', $prepare_sql, $table_name, $limit, $element); $entries = $sql_function == 'sql_query' ? $wpdb->get_results($prepare_sql) : $sql_function($prepare_sql, $table_name, $limit, $element);
In the functions.php file, you can use this filter.
add_filter('avf_sql_query_function', 'avf_sql_query_function_mod', 10, 5); function avf_sql_query_function_mod($function_name, $prepare_sql, $table_name, $limit, $element) { if($element['subtype'] == 'page') { $function_name = 'avia_get_pages_query'; } return $function_name; } function avia_get_pages_query($prepare_sql, $table_name, $limit, $element) { $args = array('depth'=> 3,'title_li'=>'', 'echo'=>false, 'sort_column'=>'menu_order, post_title'); $posts = get_pages($args); return $posts; }
Regards,
IsmaelMarch 5, 2018 at 10:53 am #921393Very elegant, thank you.
Will the avf_dropdown_post_query filter be added to the next release?March 5, 2018 at 9:04 pm #921785Hi,
That is a function Ismael has made that for you.
Best regards,
BasilisMarch 5, 2018 at 10:16 pm #921859As I understand it it’s two things.
1. A filter so that we can all hook into it with our own functions
2. A function that Ismael has made for me (thank you again)By asking if the avf_dropdown_post_query filter be added to the next release, I mean just that… will this filter be part of the next release of Enfold, or will we need to modify the core file:
config-templatebuilder/avia-template-builder/php/html-helper.class.php
each time, defeating the purpose of this thread.March 6, 2018 at 6:21 am #922061 -
AuthorPosts
- You must be logged in to reply to this topic.