예제 #1
0
 /**
  * Build a sub-sitemap for a specific taxonomy -- example.com/tax-sitemap.xml
  *
  * @param string $taxonomy Registered taxonomy's slug
  */
 function build_tax_map($taxonomy)
 {
     $options = get_mervin_options();
     if (isset($options['taxonomies-' . $taxonomy->name . '-not_in_sitemap']) && $options['taxonomies-' . $taxonomy->name . '-not_in_sitemap'] || in_array($taxonomy, array('link_category', 'nav_menu', 'post_format'))) {
         $this->bad_sitemap = true;
         return;
     }
     $terms = get_terms($taxonomy->name, array('hide_empty' => true));
     global $wpdb;
     $output = '';
     foreach ($terms as $c) {
         $url = array();
         if (zeo_get_term_meta($c, $c->taxonomy, 'noindex') && zeo_get_term_meta($c, $c->taxonomy, 'sitemap_include') != 'always') {
             continue;
         }
         if (zeo_get_term_meta($c, $c->taxonomy, 'sitemap_include') == 'never') {
             continue;
         }
         $url['loc'] = zeo_get_term_meta($c, $c->taxonomy, 'canonical');
         if (!$url['loc']) {
             $url['loc'] = get_term_link($c, $c->taxonomy);
             if (isset($options['trailingslash']) && $options['trailingslash']) {
                 $url['loc'] = trailingslashit($url['loc']);
             }
         }
         if ($c->count > 10) {
             $url['pri'] = 0.6;
         } else {
             if ($c->count > 3) {
                 $url['pri'] = 0.4;
             } else {
                 $url['pri'] = 0.2;
             }
         }
         // Grab last modified date
         $sql = "SELECT MAX(p.post_date) AS lastmod\n\t\t\t\t\tFROM\t{$wpdb->posts} AS p\n\t\t\t\t\tINNER JOIN {$wpdb->term_relationships} AS term_rel\n\t\t\t\t\tON\t\tterm_rel.object_id = p.ID\n\t\t\t\t\tINNER JOIN {$wpdb->term_taxonomy} AS term_tax\n\t\t\t\t\tON\t\tterm_tax.term_taxonomy_id = term_rel.term_taxonomy_id\n\t\t\t\t\tAND\t\tterm_tax.taxonomy = '{$c->taxonomy}'\n\t\t\t\t\tAND\t\tterm_tax.term_id = {$c->term_id}\n\t\t\t\t\tWHERE\tp.post_status = 'publish'\n\t\t\t\t\tAND\t\tp.post_password = ''";
         $url['mod'] = $wpdb->get_var($sql);
         $url['chf'] = 'weekly';
         $output .= $this->sitemap_url($url);
     }
     if (empty($output)) {
         $this->bad_sitemap = true;
         return;
     }
     $this->sitemap = '<urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ';
     $this->sitemap .= 'xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd" ';
     $this->sitemap .= 'xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' . "\n";
     $this->sitemap .= $output . '</urlset>';
 }
예제 #2
0
 function breadcrumb($prefix = '', $suffix = '', $display = true)
 {
     $options = get_mervin_options();
     global $wp_query, $post, $paged;
     $opt = get_option("mervin_breadcrumbs");
     $on_front = get_option('show_on_front');
     $blog_page = get_option('page_for_posts');
     $sep = isset($opt['breadcrumbs-sep']) && $opt['breadcrumbs-sep'] != '' ? $opt['breadcrumbs-sep'] : '&raquo;';
     $home = isset($opt['breadcrumbs-home']) && $opt['breadcrumbs-home'] != '' ? $opt['breadcrumbs-home'] : __('Home');
     $selmenu = isset($opt['breadcrumbs-selectedmenu']) && $opt['breadcrumbs-selectedmenu'] != '' ? $opt['breadcrumbs-selectedmenu'] : 0;
     if ("page" == $on_front && 'post' == get_post_type()) {
         $homelink = '<a href="' . get_permalink(get_option('page_on_front')) . '">' . $home . '</a>';
         $bloglink = $homelink;
         if ($blog_page && (!isset($opt['breadcrumbs-blog-remove']) || !$opt['breadcrumbs-blog-remove'])) {
             $bloglink = $homelink . ' ' . $sep . ' <a href="' . get_permalink($blog_page) . '">' . $this->get_bc_title($blog_page) . '</a>';
         }
     } else {
         $homelink = '<a href="' . get_bloginfo('url') . '">' . $home . '</a>';
         $bloglink = $homelink;
     }
     if ($on_front == "page" && is_front_page() || $on_front == "posts" && is_home()) {
         $output = $this->bold_or_not($home);
     } else {
         if ($on_front == "page" && is_home()) {
             $output = $homelink . ' ' . $sep . ' ' . $this->bold_or_not($this->get_bc_title($blog_page));
         } else {
             if (is_singular()) {
                 $output = $bloglink . ' ' . $sep . ' ';
                 if (isset($opt['breadcrumbs-menus']) && ($opt['breadcrumbs-menus'] = 'on')) {
                     $use_menu = $this->in_menu($selmenu);
                 }
                 if (function_exists('bbp_body_class') && count(bbp_body_class(array())) > 1) {
                     remove_filter('bbp_get_breadcrumb', '__return_false');
                     $output .= bbp_get_breadcrumb(' ' . $sep . ' ');
                     add_filter('bbp_get_breadcrumb', '__return_false');
                 } else {
                     if (isset($use_menu) && $use_menu) {
                         $trail = $this->get_menu_trail();
                         $trail = array_reverse($trail);
                         $trailposts = array();
                         for ($t = 0; $t < count($trail); $t++) {
                             $trailposts[] = $this->get_post_for_menunode($trail[$t]);
                         }
                         for ($t = 0; $t < count($trail); $t++) {
                             $bctitle = get_the_title($trail[$t]) == '' ? get_the_title($trailposts[$t]) : get_the_title($trail[$t]);
                             $output .= '<a href="' . get_permalink($trailposts[$t]) . '">' . $bctitle . '</a> ' . $sep . ' ';
                         }
                         $output .= $this->bold_or_not($this->get_bc_title($post->ID));
                     } else {
                         $post_type = get_post_type();
                         if (function_exists('get_post_type_archive_link') && get_post_type_archive_link($post_type)) {
                             if (isset($options['bctitle-ptarchive-' . $post_type]) && '' != $options['bctitle-ptarchive-' . $post_type]) {
                                 $archive_title = $options['bctitle-ptarchive-' . $post_type];
                             } else {
                                 $post_type_obj = get_post_type_object($post_type);
                                 $archive_title = $post_type_obj->labels->menu_name;
                             }
                             $output .= '<a href="' . get_post_type_archive_link($post_type) . '">' . $archive_title . '</a> ' . $sep . ' ';
                         }
                         if (0 == $post->post_parent) {
                             if (isset($opt['post_types-' . $post->post_type . '-maintax']) && $opt['post_types-' . $post->post_type . '-maintax'] != '0') {
                                 $main_tax = $opt['post_types-' . $post->post_type . '-maintax'];
                                 $terms = wp_get_object_terms($post->ID, $main_tax);
                                 if (is_taxonomy_hierarchical($main_tax) && $terms[0]->parent != 0) {
                                     $parents = $this->get_term_parents($terms[0], $main_tax);
                                     $parents = array_reverse($parents);
                                     foreach ($parents as $parent) {
                                         $bctitle = zeo_get_term_meta($parent, $main_tax, 'bctitle');
                                         if (!$bctitle) {
                                             $bctitle = $parent->name;
                                         }
                                         $output .= '<a href="' . get_term_link($parent, $main_tax) . '">' . $bctitle . '</a> ' . $sep . ' ';
                                     }
                                 }
                                 if (count($terms) > 0) {
                                     $bctitle = zeo_get_term_meta($terms[0], $main_tax, 'bctitle');
                                     if (!$bctitle) {
                                         $bctitle = $terms[0]->name;
                                     }
                                     $output .= '<a href="' . get_term_link($terms[0], $main_tax) . '">' . $bctitle . '</a> ' . $sep . ' ';
                                 }
                             }
                             $output .= $this->bold_or_not($this->get_bc_title($post->ID));
                         } else {
                             if (isset($post->ancestors)) {
                                 if (is_array($post->ancestors)) {
                                     $ancestors = array_values($post->ancestors);
                                 } else {
                                     $ancestors = array($post->ancestors);
                                 }
                             } else {
                                 $ancestors = array($post->post_parent);
                             }
                             // Reverse the order so it's oldest to newest
                             $ancestors = array_reverse($ancestors);
                             foreach ($ancestors as $ancestor) {
                                 $output .= '<a href="' . get_permalink($ancestor) . '">' . $this->get_bc_title($ancestor) . '</a> ' . $sep . ' ';
                             }
                             $output .= $this->bold_or_not($this->get_bc_title($post->ID));
                         }
                     }
                 }
             } else {
                 if (!is_404()) {
                     $output = $bloglink . ' ' . $sep . ' ';
                 } else {
                     $output = $homelink . ' ' . $sep . ' ';
                 }
                 // echo '<pre>'.print_r($wp_query,1).'</pre>';
                 if (function_exists('is_post_type_archive') && is_post_type_archive()) {
                     $post_type = get_post_type();
                     if (isset($options['bctitle-ptarchive-' . $post_type]) && '' != $options['bctitle-ptarchive-' . $post_type]) {
                         $archive_title = $options['bctitle-ptarchive-' . $post_type];
                     } else {
                         $post_type_obj = get_post_type_object($post_type);
                         $archive_title = $post_type_obj->labels->menu_name;
                     }
                     $output .= $this->bold_or_not($archive_title);
                 } else {
                     if (is_tax() || is_tag() || is_category()) {
                         $term = $wp_query->get_queried_object();
                         if (isset($options['taxonomy-' . $term->taxonomy . '-ptparent']) && $options['taxonomy-' . $term->taxonomy . '-ptparent'] != '') {
                             $post_type = $options['taxonomy-' . $term->taxonomy . '-ptparent'];
                             if ('post' == $post_type && get_option('show_on_front') == 'page') {
                                 $posts_page = get_option('page_for_posts');
                                 if ($posts_page) {
                                     $output .= '<a href="' . get_permalink($posts_page) . '">' . $this->get_bc_title($posts_page) . '</a> ' . $sep . ' ';
                                 }
                             } else {
                                 if (isset($options['bctitle-ptarchive-' . $post_type]) && '' != $options['bctitle-ptarchive-' . $post_type]) {
                                     $archive_title = $options['bctitle-ptarchive-' . $post_type];
                                 } else {
                                     $post_type_obj = get_post_type_object($post_type);
                                     $archive_title = $post_type_obj->labels->menu_name;
                                 }
                                 $output .= '<a href="' . get_post_type_archive_link($post_type) . '">' . $archive_title . '</a> ' . $sep . ' ';
                             }
                         }
                         if (is_taxonomy_hierarchical($term->taxonomy) && $term->parent != 0) {
                             $parents = $this->get_term_parents($term, $term->taxonomy);
                             $parents = array_reverse($parents);
                             foreach ($parents as $parent) {
                                 $bctitle = zeo_get_term_meta($parent, $term->taxonomy, 'bctitle');
                                 if (!$bctitle) {
                                     $bctitle = $parent->name;
                                 }
                                 $output .= '<a href="' . get_term_link($parent, $term->taxonomy) . '">' . $bctitle . '</a> ' . $sep . ' ';
                             }
                         }
                         $bctitle = zeo_get_term_meta($term, $term->taxonomy, 'bctitle');
                         if (!$bctitle) {
                             $bctitle = $term->name;
                         }
                         if ($paged) {
                             $output .= $this->bold_or_not('<a href="' . get_term_link($term, $term->taxonomy) . '">' . $bctitle . '</a>');
                         } else {
                             $output .= $this->bold_or_not($bctitle);
                         }
                     } else {
                         if (is_date()) {
                             if (isset($opt['breadcrumbs-archiveprefix'])) {
                                 $bc = $opt['breadcrumbs-archiveprefix'];
                             } else {
                                 $bc = __('Archives for');
                             }
                             if (is_day()) {
                                 global $wp_locale;
                                 $output .= '<a href="' . get_month_link(get_query_var('year'), get_query_var('monthnum')) . '">' . $wp_locale->get_month(get_query_var('monthnum')) . ' ' . get_query_var('year') . '</a> ' . $sep . ' ';
                                 $output .= $this->bold_or_not($bc . " " . get_the_date());
                             } else {
                                 if (is_month()) {
                                     $output .= $this->bold_or_not($bc . " " . single_month_title(' ', false));
                                 } else {
                                     if (is_year()) {
                                         $output .= $this->bold_or_not($bc . " " . get_query_var('year'));
                                     }
                                 }
                             }
                         } elseif (is_author()) {
                             if (isset($opt['breadcrumbs-archiveprefix'])) {
                                 $bc = $opt['breadcrumbs-archiveprefix'];
                             } else {
                                 $bc = __('Archives for');
                             }
                             $user = $wp_query->get_queried_object();
                             $output .= $this->bold_or_not($bc . " " . $user->display_name);
                         } elseif (is_search()) {
                             if (isset($opt['breadcrumbs-searchprefix']) && $opt['breadcrumbs-searchprefix'] != '') {
                                 $bc = $opt['breadcrumbs-searchprefix'];
                             } else {
                                 $bc = __('You searched for');
                             }
                             $output .= $this->bold_or_not($bc . ' "' . stripslashes(strip_tags(get_search_query())) . '"');
                         } elseif (isset($wp_query->query_vars['bbp_topic_tag'])) {
                             remove_filter('bbp_get_breadcrumb', '__return_false');
                             $output .= bbp_get_breadcrumb(' ' . $sep . ' ');
                             add_filter('bbp_get_breadcrumb', '__return_false');
                         } elseif (is_404()) {
                             if (isset($opt['breadcrumbs-404crumb']) && $opt['breadcrumbs-404crumb'] != '') {
                                 $crumb404 = $opt['breadcrumbs-404crumb'];
                             } else {
                                 $crumb404 = __('Error 404: Page not found');
                             }
                             $output .= $this->bold_or_not($crumb404);
                         }
                     }
                 }
             }
         }
     }
     if (isset($opt['breadcrumbs-prefix']) && $opt['breadcrumbs-prefix'] != "") {
         $output = $opt['breadcrumbs-prefix'] . " " . $output;
     }
     if ($display) {
         echo $prefix . $output . $suffix;
         return true;
     } else {
         return $prefix . $output . $suffix;
     }
 }