Ejemplo n.º 1
0
 /**
  * Add active class to menu of post type single template
  *
  * @param array $css_classes
  *
  * @return array
  */
 public function addActive($css_classes)
 {
     $custom_post_type = PostType::get_custom_post_type();
     if (\is_single() && \is_singular($custom_post_type) || \is_tax()) {
         // check - Post is a Custom Post Type
         $css_classes = \array_filter($css_classes, array($this, 'removeActiveClass'));
         //get all registered custom post type templates
         foreach ($custom_post_type as $post_type) {
             if ($post_type === get_post_type()) {
                 $searching_slug = array();
                 $templates = PostTypeAbstract::getTemplates($post_type);
                 if (!is_null($templates)) {
                     $pages = Page::getPageByTemplate($templates);
                     foreach ($pages as $page) {
                         $slag = sanitize_title($page->post_title);
                         $searching_slug[] = 'menu-' . $slag;
                     }
                     if (array_intersect($searching_slug, $css_classes)) {
                         $css_classes[] = 'active';
                     }
                 }
             }
         }
     }
     return $css_classes;
 }
Ejemplo n.º 2
0
 /**
  * Get page id by template name (include language)
  *
  * @param array|string $template_name
  *
  * @return bool|mixed|null|string
  * @access public
  * @static
  */
 public static function getIdByTemplate($template_name)
 {
     $template_name = is_array($template_name) ? $template_name : array($template_name);
     $page = Page::getPageByTemplate($template_name);
     if (function_exists('icl_object_id')) {
         $page_id = icl_object_id($page[0]->ID, 'page', true, ICL_LANGUAGE_CODE);
     } else {
         $page_id = $page[0]->ID;
     }
     return $page_id;
 }