function setUp() { parent::setUp(); $this->month_url = get_month_link(date('Y'), date('m')); $this->year_url = get_year_link(date('Y')); $this->post_ids = $this->factory->post->create_many(8, array('post_type' => 'post', 'post_author' => '1')); }
public function test_page_type_notfound() { $this->go_to('?name=' . rand_str()); $this->assertTrue(is_404()); $this->assertSame('notfound', Ad_Layers::instance()->get_current_page_type()); $this->go_to(get_year_link('2025')); $this->assertTrue(is_404()); $this->assertSame('notfound', Ad_Layers::instance()->get_current_page_type()); }
/** * This checks on which page we're and display the correct breancrumb navigation * @return string | void */ public function output_html() { global $post, $cat, $wp_query; $output = ''; $arc_year = get_the_time('Y'); $arc_month = get_the_time('F'); $arc_day = get_the_time('d'); $arc_day_full = get_the_time('l'); $url_year = get_year_link($arc_year); $url_month = get_month_link($arc_year, $arc_month); $templates = array_keys(fw_get_db_ext_settings_option('ns-breadcrumb', 'hide-bdb-templates', array())); $types = array_keys(fw_get_db_ext_settings_option('ns-breadcrumb', 'hide-bdb-types', array())); if (in_array(get_post_type(), $types)) { return; } if (!is_front_page()) { //breadcrumb for single post if (is_single() && !in_array('single', $templates)) { $output = $this->is_single_post(); } elseif (is_category() && !in_array('category', $templates)) { $output = '<li>' . $this->set_opt('category') . get_category_parents($cat, true, ' » ') . '</li>'; } elseif (is_tax() && !in_array('category', $templates)) { $term = $wp_query->queried_object; $output = '<li>' . $this->set_opt('category') . $term->name . '</li>'; } elseif (is_tag() && !in_array('tag', $templates)) { $output = '<li>' . $this->set_opt('tags') . single_tag_title('', false) . '</li>'; } elseif (is_day() && !in_array('archive', $templates)) { $output = '<li><a href="' . $url_year . '">' . $arc_year . '</a></li>'; $output .= '<li><a href="' . $url_month . '">' . $arc_month . '</a></li><li>' . $arc_day . ' (' . $arc_day_full . ')</li>'; } elseif (is_month() && !in_array('archive', $templates)) { $output = '<li><a href="' . $url_year . '">' . $arc_year . '</a></li><li>' . $arc_month . '</li>'; } elseif (is_year() && !in_array('archive', $templates)) { $output = '<li>' . $arc_year . '</li>'; } elseif (is_search() && !in_array('search', $templates)) { $output = '<li>' . $this->set_opt('search') . get_search_query() . '</li>'; } elseif (is_page() && !$post->post_parent && !in_array('page', $templates)) { $output = '<li>' . get_the_title() . '</li>'; } elseif (is_page() && $post->post_parent && !in_array('page', $templates)) { $output = $this->is_page_n_has_parent(); } elseif (is_author() && !in_array('author', $templates)) { global $author; $user_info = get_userdata($author); $output = '<li>' . $this->set_opt('author') . $user_info->display_name . '</li>'; } elseif (is_404() && !in_array('404', $templates)) { $output = '<li>' . $this->set_opt('error') . '</li>'; } else { //All other cases no Breadcrumb trail. } } if (!empty($output)) { $return = '<ul class="breadcrumb">'; $return .= $this->set_opt('el_prefix'); $return .= $output; $return .= '</ul>'; echo $return; } }
/** * Prints the date for a post with the month + date linkable to the moth archive and the year linked to the yearly archive * Date looks like - "September 21, 2014" */ function elder_linkable_date() { global $year, $currentmonth; printf('<a href="%1$s" title="View posts from %2$s %3$s">', get_month_link($year, $currentmonth), get_the_date('F'), get_the_date('Y')); echo get_the_date('F') . ' ' . get_the_date('j'); echo '</a>, '; printf('<a href="%1$s" title="View posts from %2$s">', get_year_link($year), get_the_date('Y')); echo get_the_date('Y'); echo '</a>'; }
function widget($args, $instance) { extract($args); echo $before_widget; $title = apply_filters('widget_title', empty($instance['title']) ? __('Archives', 'better-archives-widget') : $instance['title'], $instance, $this->id_base); if (!empty($title)) { echo $before_title . $title . $after_title; } // years - months global $wpdb; $prevYear = ''; $currentYear = ''; if ($months = $wpdb->get_results("SELECT DISTINCT DATE_FORMAT(post_date, '%b') AS month , MONTH(post_date) as numMonth, YEAR( post_date ) AS year, COUNT( id ) as post_count FROM {$wpdb->posts} WHERE post_status = 'publish' and post_date <= now() and post_type = 'post' GROUP BY month , year ORDER BY post_date DESC")) { echo '<ul>'; foreach ($months as $month) { $currentYear = $month->year; if ($currentYear !== $prevYear && '' !== $prevYear) { echo '</ul></li>'; } if ($currentYear !== $prevYear) { ?> <li class="baw-year"> <a href="<?php echo esc_url(get_year_link($month->year)); ?> "><?php echo esc_html($month->year); ?> </a> <ul class="baw-months"> <?php } ?> <li class="baw-month"> <a href="<?php echo esc_url(get_month_link($month->year, $month->numMonth)); ?> "><?php echo esc_html($month->month . ' ' . $month->year); ?> </a> </li> <?php $prevYear = $month->year; } } ?> </ul></li> <?php echo '</ul>'; echo $after_widget; }
/** * */ public function __construct() { global $post; $this->init_args(); // Don't display on homepage if (is_front_page()) { return; } $this->add_crumb('Home', home_url()); // Blog page if (is_home() || is_singular('post')) { $this->add_crumb('Blog', get_permalink(get_option('page_for_posts'))); } if (is_archive()) { $this->add_post_type_crumb(); } if (is_category()) { $category = current(get_the_category()); $this->add_crumb($category->name, get_category_link($category)); } elseif (is_single()) { $this->add_post_type_crumb(); $this->add_current_crumb(); } elseif (is_page()) { if ($post->post_parent) { $ancestors = get_post_ancestors($post->ID); $ancestors = array_reverse($ancestors); foreach ($ancestors as $ancestor) { $this->add_crumb(get_the_title($ancestor), get_permalink($ancestor)); } } $this->add_current_crumb(); } elseif (is_tag()) { //single_tag_title(); } elseif (is_tax()) { $this->add_crumb(framework_get_queried_object_title()); } elseif (is_day()) { //echo "<li>Archive for "; the_time('F jS, Y'); echo'</li>'; } elseif (is_month()) { $this->add_crumb(get_the_time('Y'), get_year_link(get_the_time('Y'))); $this->add_crumb(get_the_time('F')); } elseif (is_year()) { $this->add_crumb(get_the_time('Y')); } elseif (is_author()) { $this->add_crumb(get_the_author(), false); } elseif (isset($_GET['paged']) && !empty($_GET['paged'])) { //echo "<li>Blog Archives"; echo'</li>'; } elseif (is_search()) { //echo "<li>Search Results"; echo'</li>'; } }
protected function generate_data() { global $wpdb; $requested = $this->requested; if ('monthly' == $requested) { $latest_post_query = ' SELECT YEAR(post_date) as year, MONTH(post_date) as month, MAX(post_modified) as post_modified, MAX(post_modified_gmt) as post_modified_gmt, MAX(comment_count) as comment_count FROM ' . $wpdb->posts . "\n\t\t\t\tWHERE post_status = 'publish'\n\t\t\t\t\tAND post_password = ''\n\t\t\t\t\tAND post_type = 'post'" . ' GROUP BY year, month ORDER BY post_modified DESC'; } else { $latest_post_query = ' SELECT YEAR(post_date) as year, MAX(post_modified) as post_modified, MAX(post_modified_gmt) as post_modified_gmt, MAX(comment_count) as comment_count FROM ' . $wpdb->posts . "\n\t\t\t\tWHERE post_status = 'publish'\n\t\t\t\t\tAND post_password = ''\n\t\t\t\t\tAND post_type <> 'page'" . ' GROUP BY year ORDER BY post_modified DESC'; } $latest_posts = $this->get_results($latest_post_query); if (!isset($latest_posts) || 0 == sizeof($latest_posts)) { return false; } $data = array(); for ($i = 0; $i < sizeof($latest_posts); $i++) { $post = $latest_posts[$i]; $data = $this->init_data($data); if ('monthly' == $requested) { $data['location'] = get_month_link($post->year, $post->month); } else { if ('yearly' == $requested) { $data['location'] = get_year_link($post->year); } } $data['lastmod'] = $this->get_lastmod($post); $data['freq'] = $this->cal_frequency($post); $data['priority'] = $this->cal_priority($post, $data['freq']); $this->data[] = $data; } unset($latest_posts); return true; }
function get_breadcrumbs() { global $wp_query; $breadcrumbs = ""; if (!is_home()) { $breadcrumbs .= '<li><a title="' . get_bloginfo('name') . '" href="' . get_settings('home') . '">' . get_bloginfo('name') . '</a></li>'; if (is_category()) { $catTitle = single_cat_title("", false); $cat = get_cat_ID($catTitle); $breadcrumbs .= "<li>" . get_category_parents($cat, true, "") . "</li>"; } elseif (is_archive() && !is_category()) { $y = get_query_var('year'); $m = get_query_var('monthnum'); if (is_year()) { $breadcrumbs .= "<li>" . $y . "年</li>"; } if (is_month()) { $breadcrumbs .= '<li><a title="' . $y . '年" href="' . get_year_link($y) . '">' . $y . '年</a></li>'; $breadcrumbs .= "<li>" . $m . "月</li>"; } } elseif (is_search()) { $breadcrumbs .= "<li>Search Results</li>"; } elseif (is_404()) { $breadcrumbs .= "<li>404 Not Found</li>"; } elseif (is_single()) { $category = get_the_category(); $category_id = get_cat_ID($category[0]->cat_name); $breadcrumbs .= '<li>' . get_category_parents($category_id, true, "") . "</li>"; $breadcrumbs .= '<li>' . get_the_title(get_query_var('p')) . "</li>"; } elseif (is_page()) { $post = $wp_query->get_queried_object(); if ($post->post_parent == 0) { $breadcrumbs .= "<li>" . the_title('', '', false) . "</li>"; } else { $title = the_title('', '', false); $ancestors = array_reverse(get_post_ancestors($post->ID)); array_push($ancestors, $post->ID); foreach ($ancestors as $ancestor) { if ($ancestor != end($ancestors)) { $breadcrumbs .= '<li><a href="' . get_permalink($ancestor) . '">' . strip_tags(apply_filters('single_post_title', get_the_title($ancestor))) . '</a></li>'; } else { $breadcrumbs .= '<li>' . strip_tags(apply_filters('single_post_title', get_the_title($ancestor))) . '</li>'; } } } } } return $breadcrumbs; }
/** * Get all dates archives urls associated to a specific post * * @since 1.0 * * @param int $post_ID The post ID * @return array $urls List of dates URLs */ function get_rocket_post_dates_urls($post_ID) { // Get the day and month of the post $date = explode('-', get_the_time('Y-m-d', $post_ID)); $urls = array(get_year_link($date[0]) . 'index.html', get_year_link($date[0]) . $GLOBALS['wp_rewrite']->pagination_base, get_month_link($date[0], $date[1]) . 'index.html', get_month_link($date[0], $date[1]) . $GLOBALS['wp_rewrite']->pagination_base, get_day_link($date[0], $date[1], $date[2])); /** * Filter the list of dates URLs * * @since 1.1.0 * * @param array $urls List of dates URLs */ $urls = apply_filters('rocket_post_dates_urls', $urls); return $urls; }
function _checkFile($directory, $file) { $f = "{$directory}/{$file}"; if (ctype_digit($file)) { if ($this->_directory === $directory) { // add year to the list (do not closes li, because // we may have nested elements) $this->_year = $file; $lnk = get_year_link($file); $this->_htmllist[$this->_year] = "<li class=\"archive-year archive-y20{$file}\"> <a href=\"{$lnk}\">20{$file}</a>"; return 1; } elseif (is_dir($f)) { $this->_months[] = $file; return 0; } } }
/** * @param array|string $args * @param string $last_changed * @param string $join * @param string $where * @param string $order * @param string $limit * @return array */ function get_items_yearly($args, $last_changed, $join, $where, $order, $limit) { global $wpdb; $output = array(); $query = "SELECT YEAR(post_date) AS `year`, count(ID) as posts FROM {$wpdb->posts} {$join} {$where} GROUP BY YEAR(post_date) ORDER BY post_date {$order} {$limit}"; $key = md5($query); $key = "wp_get_archives:{$key}:{$last_changed}"; if (!($results = wp_cache_get($key, 'posts'))) { $results = $wpdb->get_results($query); wp_cache_set($key, $results, 'posts'); } if ($results) { foreach ((array) $results as $result) { $url = get_year_link($result->year); $text = sprintf('%d', $result->year); $output[] = $this->get_archives_link($url, $text); } } return $output; }
/** * Flushes post cache * * @param integer $post_id * @return boolean */ function flush_post($post_id = null) { if (!$post_id) { $post_id = $this->_detect_post_id(); } if ($post_id) { $uris = array(); $domain_url = w3_get_domain_url(); $feeds = $this->_config->get_array('pgcache.purge.feed.types'); if ($this->_config->get_boolean('pgcache.purge.terms') || $this->_config->get_boolean('pgcache.purge.feed.terms')) { $taxonomies = get_post_taxonomies($post_id); $terms = nxt_get_post_terms($post_id, $taxonomies); } switch (true) { case $this->_config->get_boolean('pgcache.purge.author'): case $this->_config->get_boolean('pgcache.purge.archive.daily'): case $this->_config->get_boolean('pgcache.purge.archive.monthly'): case $this->_config->get_boolean('pgcache.purge.archive.yearly'): case $this->_config->get_boolean('pgcache.purge.feed.author'): $post = get_post($post_id); } /** * Home URL */ if ($this->_config->get_boolean('pgcache.purge.home')) { $home_path = w3_get_home_path(); $site_path = w3_get_site_path(); $uris[] = $home_path; if ($site_path != $home_path) { $uris[] = $site_path; } } /** * Post URL */ if ($this->_config->get_boolean('pgcache.purge.post')) { $post_link = post_permalink($post_id); $post_uri = str_replace($domain_url, '', $post_link); $uris[] = $post_uri; } /** * Post comments URLs */ if ($this->_config->get_boolean('pgcache.purge.comments') && function_exists('get_comments_pagenum_link')) { $comments_number = get_comments_number($post_id); $comments_per_page = get_option('comments_per_page'); $comments_pages_number = @ceil($comments_number / $comments_per_page); for ($pagenum = 1; $pagenum <= $comments_pages_number; $pagenum++) { $comments_pagenum_link = $this->_get_comments_pagenum_link($post_id, $pagenum); $comments_pagenum_uri = str_replace($domain_url, '', $comments_pagenum_link); $uris[] = $comments_pagenum_uri; } } /** * Post author URLs */ if ($this->_config->get_boolean('pgcache.purge.author') && $post) { $posts_number = count_user_posts($post->post_author); $posts_per_page = get_option('posts_per_page'); $posts_pages_number = @ceil($posts_number / $posts_per_page); $author_link = get_author_link(false, $post->post_author); $author_uri = str_replace($domain_url, '', $author_link); for ($pagenum = 1; $pagenum <= $posts_pages_number; $pagenum++) { $author_pagenum_link = $this->_get_pagenum_link($author_uri, $pagenum); $author_pagenum_uri = str_replace($domain_url, '', $author_pagenum_link); $uris[] = $author_pagenum_uri; } } /** * Post terms URLs */ if ($this->_config->get_boolean('pgcache.purge.terms')) { $posts_per_page = get_option('posts_per_page'); foreach ($terms as $term) { $term_link = get_term_link($term, $term->taxonomy); $term_uri = str_replace($domain_url, '', $term_link); $posts_pages_number = @ceil($term->count / $posts_per_page); for ($pagenum = 1; $pagenum <= $posts_pages_number; $pagenum++) { $term_pagenum_link = $this->_get_pagenum_link($term_uri, $pagenum); $term_pagenum_uri = str_replace($domain_url, '', $term_pagenum_link); $uris[] = $term_pagenum_uri; } } } /** * Daily archive URLs */ if ($this->_config->get_boolean('pgcache.purge.archive.daily') && $post) { $post_date = strtotime($post->post_date); $post_year = gmdate('Y', $post_date); $post_month = gmdate('m', $post_date); $post_day = gmdate('d', $post_date); $posts_per_page = get_option('posts_per_page'); $posts_number = $this->_get_archive_posts_count($post_year, $post_month, $post_day); $posts_pages_number = @ceil($posts_number / $posts_per_page); $day_link = get_day_link($post_year, $post_month, $post_day); $day_uri = str_replace($domain_url, '', $day_link); for ($pagenum = 1; $pagenum <= $posts_pages_number; $pagenum++) { $day_pagenum_link = $this->_get_pagenum_link($day_uri, $pagenum); $day_pagenum_uri = str_replace($domain_url, '', $day_pagenum_link); $uris[] = $day_pagenum_uri; } } /** * Monthly archive URLs */ if ($this->_config->get_boolean('pgcache.purge.archive.monthly') && $post) { $post_date = strtotime($post->post_date); $post_year = gmdate('Y', $post_date); $post_month = gmdate('m', $post_date); $posts_per_page = get_option('posts_per_page'); $posts_number = $this->_get_archive_posts_count($post_year, $post_month); $posts_pages_number = @ceil($posts_number / $posts_per_page); $month_link = get_month_link($post_year, $post_month); $month_uri = str_replace($domain_url, '', $month_link); for ($pagenum = 1; $pagenum <= $posts_pages_number; $pagenum++) { $month_pagenum_link = $this->_get_pagenum_link($month_uri, $pagenum); $month_pagenum_uri = str_replace($domain_url, '', $month_pagenum_link); $uris[] = $month_pagenum_uri; } } /** * Yearly archive URLs */ if ($this->_config->get_boolean('pgcache.purge.archive.yearly') && $post) { $post_date = strtotime($post->post_date); $post_year = gmdate('Y', $post_date); $posts_per_page = get_option('posts_per_page'); $posts_number = $this->_get_archive_posts_count($post_year); $posts_pages_number = @ceil($posts_number / $posts_per_page); $year_link = get_year_link($post_year); $year_uri = str_replace($domain_url, '', $year_link); for ($pagenum = 1; $pagenum <= $posts_pages_number; $pagenum++) { $year_pagenum_link = $this->_get_pagenum_link($year_uri, $pagenum); $year_pagenum_uri = str_replace($domain_url, '', $year_pagenum_link); $uris[] = $year_pagenum_uri; } } /** * Feed URLs */ if ($this->_config->get_boolean('pgcache.purge.feed.blog')) { foreach ($feeds as $feed) { $feed_link = get_feed_link($feed); $feed_uri = str_replace($domain_url, '', $feed_link); $uris[] = $feed_uri; } } if ($this->_config->get_boolean('pgcache.purge.feed.comments')) { foreach ($feeds as $feed) { $post_comments_feed_link = get_post_comments_feed_link($post_id, $feed); $post_comments_feed_uri = str_replace($domain_url, '', $post_comments_feed_link); $uris[] = $post_comments_feed_uri; } } if ($this->_config->get_boolean('pgcache.purge.feed.author') && $post) { foreach ($feeds as $feed) { $author_feed_link = get_author_feed_link($post->post_author, $feed); $author_feed_uri = str_replace($domain_url, '', $author_feed_link); $uris[] = $author_feed_uri; } } if ($this->_config->get_boolean('pgcache.purge.feed.terms')) { foreach ($terms as $term) { foreach ($feeds as $feed) { $term_feed_link = get_term_feed_link($term->term_id, $term->taxonomy, $feed); $term_feed_uri = str_replace($domain_url, '', $term_feed_link); $uris[] = $term_feed_uri; } } } /** * Flush cache */ if (count($uris)) { $cache =& $this->_get_cache(); $mobile_groups = $this->_get_mobile_groups(); $referrer_groups = $this->_get_referrer_groups(); $encryptions = $this->_get_encryptions(); $compressions = $this->_get_compressions(); foreach ($uris as $uri) { foreach ($mobile_groups as $mobile_group) { foreach ($referrer_groups as $referrer_group) { foreach ($encryptions as $encryption) { foreach ($compressions as $compression) { $page_key = $this->_get_page_key($uri, $mobile_group, $referrer_group, $encryption, $compression); $cache->delete($page_key); } } } } } /** * Purge varnish servers */ if ($this->_config->get_boolean('varnish.enabled')) { $varnish =& w3_instance('W3_Varnish'); foreach ($uris as $uri) { $varnish->purge($uri); } } } return true; } return false; }
function foundationpress_breadcrumb($showhome = true, $separatorclass = false) { // Settings $separator = '>'; $id = 'breadcrumbs'; $class = 'breadcrumbs'; $home_title = 'Homepage'; // Get the query & post information global $post, $wp_query; $category = get_the_category(); // Build the breadcrums echo '<ul id="' . $id . '" class="' . $class . '">'; // Do not display on the homepage if (!is_front_page()) { // Home page echo '<li class="item-home"><a class="bread-link bread-home" href="' . get_home_url() . '" title="' . $home_title . '">' . $home_title . '</a></li>'; if ($separatorclass) { echo '<li class="separator separator-home"> ' . $separator . ' </li>'; } if (is_single()) { // Single post (Only display the first category) echo '<li class="item-cat item-cat-' . $category[0]->term_id . ' item-cat-' . $category[0]->category_nicename . '"><a class="bread-cat bread-cat-' . $category[0]->term_id . ' bread-cat-' . $category[0]->category_nicename . '" href="' . get_category_link($category[0]->term_id) . '" title="' . $category[0]->cat_name . '">' . $category[0]->cat_name . '</a></li>'; if ($separatorclass) { echo '<li class="separator separator-' . $category[0]->term_id . '"> ' . $separator . ' </li>'; } echo '<li class="item-current item-' . $post->ID . '"><strong class="bread-current bread-' . $post->ID . '" title="' . get_the_title() . '">' . get_the_title() . '</strong></li>'; } else { if (is_category()) { // Category page echo '<li class="item-current item-cat-' . $category[0]->term_id . ' item-cat-' . $category[0]->category_nicename . '"><strong class="bread-current bread-cat-' . $category[0]->term_id . ' bread-cat-' . $category[0]->category_nicename . '">' . $category[0]->cat_name . '</strong></li>'; } else { if (is_page()) { // Standard page if ($post->post_parent) { // If child page, get parents $anc = get_post_ancestors($post->ID); // Get parents in the right order $anc = array_reverse($anc); // Parent page loop $parents = ''; foreach ($anc as $ancestor) { $parents .= '<li class="item-parent item-parent-' . $ancestor . '"><a class="bread-parent bread-parent-' . $ancestor . '" href="' . get_permalink($ancestor) . '" title="' . get_the_title($ancestor) . '">' . get_the_title($ancestor) . '</a></li>'; if ($separatorclass) { $parents .= '<li class="separator separator-' . $ancestor . '"> ' . $separator . ' </li>'; } } // Display parent pages echo $parents; // Current page echo '<li class="current item-' . $post->ID . '">' . get_the_title() . '</li>'; } else { // Just display current page if not parents echo '<li class="current item-' . $post->ID . '"> ' . get_the_title() . '</li>'; } } else { if (is_tag()) { // Tag page // Get tag information $term_id = get_query_var('tag_id'); $taxonomy = 'post_tag'; $args = 'include=' . $term_id; $terms = get_terms($taxonomy, $args); // Display the tag name echo '<li class="current item-tag-' . $terms[0]->term_id . ' item-tag-' . $terms[0]->slug . '">' . $terms[0]->name . '</li>'; } elseif (is_day()) { // Day archive // Year link echo '<li class="item-year item-year-' . get_the_time('Y') . '"><a class="bread-year bread-year-' . get_the_time('Y') . '" href="' . get_year_link(get_the_time('Y')) . '" title="' . get_the_time('Y') . '">' . get_the_time('Y') . ' Archives</a></li>'; if ($separatorclass) { echo '<li class="separator separator-' . get_the_time('Y') . '"> ' . $separator . ' </li>'; } // Month link echo '<li class="item-month item-month-' . get_the_time('m') . '"><a class="bread-month bread-month-' . get_the_time('m') . '" href="' . get_month_link(get_the_time('Y'), get_the_time('m')) . '" title="' . get_the_time('M') . '">' . get_the_time('M') . ' Archives</a></li>'; if ($separatorclass) { echo '<li class="separator separator-' . get_the_time('m') . '"> ' . $separator . ' </li>'; } // Day display echo '<li class="current item-' . get_the_time('j') . '">' . get_the_time('jS') . ' ' . get_the_time('M') . ' Archives</li>'; } else { if (is_month()) { // Month Archive // Year link echo '<li class="item-year item-year-' . get_the_time('Y') . '"><a class="bread-year bread-year-' . get_the_time('Y') . '" href="' . get_year_link(get_the_time('Y')) . '" title="' . get_the_time('Y') . '">' . get_the_time('Y') . ' Archives</a></li>'; if ($separatorclass) { echo '<li class="separator separator-' . get_the_time('Y') . '"> ' . $separator . ' </li>'; } // Month display echo '<li class="item-month item-month-' . get_the_time('m') . '">' . get_the_time('M') . ' Archives</li>'; } else { if (is_year()) { // Display year archive echo '<li class="current item-current-' . get_the_time('Y') . '">' . get_the_time('Y') . ' Archives</li>'; } else { if (is_author()) { // Auhor archive // Get the author information global $author; $userdata = get_userdata($author); // Display author name echo '<li class="current item-current-' . $userdata->user_nicename . '">Author: ' . $userdata->display_name . '</li>'; } else { if (get_query_var('paged')) { // Paginated archives echo '<li class="current item-current-' . get_query_var('paged') . '">' . __('Page') . ' ' . get_query_var('paged') . '</li>'; } else { if (is_search()) { // Search results page echo '<li class="current item-current-' . get_search_query() . '">Search results for: ' . get_search_query() . '</li>'; } elseif (is_404()) { // 404 page echo '<li>Error 404</li>'; } } } } } } } } } } else { if ($showhome) { echo '<li class="item-home current">' . $home_title . '</li>'; } } echo '</ul>'; }
/** * Breadcrumbs. * * @since 2.2.0 * * @param string $homepage Homepage name. * * @return string HTML of breadcrumbs. */ function odin_breadcrumbs($homepage = '') { global $wp_query, $post, $author; !empty($homepage) || ($homepage = __('Home', 'odin')); // Default html. $current_before = '<li class="active">'; $current_after = '</li>'; if (!is_home() && !is_front_page() || is_paged()) { // First level. echo '<ol id="breadcrumbs" class="breadcrumb">'; echo '<li><a href="' . home_url() . '" rel="nofollow">' . $homepage . '</a></li>'; // Single post. if (is_single() && !is_attachment()) { // Checks if is a custom post type. if ('post' != $post->post_type) { // But if Woocommerce if ('product' === $post->post_type) { if (is_woocommerce_activated()) { $shop_page = get_post(wc_get_page_id('shop')); echo '<li><a href="' . get_permalink($shop_page) . '">' . get_the_title($shop_page) . '</a></li>'; } // Gets post type taxonomies. $taxonomy = get_object_taxonomies('product'); $taxy = 'product_cat'; } else { $post_type = get_post_type_object($post->post_type); echo '<li><a href="' . get_post_type_archive_link($post_type->name) . '">' . $post_type->label . '</a></li> '; // Gets post type taxonomies. $taxonomy = get_object_taxonomies($post_type->name); } if ($taxonomy) { $taxy = $taxonomy[0]; // Gets post terms. $terms = get_the_terms($post->ID, $taxy); $term = $terms ? array_shift($terms) : ''; // Gets parent post terms. $parent_term = get_term($term->parent, $taxy); if ($term) { if ($term->parent) { echo '<li><a href="' . get_term_link($parent_term) . '">' . $parent_term->name . '</a></li> '; } echo '<li><a href="' . get_term_link($term) . '">' . $term->name . '</a></li> '; } } } else { $category = get_the_category(); $category = $category[0]; // Gets parent post terms. $parent_cat = get_term($category->parent, 'category'); // Gets top term $cat_tree = get_category_parents($category, FALSE, ':'); $top_cat = explode(':', $cat_tree); $top_cat = $top_cat[0]; if ($category->parent) { if ($parent_cat->parent) { echo '<li><a href="' . get_term_link($top_cat, 'category') . '">' . $top_cat . '</a></li>'; } echo '<li><a href="' . get_term_link($parent_cat) . '">' . $parent_cat->name . '</a></li>'; } echo '<li><a href="' . get_category_link($category->term_id) . '">' . $category->name . '</a></li>'; } echo $current_before . get_the_title() . $current_after; // Single attachment. } elseif (is_attachment()) { $parent = get_post($post->post_parent); $category = get_the_category($parent->ID); $category = $category[0]; echo '<li><a href="' . get_category_link($category->term_id) . '">' . $category->name . '</a></li>'; echo '<li><a href="' . get_permalink($parent) . '">' . $parent->post_title . '</a></li>'; echo $current_before . get_the_title() . $current_after; // Page without parents. } elseif (is_page() && !$post->post_parent) { echo $current_before . get_the_title() . $current_after; // Page with parents. } elseif (is_page() && $post->post_parent) { $parent_id = $post->post_parent; $breadcrumbs = array(); while ($parent_id) { $page = get_page($parent_id); $breadcrumbs[] = '<li><a href="' . get_permalink($page->ID) . '">' . get_the_title($page->ID) . '</a></li>'; $parent_id = $page->post_parent; } $breadcrumbs = array_reverse($breadcrumbs); foreach ($breadcrumbs as $crumb) { echo $crumb . ' '; } echo $current_before . get_the_title() . $current_after; // Category archive. } elseif (is_category()) { $category_object = $wp_query->get_queried_object(); $category_id = $category_object->term_id; $current_category = get_category($category_id); $parent_category = get_category($current_category->parent); // Displays parent category. if (0 != $current_category->parent) { $parents = get_category_parents($parent_category, TRUE, false); $parents = str_replace('<a', '<li><a', $parents); $parents = str_replace('</a>', '</a></li>', $parents); echo $parents; } printf(__('%sCategory: %s%s', 'odin'), $current_before, single_cat_title('', false), $current_after); // Tags archive. } elseif (is_tag()) { printf(__('%sTag: %s%s', 'odin'), $current_before, single_tag_title('', false), $current_after); // Custom post type archive. } elseif (is_post_type_archive()) { // Check if Woocommerce Shop if (is_woocommerce_activated() && is_shop()) { $shop_page_id = wc_get_page_id('shop'); echo $current_before . get_the_title($shop_page_id) . $current_after; } else { echo $current_before . post_type_archive_title('', false) . $current_after; } // Search page. } elseif (is_search()) { printf(__('%sSearch result for: "%s"%s', 'odin'), $current_before, get_search_query(), $current_after); // Author archive. } elseif (is_author()) { $userdata = get_userdata($author); echo $current_before . __('Posted by', 'odin') . ' ' . $userdata->display_name . $current_after; // Archives per days. } elseif (is_day()) { echo '<li><a href="' . get_year_link(get_the_time('Y')) . '">' . get_the_time('Y') . '</a></li>'; echo '<li><a href="' . get_month_link(get_the_time('Y'), get_the_time('m')) . '">' . get_the_time('F') . '</a></li>'; echo $current_before . get_the_time('d') . $current_after; // Archives per month. } elseif (is_month()) { echo '<li><a href="' . get_year_link(get_the_time('Y')) . '">' . get_the_time('Y') . '</a></li>'; echo $current_before . get_the_time('F') . $current_after; // Archives per year. } elseif (is_year()) { echo $current_before . get_the_time('Y') . $current_after; // Archive fallback for custom taxonomies. } elseif (is_archive()) { $current_object = $wp_query->get_queried_object(); $taxonomy = get_taxonomy($current_object->taxonomy); $term_name = $current_object->name; // Displays the post type that the taxonomy belongs. if (!empty($taxonomy->object_type)) { // Get correct Woocommerce Post Type crumb if (is_woocommerce()) { $shop_page = get_post(wc_get_page_id('shop')); echo '<li><a href="' . get_permalink($shop_page) . '">' . get_the_title($shop_page) . '</a></li>'; } else { $_post_type = array_shift($taxonomy->object_type); $post_type = get_post_type_object($_post_type); echo '<li><a href="' . get_post_type_archive_link($post_type->name) . '">' . $post_type->label . '</a></li> '; } } // Displays parent term. if (0 != $current_object->parent) { $parent_term = get_term($current_object->parent, $current_object->taxonomy); echo '<li><a href="' . get_term_link($parent_term) . '">' . $parent_term->name . '</a></li>'; } echo $current_before . $taxonomy->label . ': ' . $term_name . $current_after; // 404 page. } elseif (is_404()) { echo $current_before . __('404 Error', 'odin') . $current_after; } // Gets pagination. if (get_query_var('paged')) { echo ' (' . sprintf(__('Page %s', 'abelman'), get_query_var('paged')) . ')'; } echo '</ol>'; } }
/** * A Breadcrumb Trail Filling Function * * This functions fills a breadcrumb for a date archive. * */ protected function do_archive_by_date() { global $wp_query; //First deal with the day breadcrumb if (is_day() || is_single()) { //Place the breadcrumb in the trail, uses the constructor to set the title, prefix, and suffix, get a pointer to it in return $breadcrumb = $this->add(new bcn_breadcrumb(get_the_time('d'), $this->opt['Hdate_template_no_anchor'], array('archive', 'date-day'))); //If this is a day archive, add current-item type if (is_day()) { $breadcrumb->add_type('current-item'); } //If we're paged, let's link to the first page if ($this->opt['bcurrent_item_linked'] || is_paged() && $this->opt['bpaged_display'] || is_single()) { //We're linking, so set the linked template $breadcrumb->set_template($this->opt['Hdate_template']); //Deal with the anchor $breadcrumb->set_url(get_day_link(get_the_time('Y'), get_the_time('m'), get_the_time('d'))); } } //Now deal with the month breadcrumb if (is_month() || is_day() || is_single()) { //Place the breadcrumb in the trail, uses the constructor to set the title, prefix, and suffix, get a pointer to it in return $breadcrumb = $this->add(new bcn_breadcrumb(get_the_time('F'), $this->opt['Hdate_template_no_anchor'], array('archive', 'date-month'))); //If this is a month archive, add current-item type if (is_month()) { $breadcrumb->add_type('current-item'); } //If we're paged, or not in the archive by month let's link to the first archive by month page if ($this->opt['bcurrent_item_linked'] || is_day() || is_single() || is_month() && is_paged() && $this->opt['bpaged_display']) { //We're linking, so set the linked template $breadcrumb->set_template($this->opt['Hdate_template']); //Deal with the anchor $breadcrumb->set_url(get_month_link(get_the_time('Y'), get_the_time('m'))); } } //Place the year breadcrumb in the trail, uses the constructor to set the title, prefix, and suffix, get a pointer to it in return $breadcrumb = $this->add(new bcn_breadcrumb(get_the_time('Y'), $this->opt['Hdate_template_no_anchor'], array('archive', 'date-year'))); //If this is a year archive, add current-item type if (is_year()) { $breadcrumb->add_type('current-item'); } //If we're paged, or not in the archive by year let's link to the first archive by year page if ($this->opt['bcurrent_item_linked'] || is_day() || is_month() || is_single() || is_paged() && $this->opt['bpaged_display']) { //We're linking, so set the linked template $breadcrumb->set_template($this->opt['Hdate_template']); //Deal with the anchor $breadcrumb->set_url(get_year_link(get_the_time('Y'))); } }
/** * Redirects incoming links to the proper URL based on the site url. * * Search engines consider www.somedomain.com and somedomain.com to be two * different URLs when they both go to the same location. This SEO enhancement * prevents penality for duplicate content by redirecting all incoming links to * one or the other. * * Prevents redirection for feeds, trackbacks, searches, comment popup, and * admin URLs. Does not redirect on IIS, page/post previews, and on form data. * * Will also attempt to find the correct link when a user enters a URL that does * not exist based on exact WordPress query. Will instead try to parse the URL * or query in an attempt to figure the correct page to go to. * * @since 2.3.0 * @uses $wp_rewrite * @uses $is_IIS * * @param string $requested_url Optional. The URL that was requested, used to * figure if redirect is needed. * @param bool $do_redirect Optional. Redirect to the new URL. * @return null|false|string Null, if redirect not needed. False, if redirect * not needed or the string of the URL */ function redirect_canonical($requested_url = null, $do_redirect = true) { global $wp_rewrite, $is_IIS, $wp_query, $wpdb; if (is_trackback() || is_search() || is_comments_popup() || is_admin() || $is_IIS || isset($_POST) && count($_POST) || is_preview() || is_robots()) { return; } if (!$requested_url) { // build the URL in the address bar $requested_url = is_ssl() ? 'https://' : 'http://'; $requested_url .= $_SERVER['HTTP_HOST']; $requested_url .= $_SERVER['REQUEST_URI']; } $original = @parse_url($requested_url); if (false === $original) { return; } // Some PHP setups turn requests for / into /index.php in REQUEST_URI // See: http://trac.wordpress.org/ticket/5017 // See: http://trac.wordpress.org/ticket/7173 // Disabled, for now: // $original['path'] = preg_replace('|/index\.php$|', '/', $original['path']); $redirect = $original; $redirect_url = false; // Notice fixing if (!isset($redirect['path'])) { $redirect['path'] = ''; } if (!isset($redirect['query'])) { $redirect['query'] = ''; } if (is_singular() && 1 > $wp_query->post_count && ($id = get_query_var('p'))) { $vars = $wpdb->get_results($wpdb->prepare("SELECT post_type, post_parent FROM {$wpdb->posts} WHERE ID = %d", $id)); if (isset($vars[0]) && ($vars = $vars[0])) { if ('revision' == $vars->post_type && $vars->post_parent > 0) { $id = $vars->post_parent; } if ($redirect_url = get_permalink($id)) { $redirect['query'] = remove_query_arg(array('p', 'page_id', 'attachment_id', 'post_type'), $redirect['query']); } } } // These tests give us a WP-generated permalink if (is_404()) { // Redirect ?page_id, ?p=, ?attachment_id= to their respective url's $id = max(get_query_var('p'), get_query_var('page_id'), get_query_var('attachment_id')); if ($id && ($redirect_post = get_post($id))) { $post_type_obj = get_post_type_object($redirect_post->post_type); if ($post_type_obj->public) { $redirect_url = get_permalink($redirect_post); $redirect['query'] = remove_query_arg(array('p', 'page_id', 'attachment_id', 'post_type'), $redirect['query']); } } if (!$redirect_url) { $redirect_url = redirect_guess_404_permalink(); } } elseif (is_object($wp_rewrite) && $wp_rewrite->using_permalinks()) { // rewriting of old ?p=X, ?m=2004, ?m=200401, ?m=20040101 if (is_attachment() && !empty($_GET['attachment_id']) && !$redirect_url) { if ($redirect_url = get_attachment_link(get_query_var('attachment_id'))) { $redirect['query'] = remove_query_arg('attachment_id', $redirect['query']); } } elseif (is_single() && !empty($_GET['p']) && !$redirect_url) { if ($redirect_url = get_permalink(get_query_var('p'))) { $redirect['query'] = remove_query_arg(array('p', 'post_type'), $redirect['query']); } if (get_query_var('page')) { $redirect_url = trailingslashit($redirect_url) . user_trailingslashit(get_query_var('page'), 'single_paged'); $redirect['query'] = remove_query_arg('page', $redirect['query']); } } elseif (is_single() && !empty($_GET['name']) && !$redirect_url) { if ($redirect_url = get_permalink($wp_query->get_queried_object_id())) { $redirect['query'] = remove_query_arg('name', $redirect['query']); } } elseif (is_page() && !empty($_GET['page_id']) && !$redirect_url) { if ($redirect_url = get_permalink(get_query_var('page_id'))) { $redirect['query'] = remove_query_arg('page_id', $redirect['query']); } } elseif (is_page() && !is_feed() && isset($wp_query->queried_object) && 'page' == get_option('show_on_front') && $wp_query->queried_object->ID == get_option('page_on_front') && !$redirect_url) { $redirect_url = home_url('/'); } elseif (is_home() && !empty($_GET['page_id']) && 'page' == get_option('show_on_front') && get_query_var('page_id') == get_option('page_for_posts') && !$redirect_url) { if ($redirect_url = get_permalink(get_option('page_for_posts'))) { $redirect['query'] = remove_query_arg('page_id', $redirect['query']); } } elseif (!empty($_GET['m']) && (is_year() || is_month() || is_day())) { $m = get_query_var('m'); switch (strlen($m)) { case 4: // Yearly $redirect_url = get_year_link($m); break; case 6: // Monthly $redirect_url = get_month_link(substr($m, 0, 4), substr($m, 4, 2)); break; case 8: // Daily $redirect_url = get_day_link(substr($m, 0, 4), substr($m, 4, 2), substr($m, 6, 2)); break; } if ($redirect_url) { $redirect['query'] = remove_query_arg('m', $redirect['query']); } // now moving on to non ?m=X year/month/day links } elseif (is_day() && get_query_var('year') && get_query_var('monthnum') && !empty($_GET['day'])) { if ($redirect_url = get_day_link(get_query_var('year'), get_query_var('monthnum'), get_query_var('day'))) { $redirect['query'] = remove_query_arg(array('year', 'monthnum', 'day'), $redirect['query']); } } elseif (is_month() && get_query_var('year') && !empty($_GET['monthnum'])) { if ($redirect_url = get_month_link(get_query_var('year'), get_query_var('monthnum'))) { $redirect['query'] = remove_query_arg(array('year', 'monthnum'), $redirect['query']); } } elseif (is_year() && !empty($_GET['year'])) { if ($redirect_url = get_year_link(get_query_var('year'))) { $redirect['query'] = remove_query_arg('year', $redirect['query']); } } elseif (is_author() && !empty($_GET['author']) && preg_match('|^[0-9]+$|', $_GET['author'])) { $author = get_userdata(get_query_var('author')); if (false !== $author && ($redirect_url = get_author_posts_url($author->ID, $author->user_nicename))) { $redirect['query'] = remove_query_arg('author', $redirect['query']); } } elseif (is_category() || is_tag() || is_tax()) { // Terms (Tags/categories) $term_count = 0; foreach (array('category__in', 'category__not_in', 'category__and', 'post__in', 'post__not_in', 'tag__in', 'tag__not_in', 'tag__and', 'tag_slug__in', 'tag_slug__and') as $key) { $term_count += count($wp_query->query_vars[$key]); } $obj = $wp_query->get_queried_object(); if ($term_count <= 1 && !empty($obj->term_id) && ($tax_url = get_term_link((int) $obj->term_id, $obj->taxonomy)) && !is_wp_error($tax_url)) { if (is_category()) { $redirect['query'] = remove_query_arg(array('category_name', 'category', 'cat'), $redirect['query']); } elseif (is_tag()) { $redirect['query'] = remove_query_arg(array('tag', 'tag_id'), $redirect['query']); } elseif (is_tax()) { // Custom taxonomies will have a custom query var, remove those too: $tax = get_taxonomy($obj->taxonomy); if (false !== $tax->query_var) { $redirect['query'] = remove_query_arg($tax->query_var, $redirect['query']); } else { $redirect['query'] = remove_query_arg(array('term', 'taxonomy'), $redirect['query']); } } $tax_url = parse_url($tax_url); if (!empty($tax_url['query'])) { // Custom taxonomies may only be accessable via ?taxonomy=..&term=.. parse_str($tax_url['query'], $query_vars); $redirect['query'] = add_query_arg($query_vars, $redirect['query']); } else { // Taxonomy is accessable via a "pretty-URL" $redirect['path'] = $tax_url['path']; } } } elseif (is_single() && strpos($wp_rewrite->permalink_structure, '%category%') !== false) { $category = get_term_by('slug', get_query_var('category_name'), 'category'); $post_terms = wp_get_object_terms($wp_query->get_queried_object_id(), 'category', array('fields' => 'tt_ids')); if (!$category || is_wp_error($category) || !is_wp_error($post_terms) && !empty($post_terms) && !in_array($category->term_taxonomy_id, $post_terms)) { $redirect_url = get_permalink($wp_query->get_queried_object_id()); } } // paging and feeds if (get_query_var('paged') || is_feed() || get_query_var('cpage')) { if (!$redirect_url) { $redirect_url = $requested_url; } $paged_redirect = @parse_url($redirect_url); while (preg_match('#/page/?[0-9]+?(/+)?$#', $paged_redirect['path']) || preg_match('#/(comments/?)?(feed|rss|rdf|atom|rss2)(/+)?$#', $paged_redirect['path']) || preg_match('#/comment-page-[0-9]+(/+)?$#', $paged_redirect['path'])) { // Strip off paging and feed $paged_redirect['path'] = preg_replace('#/page/?[0-9]+?(/+)?$#', '/', $paged_redirect['path']); // strip off any existing paging $paged_redirect['path'] = preg_replace('#/(comments/?)?(feed|rss2?|rdf|atom)(/+|$)#', '/', $paged_redirect['path']); // strip off feed endings $paged_redirect['path'] = preg_replace('#/comment-page-[0-9]+?(/+)?$#', '/', $paged_redirect['path']); // strip off any existing comment paging } $addl_path = ''; if (is_feed()) { $addl_path = !empty($addl_path) ? trailingslashit($addl_path) : ''; if (get_query_var('withcomments')) { $addl_path .= 'comments/'; } $addl_path .= user_trailingslashit('feed/' . (get_default_feed() == get_query_var('feed') || 'feed' == get_query_var('feed') ? '' : get_query_var('feed')), 'feed'); $redirect['query'] = remove_query_arg('feed', $redirect['query']); } if (get_query_var('paged') > 0) { $paged = get_query_var('paged'); $redirect['query'] = remove_query_arg('paged', $redirect['query']); if (!is_feed()) { if ($paged > 1 && !is_single()) { $addl_path = (!empty($addl_path) ? trailingslashit($addl_path) : '') . user_trailingslashit("page/{$paged}", 'paged'); } elseif (!is_single()) { $addl_path = !empty($addl_path) ? trailingslashit($addl_path) : ''; } } elseif ($paged > 1) { $redirect['query'] = add_query_arg('paged', $paged, $redirect['query']); } } if (get_option('page_comments') && ('newest' == get_option('default_comments_page') && get_query_var('cpage') > 0 || 'newest' != get_option('default_comments_page') && get_query_var('cpage') > 1)) { $addl_path = (!empty($addl_path) ? trailingslashit($addl_path) : '') . user_trailingslashit('comment-page-' . get_query_var('cpage'), 'commentpaged'); $redirect['query'] = remove_query_arg('cpage', $redirect['query']); } $paged_redirect['path'] = user_trailingslashit(preg_replace('|/index.php/?$|', '/', $paged_redirect['path'])); // strip off trailing /index.php/ if (!empty($addl_path) && $wp_rewrite->using_index_permalinks() && strpos($paged_redirect['path'], '/index.php/') === false) { $paged_redirect['path'] = trailingslashit($paged_redirect['path']) . 'index.php/'; } if (!empty($addl_path)) { $paged_redirect['path'] = trailingslashit($paged_redirect['path']) . $addl_path; } $redirect_url = $paged_redirect['scheme'] . '://' . $paged_redirect['host'] . $paged_redirect['path']; $redirect['path'] = $paged_redirect['path']; } } // tack on any additional query vars $redirect['query'] = preg_replace('#^\\??&*?#', '', $redirect['query']); if ($redirect_url && !empty($redirect['query'])) { if (strpos($redirect_url, '?') !== false) { $redirect_url .= '&'; } else { $redirect_url .= '?'; } $redirect_url .= $redirect['query']; } if ($redirect_url) { $redirect = @parse_url($redirect_url); } // www.example.com vs example.com $user_home = @parse_url(home_url()); if (!empty($user_home['host'])) { $redirect['host'] = $user_home['host']; } if (empty($user_home['path'])) { $user_home['path'] = '/'; } // Handle ports if (!empty($user_home['port'])) { $redirect['port'] = $user_home['port']; } else { unset($redirect['port']); } // trailing /index.php $redirect['path'] = preg_replace('|/index.php/*?$|', '/', $redirect['path']); // Remove trailing spaces from the path $redirect['path'] = preg_replace('#(%20| )+$#', '', $redirect['path']); if (!empty($redirect['query'])) { // Remove trailing spaces from certain terminating query string args $redirect['query'] = preg_replace('#((p|page_id|cat|tag)=[^&]*?)(%20| )+$#', '$1', $redirect['query']); // Clean up empty query strings $redirect['query'] = trim(preg_replace('#(^|&)(p|page_id|cat|tag)=?(&|$)#', '&', $redirect['query']), '&'); // Remove redundant leading ampersands $redirect['query'] = preg_replace('#^\\??&*?#', '', $redirect['query']); } // strip /index.php/ when we're not using PATHINFO permalinks if (!$wp_rewrite->using_index_permalinks()) { $redirect['path'] = str_replace('/index.php/', '/', $redirect['path']); } // trailing slashes if (is_object($wp_rewrite) && $wp_rewrite->using_permalinks() && !is_404() && (!is_front_page() || is_front_page() && get_query_var('paged') > 1)) { $user_ts_type = ''; if (get_query_var('paged') > 0) { $user_ts_type = 'paged'; } else { foreach (array('single', 'category', 'page', 'day', 'month', 'year', 'home') as $type) { $func = 'is_' . $type; if (call_user_func($func)) { $user_ts_type = $type; break; } } } $redirect['path'] = user_trailingslashit($redirect['path'], $user_ts_type); } elseif (is_front_page()) { $redirect['path'] = trailingslashit($redirect['path']); } // Strip multiple slashes out of the URL if (strpos($redirect['path'], '//') > -1) { $redirect['path'] = preg_replace('|/+|', '/', $redirect['path']); } // Always trailing slash the Front Page URL if (trailingslashit($redirect['path']) == trailingslashit($user_home['path'])) { $redirect['path'] = trailingslashit($redirect['path']); } // Ignore differences in host capitalization, as this can lead to infinite redirects // Only redirect no-www <=> yes-www if (strtolower($original['host']) == strtolower($redirect['host']) || strtolower($original['host']) != 'www.' . strtolower($redirect['host']) && 'www.' . strtolower($original['host']) != strtolower($redirect['host'])) { $redirect['host'] = $original['host']; } $compare_original = array($original['host'], $original['path']); if (!empty($original['port'])) { $compare_original[] = $original['port']; } if (!empty($original['query'])) { $compare_original[] = $original['query']; } $compare_redirect = array($redirect['host'], $redirect['path']); if (!empty($redirect['port'])) { $compare_redirect[] = $redirect['port']; } if (!empty($redirect['query'])) { $compare_redirect[] = $redirect['query']; } if ($compare_original !== $compare_redirect) { $redirect_url = $redirect['scheme'] . '://' . $redirect['host']; if (!empty($redirect['port'])) { $redirect_url .= ':' . $redirect['port']; } $redirect_url .= $redirect['path']; if (!empty($redirect['query'])) { $redirect_url .= '?' . $redirect['query']; } } if (!$redirect_url || $redirect_url == $requested_url) { return false; } // Note that you can use the "redirect_canonical" filter to cancel a canonical redirect for whatever reason by returning FALSE $redirect_url = apply_filters('redirect_canonical', $redirect_url, $requested_url); if (!$redirect_url || $redirect_url == $requested_url) { // yes, again -- in case the filter aborted the request return false; } if ($do_redirect) { // protect against chained redirects if (!redirect_canonical($redirect_url, false)) { wp_redirect($redirect_url, 301); exit; } else { // Debug // die("1: $redirect_url<br />2: " . redirect_canonical( $redirect_url, false ) ); return false; } } else { return $redirect_url; } }
function dimox_breadcrumbs() { /* === ОПЦИИ === */ $text['home'] = 'Home'; // текст ссылки "Главная" $text['category'] = 'Archive category "%s"'; // текст для страницы рубрики $text['search'] = 'Serch result "%s"'; // текст для страницы с результатами поиска $text['tag'] = 'Posts with tag "%s"'; // текст для страницы тега $text['author'] = 'Author posts %s'; // текст для страницы автора $text['404'] = 'Error 404'; // текст для страницы 404 $show_current = 1; // 1 - показывать название текущей статьи/страницы/рубрики, 0 - не показывать $show_on_home = 0; // 1 - показывать "хлебные крошки" на главной странице, 0 - не показывать $show_home_link = 1; // 1 - показывать ссылку "Главная", 0 - не показывать $show_title = 1; // 1 - показывать подсказку (title) для ссылок, 0 - не показывать $delimiter = ' <span class="tr"></span> '; // разделить между "крошками" $before = '<span class="text">'; // тег перед текущей "крошкой" $after = '</span>'; // тег после текущей "крошки" /* === КОНЕЦ ОПЦИЙ === */ global $post; $home_link = home_url('/'); $link_before = '<span typeof="v:Breadcrumb">'; $link_after = '</span>'; $link_attr = ' rel="v:url" property="v:title"'; $link = $link_before . '<a' . $link_attr . ' href="%1$s">%2$s</a>' . $link_after; $parent_id = $parent_id_2 = $post->post_parent; $frontpage_id = get_option('page_on_front'); $style = ''; if (function_exists('is_product')) { if (is_product()) { $style = ' style="text-align: left;"'; } } if (is_home() || is_front_page()) { if ($show_on_home == 1) { echo '<div class="breadcrumbs" ' . $style . '><a href="' . $home_link . '">' . $text['home'] . '</a></div>'; } } else { echo '<div class="breadcrumbs" xmlns:v="http://rdf.data-vocabulary.org/#" ' . $style . '>'; if ($show_home_link == 1) { echo '<a href="' . $home_link . '" rel="v:url" property="v:title">' . $text['home'] . '</a>'; if ($frontpage_id == 0 || $parent_id != $frontpage_id) { echo $delimiter; } } if (is_category()) { $this_cat = get_category(get_query_var('cat'), false); if ($this_cat->parent != 0) { $cats = get_category_parents($this_cat->parent, TRUE, $delimiter); if ($show_current == 0) { $cats = preg_replace("#^(.+){$delimiter}\$#", "\$1", $cats); } $cats = str_replace('<a', $link_before . '<a' . $link_attr, $cats); $cats = str_replace('</a>', '</a>' . $link_after, $cats); if ($show_title == 0) { $cats = preg_replace('/ title="(.*?)"/', '', $cats); } echo $cats; } if ($show_current == 1) { echo $before . sprintf($text['category'], single_cat_title('', false)) . $after; } } elseif (is_search()) { echo $before . sprintf($text['search'], get_search_query()) . $after; } elseif (is_day()) { echo sprintf($link, get_year_link(get_the_time('Y')), get_the_time('Y')) . $delimiter; echo sprintf($link, get_month_link(get_the_time('Y'), get_the_time('m')), get_the_time('F')) . $delimiter; echo $before . get_the_time('d') . $after; } elseif (is_month()) { echo sprintf($link, get_year_link(get_the_time('Y')), get_the_time('Y')) . $delimiter; echo $before . get_the_time('F') . $after; } elseif (is_year()) { echo $before . get_the_time('Y') . $after; } elseif (is_single() && !is_attachment()) { if (get_post_type() != 'post') { $post_type = get_post_type_object(get_post_type()); $slug = $post_type->rewrite; //printf($link, $home_link . '/' . $slug['slug'] . '/', $post_type->labels->singular_name); if ($show_current == 1) { echo $before . get_the_title() . $after; } } else { $cat = get_the_category(); $cat = $cat[0]; $cats = get_category_parents($cat, TRUE, $delimiter); if ($show_current == 0) { $cats = preg_replace("#^(.+){$delimiter}\$#", "\$1", $cats); } $cats = str_replace('<a', $link_before . '<a' . $link_attr, $cats); $cats = str_replace('</a>', '</a>' . $link_after, $cats); if ($show_title == 0) { $cats = preg_replace('/ title="(.*?)"/', '', $cats); } echo $cats; if ($show_current == 1) { echo $before . get_the_title() . $after; } } } elseif (!is_single() && !is_page() && get_post_type() != 'post' && !is_404()) { $post_type = get_post_type_object(get_post_type()); echo $before . $post_type->labels->singular_name . $after; } elseif (is_attachment()) { $parent = get_post($parent_id); $cat = get_the_category($parent->ID); $cat = $cat[0]; $cats = get_category_parents($cat, TRUE, $delimiter); $cats = str_replace('<a', $link_before . '<a' . $link_attr, $cats); $cats = str_replace('</a>', '</a>' . $link_after, $cats); if ($show_title == 0) { $cats = preg_replace('/ title="(.*?)"/', '', $cats); } echo $cats; printf($link, get_permalink($parent), $parent->post_title); if ($show_current == 1) { echo $delimiter . $before . get_the_title() . $after; } } elseif (is_page() && !$parent_id) { if ($show_current == 1) { echo $before . get_the_title() . $after; } } elseif (is_page() && $parent_id) { if ($parent_id != $frontpage_id) { $breadcrumbs = array(); while ($parent_id) { $page = get_page($parent_id); if ($parent_id != $frontpage_id) { $breadcrumbs[] = sprintf($link, get_permalink($page->ID), get_the_title($page->ID)); } $parent_id = $page->post_parent; } $breadcrumbs = array_reverse($breadcrumbs); for ($i = 0; $i < count($breadcrumbs); $i++) { echo $breadcrumbs[$i]; if ($i != count($breadcrumbs) - 1) { echo $delimiter; } } } if ($show_current == 1) { if ($show_home_link == 1 || $parent_id_2 != 0 && $parent_id_2 != $frontpage_id) { echo $delimiter; } echo $before . get_the_title() . $after; } } elseif (is_tag()) { echo $before . sprintf($text['tag'], single_tag_title('', false)) . $after; } elseif (is_author()) { global $author; $userdata = get_userdata($author); echo $before . sprintf($text['author'], $userdata->display_name) . $after; } elseif (is_404()) { echo $before . $text['404'] . $after; } if (get_query_var('paged')) { if (is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author()) { echo ' ('; } echo ' ' . __('Page') . ' ' . get_query_var('paged'); if (is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author()) { echo ')'; } } echo '</div><!-- .breadcrumbs -->'; } }
function make_breadcrumbs($opts = array('show_on_home' => 0, 'delimiter' => '»', 'home' => 'Home', 'showCurrent' => 1, 'before' => '<span class="current">', 'after' => '</span>')) { $showOnHome = $opts['show_on_home']; // 1 - show breadcrumbs on the homepage, 0 - don't show $delimiter = $opts['delimiter']; // delimiter between crumbs $home = $opts['home']; // text for the 'Home' link $showCurrent = $opts['showCurrent']; // 1 - show current post/page title in breadcrumbs, 0 - don't show $before = $opts['before']; // tag before the current crumb $after = $opts['after']; // tag after the current crumb global $post; $homeLink = get_bloginfo('url'); if (is_home() || is_front_page()) { if ($showOnHome == 1) { echo '<ul><li><a href="' . $homeLink . '">' . $home . '</a></li></ul>'; } } else { echo "<ul>\n <li><a href=\"{$homeLink}\">{$home}</a></li>\n {$delimiter}" . "\n"; if (is_category()) { global $wp_query; $cat_obj = $wp_query->get_queried_object(); $thisCat = $cat_obj->term_id; $thisCat = get_category($thisCat); $parentCat = get_category($thisCat->parent); if ($thisCat->parent != 0) { echo " <li>" . get_category_parents($parentCat, TRUE, "</li>\n {$delimiter}\n <li>"); } echo $before . 'Archive by category "' . single_cat_title('', false) . '"' . $after . "</li>" . "\n"; } elseif (is_search()) { echo ' <li>' . $before . 'Search results for "' . get_search_query() . '"' . $after . "</li>" . "\n"; } elseif (is_day()) { echo ' <li><a href="' . get_year_link(get_the_time('Y')) . '">' . get_the_time('Y') . "</a></li>\n" . $delimiter . "\n"; echo ' <li><a href="' . get_month_link(get_the_time('Y'), get_the_time('m')) . '">' . get_the_time('F') . "</a></li>" . "\n" . $delimiter . "\n"; echo ' <li>' . $before . get_the_time('d') . $after . "</li>\n"; } elseif (is_month()) { echo ' <li><a href="' . get_year_link(get_the_time('Y')) . '">' . get_the_time('Y') . "</a></li>\n" . $delimiter . "\n"; echo ' <li>' . $before . get_the_time('F') . $after . "</li>\n"; } elseif (is_year()) { echo ' <li>' . $before . get_the_time('Y') . $after . "</li>\n"; } elseif (is_single() && !is_attachment()) { if (get_post_type() != 'post') { $post_type = get_post_type_object(get_post_type()); $slug = $post_type->rewrite; echo ' <li><a href="' . $homeLink . '/' . $slug['slug'] . '/">' . $post_type->labels->singular_name . '</a></li>' . "\n"; if ($showCurrent == 1) { echo $delimiter . "\n <li>" . $before . get_the_title() . $after . '</li>' . "\n"; } } else { $cat = get_the_category(); $cat = $cat[0]; $cats = get_category_parents($cat, TRUE, "</li>\n " . $delimiter . "\n <li>"); if ($showCurrent == 0) { $cats = preg_replace("/^(.+)\\s{$delimiter}\\s\$/", "\$1", $cats); } echo "<li>" . $cats; if ($showCurrent == 1) { echo $before . get_the_title() . $after . '</li>' . "\n"; } } } elseif (!is_single() && !is_page() && get_post_type() != 'post' && !is_404()) { $post_type = get_post_type_object(get_post_type()); echo ' <li>' . $before . $post_type->labels->singular_name . $after . '</li>' . "\n"; } elseif (is_attachment()) { $parent = get_post($post->post_parent); if (has_term('', 'category', $parent->ID)) { $cat = get_the_category($parent->ID); $cat = $cat[0]; $cats = get_category_parents($cat, TRUE, "</li>\n " . $delimiter . "\n <li>"); if ($showCurrent == 0) { $cats = preg_replace("/^(.+)\\s{$delimiter}\\s\$/", "\$1", $cats); } echo " <li>" . $cats; echo ' <li><a href="' . get_permalink($parent) . '">' . $parent->post_title . '</a></li>' . "\n"; if ($showCurrent == 1) { echo ' ' . $delimiter . ' ' . ' <li>' . $before . get_the_title() . $after . '</li>' . "\n"; } } else { if ($parent->post_title != 'Home') { echo ' <li><a href="' . get_permalink($parent) . '">' . $parent->post_title . '</a></li>' . "\n " . $delimiter . "\n"; } if ($showCurrent == 1) { echo ' <li>' . $before . get_the_title() . $after . '</li>' . "\n"; } } } elseif (is_page() && !$post->post_parent) { if ($showCurrent == 1) { echo ' <li>' . $before . get_the_title() . $after . '</li>' . "\n"; } } elseif (is_page() && $post->post_parent) { $parent_id = $post->post_parent; $breadcrumbs = array(); while ($parent_id) { $page = get_page($parent_id); $breadcrumbs[] = ' <li><a href="' . get_permalink($page->ID) . '">' . get_the_title($page->ID) . '</a></li>' . "\n"; $parent_id = $page->post_parent; } $breadcrumbs = array_reverse($breadcrumbs); foreach ($breadcrumbs as $crumb) { echo $crumb; } if ($showCurrent == 1) { echo $delimiter . "\n <li>" . $before . get_the_title() . $after . '</li>' . "\n"; } } elseif (is_tag()) { echo ' <li>' . $before . 'Posts tagged "' . single_tag_title('', false) . '"' . $after . '</li>' . "\n"; } elseif (is_author()) { global $author; $userdata = get_userdata($author); echo ' <li>' . $before . 'Articles posted by ' . $userdata->display_name . $after . '</li>' . "\n"; } elseif (is_404()) { echo ' <li>' . $before . 'Error 404' . $after . '</li>' . "\n"; } if (get_query_var('paged')) { if (is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author()) { echo ' ('; } echo ' <li><span> - ' . __('Page') . ' ' . get_query_var('paged') . '</span></li>' . "\n"; if (is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author()) { echo ')'; } } echo "</ul>\n"; } }
<a class="posted-month" href="<?php echo get_month_link(get_the_time('Y'), get_the_time('m')); ?> " title="<?php printf(__('See all posts from %s', 'onemozilla'), get_the_time('F, Y')); ?> "><?php the_time('M'); ?> </a> <span class="posted-date"><?php the_time('j'); ?> </span> <a class="posted-year" href="<?php echo get_year_link(get_the_time('Y'), get_the_time('y')); ?> " title="<?php printf(__('See all posts from %s', 'onemozilla'), get_the_time('Y')); ?> "><?php the_time('Y'); ?> </a> </time> </p> <?php } ?> <?php
/** * Display archive links based on type and format. * * @since 1.2.0 * * @see get_archives_link() * * @global wpdb $wpdb * @global WP_Locale $wp_locale * * @param string|array $args { * Default archive links arguments. Optional. * * @type string $type Type of archive to retrieve. Accepts 'daily', 'weekly', 'monthly', * 'yearly', 'postbypost', or 'alpha'. Both 'postbypost' and 'alpha' * display the same archive link list as well as post titles instead * of displaying dates. The difference between the two is that 'alpha' * will order by post title and 'postbypost' will order by post date. * Default 'monthly'. * @type string|int $limit Number of links to limit the query to. Default empty (no limit). * @type string $format Format each link should take using the $before and $after args. * Accepts 'link' (`<link>` tag), 'option' (`<option>` tag), 'html' * (`<li>` tag), or a custom format, which generates a link anchor * with $before preceding and $after succeeding. Default 'html'. * @type string $before Markup to prepend to the beginning of each link. Default empty. * @type string $after Markup to append to the end of each link. Default empty. * @type bool $show_post_count Whether to display the post count alongside the link. Default false. * @type bool|int $echo Whether to echo or return the links list. Default 1|true to echo. * @type string $order Whether to use ascending or descending order. Accepts 'ASC', or 'DESC'. * Default 'DESC'. * } * @return string|void String when retrieving. */ function wp_get_archives($args = '') { global $wpdb, $wp_locale; $defaults = array('type' => 'monthly', 'limit' => '', 'format' => 'html', 'before' => '', 'after' => '', 'show_post_count' => false, 'echo' => 1, 'order' => 'DESC'); $r = wp_parse_args($args, $defaults); if ('' == $r['type']) { $r['type'] = 'monthly'; } if (!empty($r['limit'])) { $r['limit'] = absint($r['limit']); $r['limit'] = ' LIMIT ' . $r['limit']; } $order = strtoupper($r['order']); if ($order !== 'ASC') { $order = 'DESC'; } // this is what will separate dates on weekly archive links $archive_week_separator = '–'; // over-ride general date format ? 0 = no: use the date format set in Options, 1 = yes: over-ride $archive_date_format_over_ride = 0; // options for daily archive (only if you over-ride the general date format) $archive_day_date_format = 'Y/m/d'; // options for weekly archive (only if you over-ride the general date format) $archive_week_start_date_format = 'Y/m/d'; $archive_week_end_date_format = 'Y/m/d'; if (!$archive_date_format_over_ride) { $archive_day_date_format = get_option('date_format'); $archive_week_start_date_format = get_option('date_format'); $archive_week_end_date_format = get_option('date_format'); } /** * Filter the SQL WHERE clause for retrieving archives. * * @since 2.2.0 * * @param string $sql_where Portion of SQL query containing the WHERE clause. * @param array $r An array of default arguments. */ $where = apply_filters('getarchives_where', "WHERE post_type = 'post' AND post_status = 'publish'", $r); /** * Filter the SQL JOIN clause for retrieving archives. * * @since 2.2.0 * * @param string $sql_join Portion of SQL query containing JOIN clause. * @param array $r An array of default arguments. */ $join = apply_filters('getarchives_join', '', $r); $output = ''; $last_changed = wp_cache_get('last_changed', 'posts'); if (!$last_changed) { $last_changed = microtime(); wp_cache_set('last_changed', $last_changed, 'posts'); } $limit = $r['limit']; if ('monthly' == $r['type']) { $query = "SELECT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, count(ID) as posts FROM {$wpdb->posts} {$join} {$where} GROUP BY YEAR(post_date), MONTH(post_date) ORDER BY post_date {$order} {$limit}"; $key = md5($query); $key = "wp_get_archives:{$key}:{$last_changed}"; if (!($results = wp_cache_get($key, 'posts'))) { $results = $wpdb->get_results($query); wp_cache_set($key, $results, 'posts'); } if ($results) { $after = $r['after']; foreach ((array) $results as $result) { $url = get_month_link($result->year, $result->month); /* translators: 1: month name, 2: 4-digit year */ $text = sprintf(__('%1$s %2$d'), $wp_locale->get_month($result->month), $result->year); if ($r['show_post_count']) { $r['after'] = ' (' . $result->posts . ')' . $after; } $output .= get_archives_link($url, $text, $r['format'], $r['before'], $r['after']); } } } elseif ('yearly' == $r['type']) { $query = "SELECT YEAR(post_date) AS `year`, count(ID) as posts FROM {$wpdb->posts} {$join} {$where} GROUP BY YEAR(post_date) ORDER BY post_date {$order} {$limit}"; $key = md5($query); $key = "wp_get_archives:{$key}:{$last_changed}"; if (!($results = wp_cache_get($key, 'posts'))) { $results = $wpdb->get_results($query); wp_cache_set($key, $results, 'posts'); } if ($results) { $after = $r['after']; foreach ((array) $results as $result) { $url = get_year_link($result->year); $text = sprintf('%d', $result->year); if ($r['show_post_count']) { $r['after'] = ' (' . $result->posts . ')' . $after; } $output .= get_archives_link($url, $text, $r['format'], $r['before'], $r['after']); } } } elseif ('daily' == $r['type']) { $query = "SELECT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, DAYOFMONTH(post_date) AS `dayofmonth`, count(ID) as posts FROM {$wpdb->posts} {$join} {$where} GROUP BY YEAR(post_date), MONTH(post_date), DAYOFMONTH(post_date) ORDER BY post_date {$order} {$limit}"; $key = md5($query); $key = "wp_get_archives:{$key}:{$last_changed}"; if (!($results = wp_cache_get($key, 'posts'))) { $results = $wpdb->get_results($query); wp_cache_set($key, $results, 'posts'); } if ($results) { $after = $r['after']; foreach ((array) $results as $result) { $url = get_day_link($result->year, $result->month, $result->dayofmonth); $date = sprintf('%1$d-%2$02d-%3$02d 00:00:00', $result->year, $result->month, $result->dayofmonth); $text = mysql2date($archive_day_date_format, $date); if ($r['show_post_count']) { $r['after'] = ' (' . $result->posts . ')' . $after; } $output .= get_archives_link($url, $text, $r['format'], $r['before'], $r['after']); } } } elseif ('weekly' == $r['type']) { $week = _wp_mysql_week('`post_date`'); $query = "SELECT DISTINCT {$week} AS `week`, YEAR( `post_date` ) AS `yr`, DATE_FORMAT( `post_date`, '%Y-%m-%d' ) AS `yyyymmdd`, count( `ID` ) AS `posts` FROM `{$wpdb->posts}` {$join} {$where} GROUP BY {$week}, YEAR( `post_date` ) ORDER BY `post_date` {$order} {$limit}"; $key = md5($query); $key = "wp_get_archives:{$key}:{$last_changed}"; if (!($results = wp_cache_get($key, 'posts'))) { $results = $wpdb->get_results($query); wp_cache_set($key, $results, 'posts'); } $arc_w_last = ''; if ($results) { $after = $r['after']; foreach ((array) $results as $result) { if ($result->week != $arc_w_last) { $arc_year = $result->yr; $arc_w_last = $result->week; $arc_week = get_weekstartend($result->yyyymmdd, get_option('start_of_week')); $arc_week_start = date_i18n($archive_week_start_date_format, $arc_week['start']); $arc_week_end = date_i18n($archive_week_end_date_format, $arc_week['end']); $url = sprintf('%1$s/%2$s%3$sm%4$s%5$s%6$sw%7$s%8$d', home_url(), '', '?', '=', $arc_year, '&', '=', $result->week); $text = $arc_week_start . $archive_week_separator . $arc_week_end; if ($r['show_post_count']) { $r['after'] = ' (' . $result->posts . ')' . $after; } $output .= get_archives_link($url, $text, $r['format'], $r['before'], $r['after']); } } } } elseif ('postbypost' == $r['type'] || 'alpha' == $r['type']) { $orderby = 'alpha' == $r['type'] ? 'post_title ASC ' : 'post_date DESC, ID DESC '; $query = "SELECT * FROM {$wpdb->posts} {$join} {$where} ORDER BY {$orderby} {$limit}"; $key = md5($query); $key = "wp_get_archives:{$key}:{$last_changed}"; if (!($results = wp_cache_get($key, 'posts'))) { $results = $wpdb->get_results($query); wp_cache_set($key, $results, 'posts'); } if ($results) { foreach ((array) $results as $result) { if ($result->post_date != '0000-00-00 00:00:00') { $url = get_permalink($result); if ($result->post_title) { /** This filter is documented in wp-includes/post-template.php */ $text = strip_tags(apply_filters('the_title', $result->post_title, $result->ID)); } else { $text = $result->ID; } $output .= get_archives_link($url, $text, $r['format'], $r['before'], $r['after']); } } } } if ($r['echo']) { echo $output; } else { return $output; } }
function get_ls_languages($template_args = array()) { //Returns false if is admin and settings are corrupted if (is_admin() && !SitePress::check_settings_integrity()) { return false; } /** @var $wp_query WP_Query */ global $sitepress, $wpdb, $wp_query, $w_this_lang; $current_language = $this->get_current_language(); $default_language = $this->get_default_language(); $cache_key_args = $template_args ? array_filter($template_args) : array('default'); $cache_key_args[] = $current_language; $cache_key_args[] = $default_language; $cache_key_args = array_filter($cache_key_args); $cache_key = md5(json_encode($cache_key_args)); $cache_group = 'ls_languages'; $found = false; $ls_languages = wp_cache_get($cache_key, $cache_group, $found); if ($found) { return $ls_languages; } if (is_null($this->wp_query)) { $this->set_wp_query(); } // use original wp_query for this // backup current $wp_query if (!isset($wp_query)) { return $this->get_active_languages(); } $_wp_query_back = clone $wp_query; unset($wp_query); global $wp_query; // make it global again after unset $wp_query = clone $this->wp_query; $w_active_languages = $this->get_active_languages(); $this_lang = $this->this_lang; if ($this_lang == 'all') { $w_this_lang = array('code' => 'all', 'english_name' => 'All languages', 'display_name' => __('All languages', 'sitepress')); } else { $w_this_lang = $this->get_language_details($this_lang); } if (isset($template_args['skip_missing'])) { //override default setting $icl_lso_link_empty = !$template_args['skip_missing']; } else { $icl_lso_link_empty = $this->settings['icl_lso_link_empty']; } // 1. Determine translations if (is_category()) { $skip_empty = false; $term_taxonomy_id_prepared = $wpdb->prepare("SELECT term_taxonomy_id FROM {$wpdb->term_taxonomy} WHERE term_id=%d AND taxonomy=%s", array(get_query_var('cat'), 'category')); $term_taxonomy_id = $wpdb->get_var($term_taxonomy_id_prepared); $trid = $sitepress->get_element_trid($term_taxonomy_id, 'tax_category'); $translations = $this->get_element_translations($trid, 'tax_category', $skip_empty); } elseif (is_tag()) { $skip_empty = false; $term_taxonomy_id_prepared = $wpdb->prepare("SELECT term_taxonomy_id FROM {$wpdb->term_taxonomy} WHERE term_id=%d AND taxonomy=%s", array(get_query_var('tag_id'), 'post_tag')); $term_taxonomy_id = $wpdb->get_var($term_taxonomy_id_prepared); $trid = $sitepress->get_element_trid($term_taxonomy_id, 'tax_post_tag'); $translations = $this->get_element_translations($trid, 'tax_post_tag', $skip_empty); } elseif (is_tax()) { $skip_empty = false; $term_taxonomy_id_prepared = $wpdb->prepare("SELECT term_taxonomy_id FROM {$wpdb->term_taxonomy} WHERE term_id=%d AND taxonomy=%s", array($wp_query->get_queried_object_id(), get_query_var('taxonomy'))); $term_taxonomy_id = $wpdb->get_var($term_taxonomy_id_prepared); if ($this->is_translated_taxonomy(get_query_var('taxonomy'))) { $trid = $this->get_element_trid($term_taxonomy_id, 'tax_' . get_query_var('taxonomy')); $translations = $this->get_element_translations($trid, 'tax_' . get_query_var('taxonomy'), $skip_empty); } else { $translations[$this->get_current_language()] = (object) array('translation_id' => 0, 'language_code' => $this->get_default_language(), 'original' => 1, 'name' => get_query_var('taxonomy'), 'term_id' => $wp_query->get_queried_object_id()); } } elseif (is_archive()) { $translations = array(); } elseif (is_attachment()) { // Exception for attachments. Not translated. $trid = $sitepress->get_element_trid($wp_query->get_queried_object_id(), 'post_attachment'); $translations = $this->get_element_translations($trid, 'post_attachment'); } elseif (is_page() || 'page' == get_option('show_on_front') && (isset($this->wp_query->queried_object_id) && $this->wp_query->queried_object_id == get_option('page_on_front') || isset($this->wp_query->queried_object_id) && $this->wp_query->queried_object_id == get_option('page_for_posts'))) { $trid = $sitepress->get_element_trid($wp_query->get_queried_object_id(), 'post_page'); $translations = $this->get_element_translations($trid, 'post_page'); } elseif (is_singular() && !empty($wp_query->posts)) { $trid = $sitepress->get_element_trid($this->wp_query->post->ID, 'post_' . $wp_query->posts[0]->post_type); $translations = $this->get_element_translations($trid, 'post_' . $wp_query->posts[0]->post_type); } else { $wp_query->is_singular = false; $wp_query->is_archive = false; $wp_query->is_category = false; $wp_query->is_404 = true; } // 2. determine url foreach ($w_active_languages as $k => $lang) { $skip_lang = false; if (is_singular() || !empty($this->wp_query->queried_object_id) && $this->wp_query->queried_object_id == get_option('page_for_posts')) { $this_lang_tmp = $this->this_lang; $this->this_lang = $lang['code']; $lang_page_on_front = get_option('page_on_front'); $lang_page_for_posts = get_option('page_for_posts'); if ($lang_page_on_front && $lang['code'] != $default_language) { $lang_page_on_front = icl_object_id($lang_page_on_front, 'page', false, $lang['code']); } if ($lang_page_for_posts && $lang['code'] != $default_language) { $lang_page_for_posts = icl_object_id($lang_page_for_posts, 'page', false, $lang['code']); } if ('page' == get_option('show_on_front') && !empty($translations[$lang['code']]) && $translations[$lang['code']]->element_id == $lang_page_on_front) { $lang['translated_url'] = $this->language_url($lang['code']); } elseif ('page' == get_option('show_on_front') && !empty($translations[$lang['code']]) && $translations[$lang['code']]->element_id && $translations[$lang['code']]->element_id == $lang_page_for_posts) { if ($lang_page_for_posts) { $lang['translated_url'] = get_permalink($lang_page_for_posts); } else { $lang['translated_url'] = $this->language_url($lang['code']); } } else { if (!empty($translations[$lang['code']]) && isset($translations[$lang['code']]->post_title)) { $lang['translated_url'] = get_permalink($translations[$lang['code']]->element_id); $lang['missing'] = 0; } else { if ($icl_lso_link_empty) { if (!empty($template_args['link_empty_to'])) { $lang['translated_url'] = str_replace('{%lang}', $lang['code'], $template_args['link_empty_to']); } else { $lang['translated_url'] = $this->language_url($lang['code']); } } else { $skip_lang = true; } $lang['missing'] = 1; } } $this->this_lang = $this_lang_tmp; } elseif (is_category()) { if (isset($translations[$lang['code']])) { global $icl_adjust_id_url_filter_off; // force the category_link_adjust_id to not modify this $icl_adjust_id_url_filter_off = true; $lang['translated_url'] = get_category_link($translations[$lang['code']]->term_id); $icl_adjust_id_url_filter_off = false; // restore default bahavior $lang['missing'] = 0; } else { if ($icl_lso_link_empty) { if (!empty($template_args['link_empty_to'])) { $lang['translated_url'] = str_replace('{%lang}', $lang['code'], $template_args['link_empty_to']); } else { $lang['translated_url'] = $this->language_url($lang['code']); } } else { // dont skip the currrent language if ($current_language != $lang['code']) { $skip_lang = true; } } $lang['missing'] = 1; } } elseif (is_tax()) { if (isset($translations[$lang['code']])) { global $icl_adjust_id_url_filter_off; // force the category_link_adjust_id to not modify this $icl_adjust_id_url_filter_off = true; $lang['translated_url'] = get_term_link((int) $translations[$lang['code']]->term_id, get_query_var('taxonomy')); $icl_adjust_id_url_filter_off = false; // restore default bahavior $lang['missing'] = 0; } else { if ($icl_lso_link_empty) { if (!empty($template_args['link_empty_to'])) { $lang['translated_url'] = str_replace('{%lang}', $lang['code'], $template_args['link_empty_to']); } else { $lang['translated_url'] = $this->language_url($lang['code']); } } else { // dont skip the currrent language if ($current_language != $lang['code']) { $skip_lang = true; } } $lang['missing'] = 1; } } elseif (is_tag()) { if (isset($translations[$lang['code']])) { global $icl_adjust_id_url_filter_off; // force the category_link_adjust_id to not modify this $icl_adjust_id_url_filter_off = true; $lang['translated_url'] = get_tag_link($translations[$lang['code']]->term_id); $icl_adjust_id_url_filter_off = false; // restore default bahavior $lang['missing'] = 0; } else { if ($icl_lso_link_empty) { if (!empty($template_args['link_empty_to'])) { $lang['translated_url'] = str_replace('{%lang}', $lang['code'], $template_args['link_empty_to']); } else { $lang['translated_url'] = $this->language_url($lang['code']); } } else { // dont skip the currrent language if ($current_language != $lang['code']) { $skip_lang = true; } } $lang['missing'] = 1; } } elseif (is_author()) { global $authordata, $wp_query; if (empty($authordata)) { $authordata = get_userdata(get_query_var('author')); } $post_type = get_query_var('post_type') ? get_query_var('post_type') : 'post'; if ($wpdb->get_var("SELECT COUNT(p.ID) FROM {$wpdb->posts} p\r\n\t\t\t\t\t\tJOIN {$wpdb->prefix}icl_translations t ON p.ID=t.element_id AND t.element_type = 'post_{$post_type}'\r\n\t\t\t\t\t\tWHERE p.post_author='{$authordata->ID}' AND post_type='{$post_type}' AND post_status='publish' AND language_code='{$lang['code']}'")) { remove_filter('home_url', array($this, 'home_url'), 1, 4); remove_filter('author_link', array($this, 'author_link')); $author_url = get_author_posts_url($authordata->ID); add_filter('home_url', array($this, 'home_url'), 1, 4); add_filter('author_link', array($this, 'author_link')); $lang['translated_url'] = $this->convert_url($author_url, $lang['code']); $lang['missing'] = 0; } else { if ($icl_lso_link_empty) { if (!empty($template_args['link_empty_to'])) { $lang['translated_url'] = str_replace('{%lang}', $lang['code'], $template_args['link_empty_to']); } else { $lang['translated_url'] = $this->language_url($lang['code']); } } else { // dont skip the currrent language if ($current_language != $lang['code']) { $skip_lang = true; } } $lang['missing'] = 1; } } elseif (is_archive() && !is_tag()) { global $icl_archive_url_filter_off; $icl_archive_url_filter_off = true; if ($this->wp_query->is_year) { if (isset($this->wp_query->query_vars['m']) && !$this->wp_query->query_vars['year']) { $this->wp_query->query_vars['year'] = substr($this->wp_query->query_vars['m'], 0, 4); } $lang['translated_url'] = $this->archive_url(get_year_link($this->wp_query->query_vars['year']), $lang['code']); } elseif ($this->wp_query->is_month) { if (isset($this->wp_query->query_vars['m']) && !$this->wp_query->query_vars['year']) { $this->wp_query->query_vars['year'] = substr($this->wp_query->query_vars['m'], 0, 4); $this->wp_query->query_vars['monthnum'] = substr($this->wp_query->query_vars['m'], 4, 2); } else { if ($icl_lso_link_empty) { if (!empty($template_args['link_empty_to'])) { $lang['translated_url'] = str_replace('{%lang}', $lang['code'], $template_args['link_empty_to']); } else { $lang['translated_url'] = $this->language_url($lang['code']); } } $lang['missing'] = 1; } $lang['translated_url'] = $this->archive_url(get_month_link($this->wp_query->query_vars['year'], $this->wp_query->query_vars['monthnum']), $lang['code']); } elseif ($this->wp_query->is_day) { if (isset($this->wp_query->query_vars['m']) && !$this->wp_query->query_vars['year']) { $this->wp_query->query_vars['year'] = substr($this->wp_query->query_vars['m'], 0, 4); $this->wp_query->query_vars['monthnum'] = substr($this->wp_query->query_vars['m'], 4, 2); $this->wp_query->query_vars['day'] = substr($this->wp_query->query_vars['m'], 6, 2); gmdate('Y', current_time('timestamp')); //force wp_timezone_override_offset to be called } $lang['translated_url'] = $this->archive_url(get_day_link($this->wp_query->query_vars['year'], $this->wp_query->query_vars['monthnum'], $this->wp_query->query_vars['day']), $lang['code']); } else { if (isset($this->wp_query->query_vars['post_type'])) { do_action('_icl_before_archive_url', $this->wp_query->query_vars['post_type'], $lang['code']); if ($this->is_translated_post_type($this->wp_query->query_vars['post_type']) && function_exists('get_post_type_archive_link')) { remove_filter('post_type_archive_link', array($this, 'post_type_archive_link_filter'), 10); $lang['translated_url'] = $this->convert_url(get_post_type_archive_link($this->wp_query->query_vars['post_type']), $lang['code']); } else { if ($k != $this->get_default_language()) { $skip_lang = true; unset($w_active_languages[$k]); } } do_action('_icl_after_archive_url', $this->wp_query->query_vars['post_type'], $lang['code']); } } add_filter('post_type_archive_link', array($this, 'post_type_archive_link_filter'), 10, 2); $icl_archive_url_filter_off = false; } elseif (is_search()) { $url_glue = strpos($this->language_url($lang['code']), '?') === false ? '?' : '&'; $lang['translated_url'] = $this->language_url($lang['code']) . $url_glue . 's=' . urlencode($wp_query->query['s']); } else { global $icl_language_switcher_preview; if ($icl_lso_link_empty || is_home() || is_404() || 'page' == get_option('show_on_front') && ($this->wp_query->queried_object_id == get_option('page_on_front') || $this->wp_query->queried_object_id == get_option('page_for_posts')) || $icl_language_switcher_preview || WPML_Root_Page::is_current_request_root()) { $lang['translated_url'] = $this->language_url($lang['code']); $skip_lang = false; } else { $skip_lang = true; unset($w_active_languages[$k]); } } if (!$skip_lang) { $w_active_languages[$k] = $lang; } else { unset($w_active_languages[$k]); } } // 3. foreach ($w_active_languages as $k => $v) { $lang_code = $w_active_languages[$k]['language_code'] = $w_active_languages[$k]['code']; unset($w_active_languages[$k]['code']); $native_name = $this->get_display_language_name($lang_code, $lang_code); if (!$native_name) { $native_name = $w_active_languages[$k]['english_name']; } $w_active_languages[$k]['native_name'] = $native_name; $translated_name = $this->get_display_language_name($lang_code, $current_language); if (!$translated_name) { $translated_name = $w_active_languages[$k]['english_name']; } $w_active_languages[$k]['translated_name'] = $translated_name; unset($w_active_languages[$k]['display_name']); unset($w_active_languages[$k]['english_name']); if (isset($w_active_languages[$k]['translated_url'])) { $w_active_languages[$k]['url'] = $w_active_languages[$k]['translated_url']; unset($w_active_languages[$k]['translated_url']); } else { $w_active_languages[$k]['url'] = $this->language_url($k); } $flag = $this->get_flag($lang_code); if ($flag->from_template) { $wp_upload_dir = wp_upload_dir(); $flag_url = $wp_upload_dir['baseurl'] . '/flags/' . $flag->flag; } else { $flag_url = ICL_PLUGIN_URL . '/res/flags/' . $flag->flag; } $w_active_languages[$k]['country_flag_url'] = $flag_url; $w_active_languages[$k]['active'] = $current_language == $lang_code ? '1' : 0; } // 4. pass GET parameters $parameters_copied = apply_filters('icl_lang_sel_copy_parameters', array_map('trim', explode(',', $this->settings['icl_lang_sel_copy_parameters']))); if ($parameters_copied) { foreach ($_GET as $k => $v) { if (in_array($k, $parameters_copied)) { $gets_passed[$k] = $v; } } } if (!empty($gets_passed)) { $gets_passed = http_build_query($gets_passed); foreach ($w_active_languages as $code => $al) { if (empty($al['missing'])) { $glue = false !== strpos($w_active_languages[$code]['url'], '?') ? '&' : '?'; $w_active_languages[$code]['url'] .= $glue . $gets_passed; } } } // restore current $wp_query unset($wp_query); global $wp_query; // make it global again after unset $wp_query = clone $_wp_query_back; unset($_wp_query_back); $w_active_languages = apply_filters('icl_ls_languages', $w_active_languages); $w_active_languages = $this->sort_ls_languages($w_active_languages, $template_args); // Change the url, in case languages in subdomains are set. if ($this->settings['language_negotiation_type'] == 2) { foreach ($w_active_languages as $lang => $element) { $w_active_languages[$lang]['url'] = $this->convert_url($element['url'], $lang); } } wp_reset_query(); wp_cache_set($cache_key, $w_active_languages, $cache_group); return $w_active_languages; }
/** * Redirects incoming links to the proper URL based on the site url. * * Search engines consider www.somedomain.com and somedomain.com to be two * different URLs when they both go to the same location. This SEO enhancement * prevents penality for duplicate content by redirecting all incoming links to * one or the other. * * Prevents redirection for feeds, trackbacks, searches, comment popup, and * admin URLs. Does not redirect on IIS, page/post previews, and on form data. * * Will also attempt to find the correct link when a user enters a URL that does * not exist based on exact WordPress query. Will instead try to parse the URL * or query in an attempt to figure the correct page to go to. * * @since 2.3.0 * @uses $wp_rewrite * @uses $is_IIS * * @param string $requested_url Optional. The URL that was requested, used to * figure if redirect is needed. * @param bool $do_redirect Optional. Redirect to the new URL. * @return null|false|string Null, if redirect not needed. False, if redirect * not needed or the string of the URL */ function redirect_canonical($requested_url=null, $do_redirect=true) { global $wp_rewrite, $is_IIS, $wp_query, $wpdb; if ( is_trackback() || is_search() || is_comments_popup() || is_admin() || $is_IIS || ( isset($_POST) && count($_POST) ) || is_preview() || is_robots() ) return; if ( !$requested_url ) { // build the URL in the address bar $requested_url = ( !empty($_SERVER['HTTPS'] ) && strtolower($_SERVER['HTTPS']) == 'on' ) ? 'https://' : 'http://'; $requested_url .= $_SERVER['HTTP_HOST']; $requested_url .= $_SERVER['REQUEST_URI']; } $original = @parse_url($requested_url); if ( false === $original ) return; // Some PHP setups turn requests for / into /index.php in REQUEST_URI // See: http://trac.wordpress.org/ticket/5017 // See: http://trac.wordpress.org/ticket/7173 // Disabled, for now: // $original['path'] = preg_replace('|/index\.php$|', '/', $original['path']); $redirect = $original; $redirect_url = false; // Notice fixing if ( !isset($redirect['path']) ) $redirect['path'] = ''; if ( !isset($redirect['query']) ) $redirect['query'] = ''; if ( is_singular() && 1 > $wp_query->post_count && ($id = get_query_var('p')) ) { $vars = $wpdb->get_results( $wpdb->prepare("SELECT post_type, post_parent FROM $wpdb->posts WHERE ID = %d", $id) ); if ( isset($vars[0]) && $vars = $vars[0] ) { if ( 'revision' == $vars->post_type && $vars->post_parent > 0 ) $id = $vars->post_parent; if ( $redirect_url = get_permalink($id) ) $redirect['query'] = remove_query_arg(array('p', 'page_id', 'attachment_id'), $redirect['query']); } } // These tests give us a WP-generated permalink if ( is_404() ) { $redirect_url = redirect_guess_404_permalink(); } elseif ( is_object($wp_rewrite) && $wp_rewrite->using_permalinks() ) { // rewriting of old ?p=X, ?m=2004, ?m=200401, ?m=20040101 if ( is_single() && !empty($_GET['p']) && ! $redirect_url ) { if ( $redirect_url = get_permalink(get_query_var('p')) ) $redirect['query'] = remove_query_arg('p', $redirect['query']); if ( get_query_var( 'page' ) ) { $redirect_url = trailingslashit( $redirect_url ) . user_trailingslashit( get_query_var( 'page' ), 'single_paged' ); $redirect['query'] = remove_query_arg( 'page', $redirect['query'] ); } } elseif ( is_page() && !empty($_GET['page_id']) && ! $redirect_url ) { if ( $redirect_url = get_permalink(get_query_var('page_id')) ) $redirect['query'] = remove_query_arg('page_id', $redirect['query']); } elseif ( !empty($_GET['m']) && ( is_year() || is_month() || is_day() ) ) { $m = get_query_var('m'); switch ( strlen($m) ) { case 4: // Yearly $redirect_url = get_year_link($m); break; case 6: // Monthly $redirect_url = get_month_link( substr($m, 0, 4), substr($m, 4, 2) ); break; case 8: // Daily $redirect_url = get_day_link(substr($m, 0, 4), substr($m, 4, 2), substr($m, 6, 2)); break; } if ( $redirect_url ) $redirect['query'] = remove_query_arg('m', $redirect['query']); // now moving on to non ?m=X year/month/day links } elseif ( is_day() && get_query_var('year') && get_query_var('monthnum') && !empty($_GET['day']) ) { if ( $redirect_url = get_day_link(get_query_var('year'), get_query_var('monthnum'), get_query_var('day')) ) $redirect['query'] = remove_query_arg(array('year', 'monthnum', 'day'), $redirect['query']); } elseif ( is_month() && get_query_var('year') && !empty($_GET['monthnum']) ) { if ( $redirect_url = get_month_link(get_query_var('year'), get_query_var('monthnum')) ) $redirect['query'] = remove_query_arg(array('year', 'monthnum'), $redirect['query']); } elseif ( is_year() && !empty($_GET['year']) ) { if ( $redirect_url = get_year_link(get_query_var('year')) ) $redirect['query'] = remove_query_arg('year', $redirect['query']); } elseif ( is_category() && !empty($_GET['cat']) ) { if ( $redirect_url = get_category_link(get_query_var('cat')) ) $redirect['query'] = remove_query_arg('cat', $redirect['query']); } elseif ( is_author() && !empty($_GET['author']) ) { $author = get_userdata(get_query_var('author')); if ( false !== $author && $redirect_url = get_author_posts_url($author->ID, $author->user_nicename) ) $redirect['query'] = remove_query_arg('author', $redirect['author']); } // paging and feeds if ( get_query_var('paged') || is_feed() || get_query_var('cpage') ) { if ( !$redirect_url ) $redirect_url = $requested_url; $paged_redirect = @parse_url($redirect_url); while ( preg_match( '#/page/[0-9]+?(/+)?$#', $paged_redirect['path'] ) || preg_match( '#/(comments/?)?(feed|rss|rdf|atom|rss2)(/+)?$#', $paged_redirect['path'] ) || preg_match( '#/comment-page-[0-9]+(/+)?$#', $paged_redirect['path'] ) ) { // Strip off paging and feed $paged_redirect['path'] = preg_replace('#/page/[0-9]+?(/+)?$#', '/', $paged_redirect['path']); // strip off any existing paging $paged_redirect['path'] = preg_replace('#/(comments/?)?(feed|rss2?|rdf|atom)(/+)?$#', '/', $paged_redirect['path']); // strip off feed endings $paged_redirect['path'] = preg_replace('#/comment-page-[0-9]+?(/+)?$#', '/', $paged_redirect['path']); // strip off any existing comment paging } $addl_path = ''; if ( is_feed() ) { $addl_path = !empty( $addl_path ) ? trailingslashit($addl_path) : ''; if ( get_query_var( 'withcomments' ) ) $addl_path .= 'comments/'; $addl_path .= user_trailingslashit( 'feed/' . ( ( 'rss2' == get_query_var('feed') || 'feed' == get_query_var('feed') ) ? '' : get_query_var('feed') ), 'feed' ); $redirect['query'] = remove_query_arg( 'feed', $redirect['query'] ); } if ( get_query_var('paged') > 0 ) { $paged = get_query_var('paged'); $redirect['query'] = remove_query_arg( 'paged', $redirect['query'] ); if ( !is_feed() ) { if ( $paged > 1 && !is_single() ) { $addl_path = ( !empty( $addl_path ) ? trailingslashit($addl_path) : '' ) . user_trailingslashit("page/$paged", 'paged'); } elseif ( !is_single() ) { $addl_path = ( !empty( $addl_path ) ? trailingslashit($addl_path) : '' ) . user_trailingslashit($paged_redirect['path'], 'paged'); } } elseif ( $paged > 1 ) { $redirect['query'] = add_query_arg( 'paged', $paged, $redirect['query'] ); } } if ( get_option('page_comments') && ( ( 'newest' == get_option('default_comments_page') && get_query_var('cpage') > 0 ) || ( 'newest' != get_option('default_comments_page') && get_query_var('cpage') > 1 ) ) ) { $addl_path = ( !empty( $addl_path ) ? trailingslashit($addl_path) : '' ) . user_trailingslashit( 'comment-page-' . get_query_var('cpage'), 'commentpaged' ); $redirect['query'] = remove_query_arg( 'cpage', $redirect['query'] ); } $paged_redirect['path'] = user_trailingslashit( preg_replace('|/index.php/?$|', '/', $paged_redirect['path']) ); // strip off trailing /index.php/ if ( !empty( $addl_path ) && $wp_rewrite->using_index_permalinks() && strpos($paged_redirect['path'], '/index.php/') === false ) $paged_redirect['path'] = trailingslashit($paged_redirect['path']) . 'index.php/'; if ( !empty( $addl_path ) ) $paged_redirect['path'] = trailingslashit($paged_redirect['path']) . $addl_path; $redirect_url = $paged_redirect['scheme'] . '://' . $paged_redirect['host'] . $paged_redirect['path']; $redirect['path'] = $paged_redirect['path']; } } // tack on any additional query vars $redirect['query'] = preg_replace( '#^\??&*?#', '', $redirect['query'] ); if ( $redirect_url && !empty($redirect['query']) ) { if ( strpos($redirect_url, '?') !== false ) $redirect_url .= '&'; else $redirect_url .= '?'; $redirect_url .= $redirect['query']; } if ( $redirect_url ) $redirect = @parse_url($redirect_url); // www.example.com vs example.com $user_home = @parse_url(get_option('home')); if ( !empty($user_home['host']) ) $redirect['host'] = $user_home['host']; if ( empty($user_home['path']) ) $user_home['path'] = '/'; // Handle ports if ( !empty($user_home['port']) ) $redirect['port'] = $user_home['port']; else unset($redirect['port']); // trailing /index.php $redirect['path'] = preg_replace('|/index.php/*?$|', '/', $redirect['path']); // Remove trailing spaces from the path $redirect['path'] = preg_replace( '#(%20| )+$#', '', $redirect['path'] ); if ( !empty( $redirect['query'] ) ) { // Remove trailing spaces from certain terminating query string args $redirect['query'] = preg_replace( '#((p|page_id|cat|tag)=[^&]*?)(%20| )+$#', '$1', $redirect['query'] ); // Clean up empty query strings $redirect['query'] = trim(preg_replace( '#(^|&)(p|page_id|cat|tag)=?(&|$)#', '&', $redirect['query']), '&'); // Remove redundant leading ampersands $redirect['query'] = preg_replace( '#^\??&*?#', '', $redirect['query'] ); } // strip /index.php/ when we're not using PATHINFO permalinks if ( !$wp_rewrite->using_index_permalinks() ) $redirect['path'] = str_replace('/index.php/', '/', $redirect['path']); // trailing slashes if ( is_object($wp_rewrite) && $wp_rewrite->using_permalinks() && !is_404() && (!is_front_page() || ( is_front_page() && (get_query_var('paged') > 1) ) ) ) { $user_ts_type = ''; if ( get_query_var('paged') > 0 ) { $user_ts_type = 'paged'; } else { foreach ( array('single', 'category', 'page', 'day', 'month', 'year', 'home') as $type ) { $func = 'is_' . $type; if ( call_user_func($func) ) { $user_ts_type = $type; break; } } } $redirect['path'] = user_trailingslashit($redirect['path'], $user_ts_type); } elseif ( is_front_page() ) { $redirect['path'] = trailingslashit($redirect['path']); } // Always trailing slash the Front Page URL if ( trailingslashit( $redirect['path'] ) == trailingslashit( $user_home['path'] ) ) $redirect['path'] = trailingslashit($redirect['path']); // Ignore differences in host capitalization, as this can lead to infinite redirects // Only redirect no-www <=> yes-www if ( strtolower($original['host']) == strtolower($redirect['host']) || ( strtolower($original['host']) != 'www.' . strtolower($redirect['host']) && 'www.' . strtolower($original['host']) != strtolower($redirect['host']) ) ) $redirect['host'] = $original['host']; $compare_original = array($original['host'], $original['path']); if ( !empty( $original['port'] ) ) $compare_original[] = $original['port']; if ( !empty( $original['query'] ) ) $compare_original[] = $original['query']; $compare_redirect = array($redirect['host'], $redirect['path']); if ( !empty( $redirect['port'] ) ) $compare_redirect[] = $redirect['port']; if ( !empty( $redirect['query'] ) ) $compare_redirect[] = $redirect['query']; if ( $compare_original !== $compare_redirect ) { $redirect_url = $redirect['scheme'] . '://' . $redirect['host']; if ( !empty($redirect['port']) ) $redirect_url .= ':' . $redirect['port']; $redirect_url .= $redirect['path']; if ( !empty($redirect['query']) ) $redirect_url .= '?' . $redirect['query']; } if ( !$redirect_url || $redirect_url == $requested_url ) return false; // Note that you can use the "redirect_canonical" filter to cancel a canonical redirect for whatever reason by returning FALSE $redirect_url = apply_filters('redirect_canonical', $redirect_url, $requested_url); if ( !$redirect_url || $redirect_url == $requested_url ) // yes, again -- in case the filter aborted the request return false; if ( $do_redirect ) { // protect against chained redirects if ( !redirect_canonical($redirect_url, false) ) { wp_redirect($redirect_url, 301); exit(); } else { // Debug // die("1: $redirect_url<br />2: " . redirect_canonical( $redirect_url, false ) ); return false; } } else { return $redirect_url; } }
function get_the_breadcrumb() { global $wp_query; $queried_object = get_queried_object(); $breadcrumb = ''; $delimiter = ' / '; $before = ' '; $after = ' '; if (!is_home()) { $breadcrumb .= '<a href="' . home_url() . '" title="' . get_bloginfo('name') . '">' . __('Home', SH_NAME) . '</a>'; /** If category or single post */ if (is_category()) { $cat_obj = $wp_query->get_queried_object(); $this_category = get_category($cat_obj->term_id); if ($this_category->parent != 0) { $parent_category = get_category($this_category->parent); $breadcrumb .= get_category_parents($parent_category, TRUE, $delimiter); } $breadcrumb .= $delimiter . $before . '<a href="' . get_category_link(get_query_var('cat')) . '">' . single_cat_title('', FALSE) . '</a>' . $after; } elseif (is_tax()) { $breadcrumb .= $delimiter . $before . '<a href="' . get_term_link($queried_object) . '">' . $queried_object->name . '</a>' . $after; } elseif (is_page()) { global $post; if ($post->post_parent) { $anc = get_post_ancestors($post->ID); foreach ($anc as $ancestor) { $breadcrumb .= $delimiter . $before . '<a href="' . get_permalink($ancestor) . '">' . get_the_title($ancestor) . '</a>' . $after; } $breadcrumb .= $delimiter . $before . get_the_title($post->ID) . $after; } else { $breadcrumb .= $delimiter . $before . '' . get_the_title() . '' . $after; } } elseif (is_singular()) { if ($category = wp_get_object_terms(get_the_ID(), get_taxonomies())) { if (!is_wp_error($category)) { $breadcrumb .= $delimiter . $before . '<a href="' . get_term_link(sh_set($category, '0')) . '">' . sh_set(sh_set($category, '0'), 'name') . '</a>' . $after; $breadcrumb .= $delimiter . $before . '' . get_the_title() . '' . $after; } else { $breadcrumb .= $delimiter . $before . '' . get_the_title() . '' . $after; } } else { $breadcrumb .= $delimiter . $before . '' . get_the_title() . '' . $after; } } elseif (is_tag()) { $breadcrumb .= $delimiter . $before . '<a href="' . get_term_link($queried_object) . '">' . single_tag_title('', FALSE) . '</a>' . $after; } elseif (is_day()) { $breadcrumb .= $delimiter . $before . '<a href="">' . __('Archive for ', SH_NAME) . get_the_time('F jS, Y') . '</a>' . $after; } elseif (is_month()) { $breadcrumb .= $delimiter . $before . '<a href="' . get_month_link(get_the_time('Y'), get_the_time('m')) . '">' . __('Archive for ', SH_NAME) . get_the_time('F, Y') . '</a>' . $after; } elseif (is_year()) { $breadcrumb .= $delimiter . $before . '<a href="' . get_year_link(get_the_time('Y')) . '">' . __('Archive for ', SH_NAME) . get_the_time('Y') . '</a>' . $after; } elseif (is_author()) { $breadcrumb .= $delimiter . $before . '<a href="' . esc_url(get_author_posts_url(get_the_author_meta("ID"))) . '">' . __('Archive for ', SH_NAME) . get_the_author() . '</a>' . $after; } elseif (is_search()) { $breadcrumb .= $delimiter . $before . '' . __('Search Results for ', SH_NAME) . get_search_query() . '' . $after; } elseif (is_404()) { $breadcrumb .= $delimiter . $before . '' . __('404 - Not Found', SH_NAME) . '' . $after; } elseif (is_post_type_archive('product')) { $shop_page_id = woocommerce_get_page_id('shop'); if (get_option('page_on_front') !== $shop_page_id) { $shop_page = get_post($shop_page_id); $_name = woocommerce_get_page_id('shop') ? get_the_title(woocommerce_get_page_id('shop')) : ''; if (!$_name) { $product_post_type = get_post_type_object('product'); $_name = $product_post_type->labels->singular_name; } if (is_search()) { $breadcrumb .= $before . '<a href="' . get_post_type_archive_link('product') . '">' . $_name . '</a>' . $delimiter . esc_html__('Search results for “', 'woocommerce') . get_search_query() . '”' . $after; } elseif (is_paged()) { $breadcrumb .= $before . '<a href="' . get_post_type_archive_link('product') . '">' . $_name . '</a>' . $after; } else { $breadcrumb .= $before . $_name . $after; } } } else { $breadcrumb .= $delimiter . $before . '<a href="' . get_permalink() . '">' . get_the_title() . '</a>' . $after; } /** Default value */ } return $breadcrumb; }
/** * Print the breadcrumb. * * @param string $sep * @return string * @since 1.0.0 */ function yit_breadcrumb($delimiter = '»') { global $wp_query; $post = $wp_query->get_queried_object(); $home = apply_filters('yit_homepage_breadcrumb_text', __('Home Page', 'yit')); // text for the 'Home' link $before = '<a class="no-link current" href="#">'; // tag before the current crumb $after = '</a>'; // tag after the current crumb echo '<p id="yit-breadcrumb" itemprop="breadcrumb">'; $homeLink = apply_filters('yit_breadcrumb_homelink', YIT_SITE_URL); if (!is_home() && !is_front_page()) { echo '<a class="home" href="' . $homeLink . '">' . $home . '</a> ' . $delimiter . ' '; } if (is_category()) { $cat_obj = $post; $thisCat = $cat_obj->term_id; $thisCat = get_category($thisCat); $parentCat = get_category($thisCat->parent); if ($thisCat->parent != 0) { echo get_category_parents($parentCat, true, ' ' . $delimiter . ' '); } echo $before . sprintf(__('Archive by category "%s"', 'yit'), single_cat_title('', false)) . $after; } elseif (is_day()) { echo '<a href="' . get_year_link(get_the_time('Y')) . '">' . get_the_time('Y') . '</a> ' . $delimiter . ' '; echo '<a href="' . get_month_link(get_the_time('Y'), get_the_time('m')) . '">' . get_the_time('F') . '</a> ' . $delimiter . ' '; echo $before . get_the_time('d') . $after; } elseif (is_month()) { echo '<a href="' . get_year_link(get_the_time('Y')) . '">' . get_the_time('Y') . '</a> ' . $delimiter . ' '; echo $before . get_the_time('F') . $after; } elseif (is_year()) { echo $before . get_the_time('Y') . $after; } elseif (is_single() && !is_attachment()) { if (get_post_type() != 'post') { $post_type = get_post_type_object(get_post_type()); $slug = $post_type->rewrite; echo '<a href="' . $homeLink . '/' . $slug['slug'] . '/">' . $post_type->labels->singular_name . '</a> ' . $delimiter . ' '; echo $before . get_the_title() . $after; } else { $cat = get_the_category(); $cat = $cat[0]; if (!empty($cat)) { echo get_category_parents($cat, true, ' ' . $delimiter . ' '); } echo $before . get_the_title() . $after; } } elseif (!is_single() && !is_page() && get_post_type() != 'post' && !is_404() & !is_home()) { $post_type = get_post_type_object(get_post_type()); echo $before . $post_type->labels->singular_name . $after; } elseif (is_attachment()) { $parent = get_post($post->post_parent); if ($parent->post_type == 'page' || $parent->post_type == 'post') { $cat = get_the_category($parent->ID); $cat = $cat[0]; echo get_category_parents($cat, true, ' ' . $delimiter . ' '); } echo '<a href="' . get_permalink($parent) . '">' . $parent->post_title . '</a> ' . $delimiter . ' '; echo $before . get_the_title() . $after; } elseif (is_page() && !$post->post_parent) { echo $before . ucfirst(strtolower(get_the_title())) . $after; } elseif (is_page() && $post->post_parent) { $parent_id = $post->post_parent; $breadcrumbs = array(); while ($parent_id) { $page = get_page($parent_id); $breadcrumbs[] = '<a href="' . get_permalink($page->ID) . '">' . get_the_title($page->ID) . '</a>'; $parent_id = $page->post_parent; } $breadcrumbs = array_reverse($breadcrumbs); foreach ($breadcrumbs as $crumb) { echo $crumb . ' ' . $delimiter . ' '; } echo $before . yit_remove_chars_title(get_the_title()) . $after; } elseif (is_search()) { echo $before . sprintf(__('Search results for "%s"', 'yit'), get_search_query()) . $after; } elseif (is_tag()) { echo $before . sprintf(__('Posts tagged "%s"', 'yit'), single_tag_title('', false)) . $after; } elseif (is_author()) { global $author; $userdata = get_userdata($author); echo $before . sprintf(__('Articles posted by %s', 'yit'), $userdata->display_name) . $after; } elseif (is_404()) { echo $before . __('Error 404', 'yit') . $after; } elseif (is_home()) { echo $before . apply_filters('yit_posts_page_breadcrumb', __('Home', 'yit')) . $after; } if (get_query_var('paged')) { if (is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author()) { echo ' ('; } echo ' - ' . $before . __('Page', 'yit') . ' ' . get_query_var('paged') . $after; if (is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author()) { echo ')'; } } echo '</p>'; }
/** * Turns %tag% from permalink structures into usable links for the breadcrumb trail. This feels kind of * hackish for now because we're checking for specific %tag% examples and only doing it for the 'post' * post type. In the future, maybe it'll handle a wider variety of possibilities, especially for custom post * types. * * @since 0.6.0 * @access public * @param int $post_id ID of the post whose parents we want. * @param string $path Path of a potential parent page. * @param array $args Mixed arguments for the menu. * @return array */ public function map_rewrite_tags($post_id, $path) { /* Get the post based on the post ID. */ $post = get_post($post_id); /* If no post is returned, an error is returned, or the post does not have a 'post' post type, return. */ if (empty($post) || is_wp_error($post) || 'post' !== $post->post_type) { return $trail; } /* Trim '/' from both sides of the $path. */ $path = trim($path, '/'); /* Split the $path into an array of strings. */ $matches = explode('/', $path); /* If matches are found for the path. */ if (is_array($matches)) { /* Loop through each of the matches, adding each to the $trail array. */ foreach ($matches as $match) { /* Trim any '/' from the $match. */ $tag = trim($match, '/'); /* If using the %year% tag, add a link to the yearly archive. */ if ('%year%' == $tag) { $this->items[] = '<a href="' . esc_url(get_year_link(get_the_time('Y', $post_id))) . '">' . sprintf($this->args['labels']['archive_year'], get_the_time(_x('Y', 'yearly archives date format', 'toivo-lite'))) . '</a>'; } elseif ('%monthnum%' == $tag) { $this->items[] = '<a href="' . esc_url(get_month_link(get_the_time('Y', $post_id), get_the_time('m', $post_id))) . '">' . sprintf($this->args['labels']['archive_month'], get_the_time(_x('F', 'monthly archives date format', 'toivo-lite'))) . '</a>'; } elseif ('%day%' == $tag) { $this->items[] = '<a href="' . esc_url(get_day_link(get_the_time('Y', $post_id), get_the_time('m', $post_id), get_the_time('d', $post_id))) . '">' . sprintf($this->args['labels']['archive_day'], get_the_time(_x('j', 'daily archives date format', 'toivo-lite'))) . '</a>'; } elseif ('%author%' == $tag) { $this->items[] = '<a href="' . esc_url(get_author_posts_url($post->post_author)) . '">' . get_the_author_meta('display_name', $post->post_author) . '</a>'; } elseif ('%category%' == $tag) { /* Force override terms in this post type. */ $this->args['post_taxonomy'][$post->post_type] = false; /* Get the post categories. */ $terms = get_the_category($post_id); /* Check that categories were returned. */ if ($terms) { /* Sort the terms by ID and get the first category. */ usort($terms, '_usort_terms_by_ID'); $term = get_term($terms[0], 'category'); /* If the category has a parent, add the hierarchy to the trail. */ if (0 < $term->parent) { $this->do_term_parents($term->parent, 'category'); } /* Add the category archive link to the trail. */ $this->items[] = '<a href="' . esc_url(get_term_link($term, 'category')) . '">' . $term->name . '</a>'; } } } } }
/** * Returns a list of special pages that can be configured by this rule. * * @since 1.0.0 * * @return array List of special pages. */ protected function get_special_pages() { if (!is_array($this->_content)) { $this->_content = array(); $front_type = get_option('show_on_front'); $front_url = MS_Helper_Utility::home_url('/'); if ('page' === $front_type) { $home_url = get_permalink(get_option('page_for_posts')); } else { $home_url = $front_url; } $arch_year = get_year_link(''); $arch_month = get_month_link('', ''); $arch_day = get_day_link('', '', ''); $arch_hour = esc_url_raw(add_query_arg('hour', '15', $arch_day)); // Archive pages $this->_content['archive'] = (object) array('label' => __('Any Archive page', 'membership2'), 'url' => ''); $this->_content['author'] = (object) array('label' => __('Author Archives', 'membership2'), 'url' => ''); $this->_content['date'] = (object) array('label' => __('Any Date or Time Archive', 'membership2'), 'url' => ''); $this->_content['year'] = (object) array('label' => __('Archive: Year', 'membership2'), 'url' => $arch_year); $this->_content['month'] = (object) array('label' => __('Archive: Month', 'membership2'), 'url' => $arch_month); $this->_content['day'] = (object) array('label' => __('Archive: Day', 'membership2'), 'url' => $arch_day); $this->_content['time'] = (object) array('label' => __('Archive: Time', 'membership2'), 'url' => $arch_hour); // Singular pages $this->_content['front'] = (object) array('label' => __('Front Page', 'membership2'), 'url' => $front_url); $this->_content['home'] = (object) array('label' => __('Blog Index', 'membership2'), 'url' => $home_url); $this->_content['notfound'] = (object) array('label' => __('404 Not Found', 'membership2'), 'url' => ''); $this->_content['search'] = (object) array('label' => __('Search Results', 'membership2'), 'url' => ''); $this->_content['single'] = (object) array('label' => __('Any single page or post', 'membership2'), 'url' => ''); $this->_content['attachment'] = (object) array('label' => __('Any attachment page', 'membership2'), 'url' => ''); } return $this->_content; }
/** * This function normally outputs the canonical but is also used in other places to retrieve * the canonical URL for the current page. * * @param bool $echo Whether or not to output the canonical element. * @param bool $un_paged Whether or not to return the canonical with or without pagination added to the URL. * @param bool $no_override Whether or not to return a manually overridden canonical * * @return string $canonical */ public function canonical($echo = true, $un_paged = false, $no_override = false) { $canonical = false; $skip_pagination = false; // Set decent canonicals for homepage, singulars and taxonomy pages if (is_singular()) { $meta_canon = WPSEO_Meta::get_value('canonical'); if ($no_override === false && $meta_canon !== '') { $canonical = $meta_canon; $skip_pagination = true; } else { $obj = get_queried_object(); $canonical = get_permalink($obj->ID); // Fix paginated pages canonical, but only if the page is truly paginated. if (get_query_var('page') > 1) { global $wp_rewrite; $numpages = substr_count($obj->post_content, '<!--nextpage-->') + 1; if ($numpages && get_query_var('page') <= $numpages) { if (!$wp_rewrite->using_permalinks()) { $canonical = add_query_arg('page', get_query_var('page'), $canonical); } else { $canonical = user_trailingslashit(trailingslashit($canonical) . get_query_var('page')); } } } } unset($meta_canon); } else { if (is_search()) { $canonical = get_search_link(); } elseif (is_front_page()) { $canonical = home_url('/'); } elseif ($this->is_posts_page()) { $canonical = get_permalink(get_option('page_for_posts')); } elseif (is_tax() || is_tag() || is_category()) { $term = get_queried_object(); if ($no_override === false) { $canonical = WPSEO_Taxonomy_Meta::get_term_meta($term, $term->taxonomy, 'canonical'); if (is_string($canonical) && $canonical !== '') { $skip_pagination = true; } } if (!is_string($canonical) || $canonical === '') { $canonical = get_term_link($term, $term->taxonomy); } } elseif (is_post_type_archive()) { $post_type = get_query_var('post_type'); if (is_array($post_type)) { $post_type = reset($post_type); } $canonical = get_post_type_archive_link($post_type); } elseif (is_author()) { $canonical = get_author_posts_url(get_query_var('author'), get_query_var('author_name')); } elseif (is_archive()) { if (is_date()) { if (is_day()) { $canonical = get_day_link(get_query_var('year'), get_query_var('monthnum'), get_query_var('day')); } elseif (is_month()) { $canonical = get_month_link(get_query_var('year'), get_query_var('monthnum')); } elseif (is_year()) { $canonical = get_year_link(get_query_var('year')); } } } } if ($canonical && $un_paged) { return $canonical; } if ($canonical && !$skip_pagination && get_query_var('paged') > 1) { global $wp_rewrite; if (!$wp_rewrite->using_permalinks()) { $canonical = add_query_arg('paged', get_query_var('paged'), $canonical); } else { if (is_front_page()) { $base = $wp_rewrite->using_index_permalinks() ? 'index.php/' : '/'; $canonical = home_url($base); } $canonical = user_trailingslashit(trailingslashit($canonical) . trailingslashit($wp_rewrite->pagination_base) . get_query_var('paged')); } } if ($canonical && 'default' !== $this->options['force_transport']) { $canonical = preg_replace('`^http[s]?`', $this->options['force_transport'], $canonical); } /** * Filter: 'wpseo_canonical' - Allow filtering of the canonical URL put out by WP SEO * * @api string $canonical The canonical URL */ $canonical = apply_filters('wpseo_canonical', $canonical); if (is_string($canonical) && $canonical !== '') { if ($echo !== false) { echo '<link rel="canonical" href="' . esc_url($canonical, null, 'other') . '" />' . "\n"; } else { return $canonical; } } else { return false; } }
/** * Gets the crumbs for a date-based archive. * * @access private * @static * @param array $options * @return array */ private static function get_date_archive_crumbs(array $options) { $crumbs = array(); $date = new DateTime(get_the_date('c')); $last_show = $options['last_show']; if (is_year() && !$last_show) { return $crumbs; } $crumbs[] = new HAG_Crumb($options, $date->format('Y'), get_year_link($date->format('Y')), false, is_year()); if (is_year() || is_month() && !$last_show) { return $crumbs; } $crumbs[] = new HAG_Crumb($options, $date->format('F'), get_month_link($date->format('Y'), $date->format('n')), false, is_month()); if (is_month() || is_day() && !$last_show) { return $crumbs; } $crumbs[] = new HAG_Crumb($options, $date->format('jS'), get_day_link($date->format('Y'), $date->format('n'), $date->format('j')), false, is_day()); return $crumbs; }
function waves_breadcrumbs() { /* === OPTIONS === */ $text['home'] = __('<i class="fa fa-home"></i>', 'waves'); // text for the 'Home' link $text['category'] = __('Archive by Category "%s"', 'waves'); // text for a category page $text['search'] = __('Search Results for "%s" Query', 'waves'); // text for a search results page $text['tag'] = __('Posts Tagged "%s"', 'waves'); // text for a tag page $text['author'] = __('Articles Posted by %s', 'waves'); // text for an author page $text['404'] = __('Error 404', 'waves'); // text for the 404 page $showCurrent = 1; // 1 - show current post/page title in breadcrumbs, 0 - don't show $showOnHome = 0; // 1 - show breadcrumbs on the homepage, 0 - don't show $breadcrumb_char = get_theme_mod('breadcrumb_char', '1'); if ($breadcrumb_char) { switch ($breadcrumb_char) { case '2': $delimiter = ' // '; break; case '3': $delimiter = ' > '; break; case '1': default: $delimiter = ' » '; break; } } $before = '<span class="current">'; // tag before the current crumb $after = '</span>'; // tag after the current crumb /* === END OF OPTIONS === */ global $post; $homeLink = home_url() . '/'; $linkBefore = '<span typeof="v:Breadcrumb">'; $linkAfter = '</span>'; $linkAttr = ' rel="v:url" property="v:title"'; $link = $linkBefore . '<a' . $linkAttr . ' href="%1$s">%2$s</a>' . $linkAfter; if (is_home() || is_front_page()) { if ($showOnHome == 1) { echo '<div id="crumbs"><a href="' . $homeLink . '">' . $text['home'] . '</a></div>'; } } else { echo '<div id="crumbs" xmlns:v="http://rdf.data-vocabulary.org/#">' . sprintf($link, $homeLink, $text['home']) . $delimiter; if (is_category()) { $thisCat = get_category(get_query_var('cat'), false); if ($thisCat->parent != 0) { $cats = get_category_parents($thisCat->parent, TRUE, $delimiter); $cats = str_replace('<a', $linkBefore . '<a' . $linkAttr, $cats); $cats = str_replace('</a>', '</a>' . $linkAfter, $cats); echo $cats; } echo $before . sprintf($text['category'], single_cat_title('', false)) . $after; } elseif (is_search()) { echo $before . sprintf($text['search'], get_search_query()) . $after; } elseif (is_day()) { echo sprintf($link, get_year_link(get_the_time('Y')), get_the_time('Y')) . $delimiter; echo sprintf($link, get_month_link(get_the_time('Y'), get_the_time('m')), get_the_time('F')) . $delimiter; echo $before . get_the_time('d') . $after; } elseif (is_month()) { echo sprintf($link, get_year_link(get_the_time('Y')), get_the_time('Y')) . $delimiter; echo $before . get_the_time('F') . $after; } elseif (is_year()) { echo $before . get_the_time('Y') . $after; } elseif (is_single() && !is_attachment()) { if (get_post_type() != 'post') { $post_type = get_post_type_object(get_post_type()); $slug = $post_type->rewrite; printf($link, $homeLink . '/' . $slug['slug'] . '/', $post_type->labels->singular_name); if ($showCurrent == 1) { echo $delimiter . $before . get_the_title() . $after; } } else { $cat = get_the_category(); $cat = $cat[0]; $cats = get_category_parents($cat, TRUE, $delimiter); if ($showCurrent == 0) { $cats = preg_replace("#^(.+){$delimiter}\$#", "\$1", $cats); } $cats = str_replace('<a', $linkBefore . '<a' . $linkAttr, $cats); $cats = str_replace('</a>', '</a>' . $linkAfter, $cats); echo $cats; if ($showCurrent == 1) { echo $before . get_the_title() . $after; } } } elseif (!is_single() && !is_page() && get_post_type() != 'post' && !is_404()) { $post_type = get_post_type_object(get_post_type()); echo $before . $post_type->labels->singular_name . $after; } elseif (is_attachment()) { $parent = get_post($post->post_parent); $cat = get_the_category($parent->ID); $cat = $cat[0]; $cats = get_category_parents($cat, TRUE, $delimiter); $cats = str_replace('<a', $linkBefore . '<a' . $linkAttr, $cats); $cats = str_replace('</a>', '</a>' . $linkAfter, $cats); echo $cats; printf($link, get_permalink($parent), $parent->post_title); if ($showCurrent == 1) { echo $delimiter . $before . get_the_title() . $after; } } elseif (is_page() && !$post->post_parent) { if ($showCurrent == 1) { echo $before . get_the_title() . $after; } } elseif (is_page() && $post->post_parent) { $parent_id = $post->post_parent; $breadcrumbs = array(); while ($parent_id) { $page = get_page($parent_id); $breadcrumbs[] = sprintf($link, get_permalink($page->ID), get_the_title($page->ID)); $parent_id = $page->post_parent; } $breadcrumbs = array_reverse($breadcrumbs); for ($i = 0; $i < count($breadcrumbs); $i++) { echo $breadcrumbs[$i]; if ($i != count($breadcrumbs) - 1) { echo $delimiter; } } if ($showCurrent == 1) { echo $delimiter . $before . get_the_title() . $after; } } elseif (is_tag()) { echo $before . sprintf($text['tag'], single_tag_title('', false)) . $after; } elseif (is_author()) { global $author; $userdata = get_userdata($author); echo $before . sprintf($text['author'], $userdata->display_name) . $after; } elseif (is_404()) { echo $before . $text['404'] . $after; } if (get_query_var('paged')) { if (is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author()) { echo ' ('; } echo __('Page', 'waves') . ' ' . get_query_var('paged'); if (is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author()) { echo ')'; } } echo '</div>'; } }
$current_term = $wp_query->get_queried_object(); $ancestors = array_reverse(get_ancestors($current_term->term_id, 'product_cat')); foreach ($ancestors as $ancestor) { $ancestor = get_term($ancestor, 'product_cat'); echo $before . '<a href="' . get_term_link($ancestor) . '">' . esc_html($ancestor->name) . '</a>' . $after . $delimiter; } echo $before . esc_html($current_term->name) . $after; } elseif (is_tax('product_tag')) { $queried_object = $wp_query->get_queried_object(); echo $prepend . $before . __('Products tagged “', 'woocommerce') . $queried_object->name . '”' . $after; } elseif (is_day()) { echo $before . '<a href="' . get_year_link(get_the_time('Y')) . '">' . get_the_time('Y') . '</a>' . $after . $delimiter; echo $before . '<a href="' . get_month_link(get_the_time('Y'), get_the_time('m')) . '">' . get_the_time('F') . '</a>' . $after . $delimiter; echo $before . get_the_time('d') . $after; } elseif (is_month()) { echo $before . '<a href="' . get_year_link(get_the_time('Y')) . '">' . get_the_time('Y') . '</a>' . $after . $delimiter; echo $before . get_the_time('F') . $after; } elseif (is_year()) { echo $before . get_the_time('Y') . $after; } elseif (is_post_type_archive('product') && get_option('page_on_front') !== $shop_page_id) { $_name = wc_get_page_id('shop') ? get_the_title(wc_get_page_id('shop')) : ''; if (!$_name) { $product_post_type = get_post_type_object('product'); $_name = $product_post_type->labels->singular_name; } if (is_search()) { echo $before . '<a href="' . get_post_type_archive_link('product') . '">' . $_name . '</a>' . $delimiter . __('Search results for “', 'woocommerce') . get_search_query() . '”' . $after; } elseif (is_paged()) { echo $before . '<a href="' . get_post_type_archive_link('product') . '">' . $_name . '</a>' . $after; } else { echo $before . $_name . $after;