示例#1
0
 /**
  * Returns HTML fragment containing a section title
  *
  * @param array $args widget args, as passed to WP_Widget::widget
  * @param array $instance widget instance args, as passed to WP_Widget::widget
  * @return string HTML fragment with title
  */
 public function section_title($args, $instance)
 {
     global $post;
     $html = $title = $href = '';
     $section_id = 0;
     // Determine which post to use for the section title
     if ($instance['navigation_style'] != 'site') {
         // Gather ancestors
         $sections = bu_navigation_gather_sections($post->ID, array('post_types' => $post->post_type));
         // Adaptive navigation style uses the grandparent of current post
         if ($instance['navigation_style'] == 'adaptive') {
             $grandparent_offset = count($sections) - 2;
             // If the current page is the last item, go up one further
             if (end($sections) == $post->ID) {
                 $grandparent_offset--;
             }
             if (isset($sections[$grandparent_offset])) {
                 $section_id = $sections[$grandparent_offset];
             }
         } else {
             // Default to top level post (if we have one)
             if (isset($sections[1])) {
                 $section_id = $sections[1];
             }
         }
     }
     // Use section post for title
     if ($section_id) {
         $section = get_post($section_id);
         // Prevent usage of non-published posts as titles
         if ('publish' === $section->post_status) {
             // Second argument prevents usage of default (no title) label
             $title = bu_navigation_get_label($section, '');
             $href = get_permalink($section->ID);
         }
     }
     // Fallback to site title if we're still empty
     if (empty($title)) {
         $title = get_bloginfo('name');
         $href = trailingslashit(get_bloginfo('url'));
     }
     if ($title && $href) {
         $html = sprintf("<a class=\"content_nav_header\" href=\"%s\">%s</a>\n", esc_attr($href), $title);
     }
     return $html;
 }
示例#2
0
文件: post.php 项目: iamapioneer/sdas
 public function get_post_breadcrumbs($post)
 {
     $output = "<ul id=\"bu-post-breadcrumbs\">";
     // Manually fetch ancestors to get around BU WP core mod...
     $ancestors = array($post);
     while ($post->post_parent != 0) {
         $post = get_post($post->post_parent);
         array_push($ancestors, $post);
     }
     // Start from the root
     $ancestors = array_reverse($ancestors);
     // Print markup
     foreach ($ancestors as $ancestor) {
         $label = bu_navigation_get_label($ancestor);
         if ($ancestor != end($ancestors)) {
             $output .= "<li>" . $label . "<ul>";
         } else {
             $output .= "<li class=\"current\">" . $label;
             $output .= str_repeat("</li></ul>", count($ancestors));
         }
     }
     return $output;
 }