• Resolved Iurie Malai

    (@flegmatiq)


    Greg, I have customized the Twenty Seventeen content.php template to display both posts and adverts in the same manner on the home page. Now I want to use this template with the [adverts_list] shortcode, from the same location (/wp-content/themes/twentyseventeen-child/template-parts/post), instead of list-item.php. I checked the documentation, but I am unable to solve this, so temporary I just renamed the content.php to list-item.php and copied it to the plugin template directory. Can you suggest how to solve this in a correct way?

    Regards,
    Iurie

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Greg Winiarski

    (@gwin)

    The correct way to do that would be to add following code in your (child) theme functions.php file

    
    add_action("adverts_template_load", "custom_list_template");
    function custom_list_template( $tpl ) {
        // $tpl is an absolute path to a file, for example
        // /home/simpliko/public_html/wp-content/plugins/wpadverts/templates/list.php
        
        $basename = basename( $tpl );
        // $basename is just a filename for example list.php
         
         if( $basename == "list-item.php" ) {
            // return path to list.php file in custom-list-template directory
            return dirname( __FILE__ ) . "/list-item.php";
         } else {
            return $tpl;
         }
    }
    

    and place your custom list-item.php file in wp-content/themes/twentyseventeen-child/ folder.

    Thread Starter Iurie Malai

    (@flegmatiq)

    Thank you very much, Greg!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘A child theme template instead of list-item.php’ is closed to new replies.