Ejemplo n.º 1
0
 /**
  * Use correct template when filtering a post type archive
  * @param  string $template Template path
  * @return string           Template path
  */
 public function enablePostTypeArchiveSearch($template)
 {
     $template = \Municipio\Helper\Template::locateTemplate($template);
     if (is_post_type_archive() && is_search()) {
         $archiveTemplate = \Municipio\Helper\Template::locateTemplate('archive-' . get_post_type() . '.blade.php');
         if (!$archiveTemplate) {
             $archiveTemplate = \Municipio\Helper\Template::locateTemplate('archive.blade.php');
         }
         $template = $archiveTemplate;
     }
     return $template;
 }
Ejemplo n.º 2
0
 public function addTemplateFilters()
 {
     $types = array('index' => 'index.blade.php', 'home' => 'home.blade.php', 'single' => 'single.blade.php', 'page' => 'page.blade.php', '404' => '404.blade.php', 'archive' => 'archive.blade.php', 'author' => 'author.blade.php', 'category' => 'category.blade.php', 'tag' => 'tag.blade.php', 'taxonomy' => 'taxonomy.blade.php', 'date' => 'date.blade.php', 'front-page' => 'front-page.blade.php', 'paged' => 'paged.blade.php', 'search' => 'search.blade.php', 'single' => 'single.blade.php', 'singular' => 'singular.blade.php', 'attachment' => 'attachment.blade.php');
     $types = apply_filters('Municipio/blade/template_types', $types);
     if (isset($types) && !empty($types) && is_array($types)) {
         foreach ($types as $key => $type) {
             add_filter($key . '_template', function ($original) use($key, $type, $types) {
                 if (empty($original) && is_front_page()) {
                     $type = $types['front-page'];
                 }
                 $templatePath = \Municipio\Helper\Template::locateTemplate($type);
                 // Look for post type archive
                 global $wp_query;
                 if (is_post_type_archive() && isset($wp_query->query['post_type'])) {
                     $search = 'archive-' . $wp_query->query['post_type'] . '.blade.php';
                     $found = \Municipio\Helper\Template::locateTemplate($search);
                     if ($found) {
                         $templatePath = $found;
                     }
                 }
                 // Look for post type single page
                 if (is_single() && isset($wp_query->query['post_type'])) {
                     $search = 'single-' . $wp_query->query['post_type'] . '.blade.php';
                     $found = \Municipio\Helper\Template::locateTemplate($search);
                     if ($found) {
                         $templatePath = $found;
                     }
                 }
                 if ($templatePath) {
                     return $templatePath;
                 }
                 return $original;
             });
         }
     }
 }