Subfolder for template-files

This topic contains 3 replies, has 2 voices, and was last updated by  Stephen Harris 9 years, 4 months ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #19592

    Hi Stephen,
    is there a way to put the event-organiser template files in a subfolder? At the moment, they are making a bit of a mess in my theme-folder. It would be great to put them in a subfolder called ‘event-organiser’.

    Thanks for your help!
    Best regards
    Martin

    • This topic was modified 9 years, 4 months ago by  Martin Schuff.
    • This topic was modified 9 years, 4 months ago by  Martin Schuff.
    Martin Schuff
    #19595

    Yes you can register additional template locations:

    function mytheme_register_subfolder_for_stack( $stack ){
    
        $template_dir = get_stylesheet_directory(); //child theme
        $parent_template_dir = get_template_directory(); //parent theme 
    
        //prepend /event-organiser subdirectory of child & parent theme
        //The locations get checked in order.
        array_unshift( 
            $stack, 
            $template_dir . "/event-organiser", 
            $parent_template_dir . "/event-organiser" 
       );
    
        return $stack;
    }
    add_filter( 'eventorganiser_template_stack', 'mytheme_register_subfolder_for_stack' );
    

    The above puts the /event-organiser subdirectory of the child and parent theme (even if there is no child theme you can keep that there) at the beginning of the template stack – so the plug-in will look for the template file there first.

    You can also remove locations in the unlikely event that there are naming conflicts.

    Stephen Harris
    #19599

    Thanks Stephen! It works fine! Only single-event.php has to stay in the root of the theme. But I guess that’s wordpress specific.

    • This reply was modified 9 years, 4 months ago by  Martin Schuff.
    Martin Schuff
    #19604

    That’s true, the single-event.php is handled differently because if it’s not present in the theme it reverts to single.php.

    Stephen Harris
Viewing 4 posts - 1 through 4 (of 4 total)
To enable me to focus on Pro customers, only users who have a valid license for the Pro add-on may post new topics or replies in this forum. If you have a valid license, please log-in or register an account using the e-mail address you purchased the license with. If you don't you can purchase one here. Or there's always the WordPress repository forum.