Tagged: 

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #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 like

    Thing 1
    – Sub Thing A
    – Sub Thing B
    Thing 2
    – Sub Thing A
    – Sub Thing B

    Will 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.

    #920844

    Hey 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ünter

    #920845

    Thank you for the response Günter.
    I look forward hearing how best to filter the results.
    All the best!

    #921385

    Hi!

    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,
    Ismael

    #921393

    Very elegant, thank you.
    Will the avf_dropdown_post_query filter be added to the next release?

    #921785

    Hi,

    That is a function Ismael has made that for you.

    Best regards,
    Basilis

    #921859

    As 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.

    #922061

    Hi,

    Our developers created a better function that will probably be included in the latest version of the theme. For now, please use the modification above.

    Best regards,
    Ismael

Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.