Пример #1
0
 /**
  * Get the fields for this page type by merging the default template fields
  * with page specific ones
  * @return array The array of fields
  */
 public function getFields()
 {
     // First figure out what template we're on to get the correct fields
     // If this is the user facing page, then _wp_page_template will be populated
     // and that can be used as the template.
     //
     // If this is the admin facing page, then loadPost() is run to figure out
     // the page ID and the template is determined that way
     if (!empty($this->_wp_page_template)) {
         $template = $this->_wp_page_template;
     } else {
         if (!$this->loadPost() || !Obj::iterable($this->loaded_post)) {
             return [];
         }
         $template = get_page_template_slug($this->loaded_post->ID);
         $this->_wp_page_template = $template;
     }
     $fields_by_template = [];
     if (!empty($template)) {
         $fields_by_template = $this->getFieldsByPageTemplate($template);
     }
     return array_merge($this->getDefaultFields(), $fields_by_template);
 }
Пример #2
0
 /**
  * Get list of links of available taxonomy terms
  * @param string $taxonomy
  * @param string $current_class
  * @param string $link_prefix
  * @param obj $current_term
  * @param obj $current_post
  * @return string HTML
  */
 public static function getTermsNav($taxonomy = 'category', $current_class = 'current-term', $link_prefix = null, $current_term = null, $current_post = null)
 {
     $terms = \Taco\Term\Factory::createMultiple(get_terms($taxonomy));
     if (!Arr::iterable($terms)) {
         return null;
     }
     if (!Obj::iterable($current_term)) {
         $current_term = \Taco\Term\Factory::create(get_queried_object());
     }
     $term_links = array();
     $current_class = ' class="' . $current_class . '"';
     if (is_null($link_prefix)) {
         $link_prefix = '/' . $taxonomy . '/';
     }
     foreach ($terms as $term) {
         $term_class = null;
         if (Obj::iterable($current_term)) {
             // We are on a taxonomy/category template
             if ((int) $current_term->term_id === (int) $term->term_id) {
                 $term_class = $current_class;
             }
         } else {
             // We are on a single page/post
             if (!Obj::iterable($current_post)) {
                 global $post;
                 $current_post = \Taco\Post\Factory::create($post);
             }
             $current_post_term = reset($current_post->getTerms($taxonomy));
             if ((int) $current_post_term->term_id === (int) $term->term_id) {
                 $term_class = $current_class;
             }
         }
         $term_links[] = sprintf('<li%s><a href="%s%s/">%s</a></li>', $term_class, $link_prefix, $term->slug, $term->name);
     }
     return sprintf('<ul>
     %s
   </ul>', join('', $term_links));
 }