function webdados_fb_open_graph() { global $webdados_fb_open_graph_plugin_settings, $webdados_fb_open_graph_plugin_name, $webdados_fb_open_graph_plugin_version, $webdados_fb_open_graph_settings; //Upgrade webdados_fb_open_graph_upgrade(); //Get options - OLD (until 0.5.4) /*foreach($webdados_fb_open_graph_plugin_settings as $key) { $$key=get_option('wonderm00n_open_graph_'.$key); }*/ //Get options - NEW (after 0.5.4) extract($webdados_fb_open_graph_settings); //Also set Title Tag? $fb_set_title_tag = 0; //Additional images $fb_image_additional = array(); $fb_type = 'article'; if (is_singular()) { //It's a Post or a Page or an attachment page - It can also be the homepage if it's set as a page global $post; $fb_title = esc_attr(strip_tags(stripslashes($post->post_title))); //SubHeading if ($fb_show_subheading == 1) { if (webdados_fb_open_graph_subheadingactive()) { $fb_title .= ' - ' . get_the_subheading(); } } $fb_url = get_permalink(); if (is_front_page()) { /* Fix homepage type when it's a static page */ $fb_url = get_option('home') . (intval($fb_url_add_trailing) == 1 ? '/' : ''); $fb_type = trim($fb_type_homepage == '' ? 'website' : $fb_type_homepage); } if (trim($post->post_excerpt) != '') { //If there's an excerpt that's what we'll use $fb_desc = trim($post->post_excerpt); } else { //If not we grab it from the content $fb_desc = trim($post->post_content); } $fb_desc = intval($fb_desc_chars) > 0 ? mb_substr(esc_attr(strip_tags(strip_shortcodes(stripslashes($fb_desc)))), 0, $fb_desc_chars) : esc_attr(strip_tags(strip_shortcodes(stripslashes($fb_desc)))); if (intval($fb_image_show) == 1 || intval($fb_image_show_schema) == 1 || intval($fb_image_show_twitter) == 1) { $fb_image = webdados_fb_open_graph_post_image($fb_image_use_specific, $fb_image_use_featured, $fb_image_use_content, $fb_image_use_media, $fb_image_use_default, $fb_image); } //Author $author_id = $post->post_author; if ($author_id > 0) { $fb_author = get_the_author_meta('facebook', $author_id); $fb_author_meta = get_the_author_meta('display_name', $author_id); $fb_author_linkrelgp = get_the_author_meta('googleplus', $author_id); $fb_author_twitter = get_the_author_meta('twitter', $author_id); } else { $fb_author = ''; $fb_author_meta = ''; $fb_author_linkrelgp = ''; $fb_author_twitter = ''; } //Author - Hide on pages? if (is_page() && $fb_author_hide_on_pages == 1) { $fb_author = ''; $fb_author_meta = ''; $fb_author_linkrelgp = ''; $fb_author_twitter = ''; } //Published and Modified time if (is_singular('post')) { $fb_article_pub_date = get_the_date('c'); $fb_article_mod_date = get_the_modified_date('c'); } else { $fb_article_dates_show = 0; $fb_article_pub_date = ''; $fb_article_mod_date = ''; } //Categories if (is_singular('post')) { $cats = get_the_category(); if (!is_wp_error($cats) && (is_array($cats) && count($cats) > 0)) { $fb_sections = array(); foreach ($cats as $cat) { $fb_sections[] = $cat->name; } } } else { $fb_article_sections_show = 0; } //Business Directory Plugin if ($fb_show_businessdirectoryplugin == 1) { @(include_once ABSPATH . 'wp-admin/includes/plugin.php'); if (is_plugin_active('business-directory-plugin/wpbusdirman.php')) { global $wpbdp; //$bdpaction = _wpbdp_current_action(); $bdpaction = $wpbdp->controller->get_current_action(); switch ($bdpaction) { case 'showlisting': //Listing $listing_id = get_query_var('listing') ? wpbdp_get_post_by_slug(get_query_var('listing'))->ID : wpbdp_getv($_GET, 'id', get_query_var('id')); $bdppost = get_post($listing_id); $fb_title = esc_attr(strip_tags(stripslashes($bdppost->post_title))) . ' - ' . $fb_title; $fb_set_title_tag = 1; $fb_url = get_permalink($listing_id); if (trim($bdppost->post_excerpt) != '') { //If there's an excerpt that's what we'll use $fb_desc = trim($bdppost->post_excerpt); } else { //If not we grab it from the content $fb_desc = trim($bdppost->post_content); } $fb_desc = intval($fb_desc_chars) > 0 ? mb_substr(esc_attr(strip_tags(strip_shortcodes(stripslashes($fb_desc)))), 0, $fb_desc_chars) : esc_attr(strip_tags(strip_shortcodes(stripslashes($fb_desc)))); if (intval($fb_image_show) == 1 || intval($fb_image_show_schema) == 1 || intval($fb_image_show_twitter) == 1) { $thumbdone = false; if (intval($fb_image_use_featured) == 1) { //Featured if ($id_attachment = get_post_thumbnail_id($bdppost->ID)) { //There's a featured/thumbnail image for this listing $fb_image = wp_get_attachment_url($id_attachment, false); $thumbdone = true; } } if (!$thumbdone) { //Main image loaded if ($thumbnail_id = wpbdp_listings_api()->get_thumbnail_id($bdppost->ID)) { $fb_image = wp_get_attachment_url($thumbnail_id, false); } } } break; case 'browsecategory': //Categories $term = get_term_by('slug', get_query_var('category'), wpbdp_categories_taxonomy()); $fb_title = esc_attr(strip_tags(stripslashes($term->name))) . ' - ' . $fb_title; $fb_set_title_tag = 1; $fb_url = get_term_link($term); if (trim($term->description) != '') { $fb_desc = trim($term->description); } break; case 'main': //Main page //No changes break; default: //No changes break; } } } } else { global $wp_query; //Other pages - Defaults $fb_title = esc_attr(strip_tags(stripslashes(get_bloginfo('name')))); //$fb_url=get_option('home').(intval($fb_url_add_trailing)==1 ? '/' : ''); //2013-11-4 changed from 'siteurl' to 'home' $fb_url = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; //Not really canonical but will work for now //These are only used in posts/pages $fb_article_sections_show = 0; $fb_article_dates_show = 0; $fb_author_show = 0; $fb_author_show_meta = 0; $fb_author_show_linkrelgp = 0; $fb_author_show_twitter = 0; switch (trim($fb_desc_homepage)) { case 'custom': $fb_desc = esc_attr(strip_tags(stripslashes($fb_desc_homepage_customtext))); //WPML? if (function_exists('icl_object_id') && function_exists('icl_register_string')) { global $sitepress; if (ICL_LANGUAGE_CODE != $sitepress->get_default_language()) { $fb_desc = icl_t('wd-fb-og', 'wd_fb_og_desc_homepage_customtext', $fb_desc); } else { //We got it already } } break; default: $fb_desc = esc_attr(strip_tags(stripslashes(get_bloginfo('description')))); break; } if (is_category()) { $fb_title = esc_attr(strip_tags(stripslashes(single_cat_title('', false)))); $term = $wp_query->get_queried_object(); $fb_url = get_term_link($term, $term->taxonomy); $cat_desc = trim(esc_attr(strip_tags(stripslashes(category_description())))); if (trim($cat_desc) != '') { $fb_desc = $cat_desc; } } else { if (is_tag()) { $fb_title = esc_attr(strip_tags(stripslashes(single_tag_title('', false)))); $term = $wp_query->get_queried_object(); $fb_url = get_term_link($term, $term->taxonomy); $tag_desc = trim(esc_attr(strip_tags(stripslashes(tag_description())))); if (trim($tag_desc) != '') { $fb_desc = $tag_desc; } } else { if (is_tax()) { $fb_title = esc_attr(strip_tags(stripslashes(single_term_title('', false)))); $term = $wp_query->get_queried_object(); $fb_url = get_term_link($term, $term->taxonomy); //WooCommerce if (intval($fb_image_show) == 1 || intval($fb_image_show_schema) == 1 || intval($fb_image_show_twitter) == 1) { if (class_exists('woocommerce') && $fb_wc_usecategthumb == 1 && is_product_category()) { if ($thumbnail_id = get_woocommerce_term_meta($term->term_id, 'thumbnail_id', true)) { if ($image = wp_get_attachment_url($thumbnail_id)) { $fb_image = $image; } } } } } else { if (is_search()) { $fb_title = esc_attr(strip_tags(stripslashes(__('Search for') . ' "' . get_search_query() . '"'))); $fb_url = get_search_link(); } else { if (is_author()) { $fb_title = esc_attr(strip_tags(stripslashes(get_the_author_meta('display_name', get_query_var('author'))))); $fb_url = get_author_posts_url(get_query_var('author'), get_query_var('author_name')); } else { if (is_archive()) { if (is_day()) { $fb_title = esc_attr(strip_tags(stripslashes(get_query_var('day') . ' ' . single_month_title(' ', false) . ' ' . __('Archives')))); $fb_url = get_day_link(get_query_var('year'), get_query_var('monthnum'), get_query_var('day')); } else { if (is_month()) { $fb_title = esc_attr(strip_tags(stripslashes(single_month_title(' ', false) . ' ' . __('Archives')))); $fb_url = get_month_link(get_query_var('year'), get_query_var('monthnum')); } else { if (is_year()) { $fb_title = esc_attr(strip_tags(stripslashes(get_query_var('year') . ' ' . __('Archives')))); $fb_url = get_year_link(get_query_var('year')); } } } } else { if (is_front_page()) { $fb_url = get_option('home') . (intval($fb_url_add_trailing) == 1 ? '/' : ''); $fb_type = trim($fb_type_homepage == '' ? 'website' : $fb_type_homepage); } else { //Others... Defaults already set up there } } } } } } } } //If no description let's just add the title if (trim($fb_desc) == '') { $fb_desc = $fb_title; } //YOAST? if ($fb_show_wpseoyoast == 1) { if (defined('WPSEO_VERSION')) { $wpseo = WPSEO_Frontend::get_instance(); //App ID - From our plugin //Admin ID - From our plugin //Locale - From our plugin //Sitename - From our plugin //Title - From WPSEO $fb_title = strip_tags($wpseo->title(false)); //Title - SubHeading plugin if ($fb_show_subheading == 1) { if (webdados_fb_open_graph_subheadingactive()) { $fb_title .= ' - ' . get_the_subheading(); } } //URL - From WPSEO $fb_url = $wpseo->canonical(false); //Description - From WPSEO or our plugin $fb_desc_temp = $wpseo->metadesc(false); $fb_desc = strip_tags(trim($fb_desc_temp) != '' ? trim($fb_desc_temp) : $fb_desc); //Image - From our plugin } } //WooCommerce - Additional product images? if (intval($fb_image_show) == 1 && class_exists('woocommerce') && $fb_wc_useproductgallery == 1 && is_product()) { global $post; $product = new WC_Product($post->ID); if ($attachment_ids = $product->get_gallery_attachment_ids()) { foreach ($attachment_ids as $attachment_id) { if ($image_link = wp_get_attachment_url($attachment_id)) { if (trim($image_link) != '') { $fb_image_additional[] = trim($image_link); } } } } } //Apply Filters $fb_title = apply_filters('fb_og_title', $fb_title); $fb_desc = apply_filters('fb_og_desc', $fb_desc); $fb_image = apply_filters('fb_og_image', $fb_image); $fb_image_additional = apply_filters('fb_og_image_additional', $fb_image_additional); $fb_locale = apply_filters('fb_og_locale', $fb_locale); $fb_image_size = false; if (intval($fb_image_show) == 1 && trim($fb_image) != '') { if (intval($fb_image_size_show) == 1) { if (isset($GLOBALS['webdados_fb_img_size'])) { //Already fetched $fb_image_size = $GLOBALS['webdados_fb_img_size']; } else { $fb_image_size = webdados_fb_open_graph_getimagesize($fb_image); } } } else { $fb_image_size_show = 0; } //No spaces on URLs if (isset($fb_url) && trim($fb_url) != '') { $fb_url = str_replace(' ', '%20', trim($fb_url)); } if (isset($fb_publisher) && trim($fb_publisher) != '') { $fb_publisher = str_replace(' ', '%20', trim($fb_publisher)); } if (isset($fb_publisher_schema) && trim($fb_publisher_schema) != '') { $fb_publisher_schema = str_replace(' ', '%20', trim($fb_publisher_schema)); } if (isset($fb_author) && trim($fb_author) != '') { $fb_author = str_replace(' ', '%20', trim($fb_author)); } if (isset($fb_author_linkrelgp) && trim($fb_author_linkrelgp) != '') { $fb_author_linkrelgp = str_replace(' ', '%20', trim($fb_author_linkrelgp)); } if (isset($fb_image) && trim($fb_image) != '') { $fb_image = str_replace(' ', '%20', trim($fb_image)); } if (isset($fb_image_additional) && is_array($fb_image_additional) && count($fb_image_additional)) { foreach ($fb_image_additional as $key => $value) { $fb_image_additional[$key] = str_replace(' ', '%20', trim($value)); } } $html = ' <!-- START - ' . $webdados_fb_open_graph_plugin_name . ' ' . $webdados_fb_open_graph_plugin_version . ' --> '; if (intval($fb_app_id_show) == 1 && trim($fb_app_id) != '') { $html .= '<meta property="fb:app_id" content="' . trim(esc_attr($fb_app_id)) . '"/> '; } if (intval($fb_admin_id_show) == 1 && trim($fb_admin_id) != '') { $html .= '<meta property="fb:admins" content="' . trim(esc_attr($fb_admin_id)) . '"/> '; } if (intval($fb_locale_show) == 1) { $html .= '<meta property="og:locale" content="' . trim(esc_attr(trim($fb_locale) != '' ? trim($fb_locale) : trim(get_locale()))) . '"/> '; } if (intval($fb_sitename_show) == 1) { $html .= '<meta property="og:site_name" content="' . trim(esc_attr(get_bloginfo('name'))) . '"/> '; } if (intval($fb_title_show) == 1) { $html .= '<meta property="og:title" content="' . trim(esc_attr($fb_title)) . '"/> '; } if (intval($fb_set_title_tag) == 1) { //Does nothing so far. We try to create the <title> tag but it's too late now } if (intval($fb_title_show_schema) == 1) { $html .= '<meta itemprop="name" content="' . trim(esc_attr($fb_title)) . '"/> '; } if (intval($fb_title_show_twitter) == 1) { $html .= '<meta name="twitter:title" content="' . trim(esc_attr($fb_title)) . '"/> '; } if (intval($fb_url_show) == 1) { $html .= '<meta property="og:url" content="' . trim(esc_attr($fb_url)) . '"/> '; } if (intval($fb_url_show_twitter) == 1) { $html .= '<meta name="twitter:url" content="' . trim(esc_attr($fb_url)) . '"/> '; } if (intval($fb_url_canonical) == 1) { $html .= '<link rel="canonical" href="' . trim(esc_attr($fb_url)) . '"/> '; } if (intval($fb_type_show) == 1) { $html .= '<meta property="og:type" content="' . trim(esc_attr($fb_type)) . '"/> '; } if (intval($fb_article_dates_show) == 1 && trim($fb_article_pub_date) != '') { $html .= '<meta property="article:published_time" content="' . trim(esc_attr($fb_article_pub_date)) . '"/> '; } if (intval($fb_article_dates_show) == 1 && trim($fb_article_mod_date) != '') { $html .= '<meta property="article:modified_time" content="' . trim(esc_attr($fb_article_mod_date)) . '" /> <meta property="og:updated_time" content="' . trim(esc_attr($fb_article_mod_date)) . '" /> '; } if (intval($fb_article_sections_show) == 1 && isset($fb_sections) && is_array($fb_sections) && count($fb_sections) > 0) { foreach ($fb_sections as $fb_section) { $html .= '<meta property="article:section" content="' . trim(esc_attr($fb_section)) . '"/> '; } } if (intval($fb_publisher_show) == 1 && trim($fb_publisher) != '') { $html .= '<meta property="article:publisher" content="' . trim(esc_attr($fb_publisher)) . '"/> '; } if (intval($fb_publisher_show_schema) == 1 && trim($fb_publisher_schema) != '') { $html .= '<link rel="publisher" href="' . trim(esc_attr($fb_publisher_schema)) . '"/> '; } if (intval($fb_publisher_show_twitter) == 1 && trim($fb_publisher_twitteruser) != '') { $html .= '<meta name="twitter:site" content="@' . trim(esc_attr($fb_publisher_twitteruser)) . '"/> '; } if (intval($fb_author_show) == 1 && $fb_author != '') { $html .= '<meta property="article:author" content="' . trim(esc_attr($fb_author)) . '"/> '; } if (intval($fb_author_show_meta) == 1 && $fb_author_meta != '') { $html .= '<meta name="author" content="' . trim(esc_attr($fb_author_meta)) . '"/> '; } if (intval($fb_author_show_linkrelgp) == 1 && trim($fb_author_linkrelgp) != '') { $html .= '<link rel="author" href="' . trim(esc_attr($fb_author_linkrelgp)) . '"/> '; } if (intval($fb_author_show_twitter) == 1 && (trim($fb_author_twitter) != '' || trim($fb_publisher_twitteruser) != '')) { $html .= '<meta name="twitter:creator" content="@' . trim(esc_attr(trim($fb_author_twitter) != '' ? trim($fb_author_twitter) : trim($fb_publisher_twitteruser))) . '"/> '; } if (intval($fb_desc_show) == 1) { $html .= '<meta property="og:description" content="' . trim(esc_attr($fb_desc)) . '"/> '; } if (intval($fb_desc_show_meta) == 1) { $html .= '<meta name="description" content="' . trim(esc_attr($fb_desc)) . '"/> '; } if (intval($fb_desc_show_schema) == 1) { $html .= '<meta itemprop="description" content="' . trim(esc_attr($fb_desc)) . '"/> '; } if (intval($fb_desc_show_twitter) == 1) { $html .= '<meta name="twitter:description" content="' . trim(esc_attr($fb_desc)) . '"/> '; } if (intval($fb_image_show) == 1 && trim($fb_image) != '') { $html .= '<meta property="og:image" content="' . trim(esc_attr($fb_image)) . '"/> '; } if (intval($fb_image_show) == 1 && isset($fb_image_additional) && is_array($fb_image_additional) && count($fb_image_additional) > 0) { foreach ($fb_image_additional as $fb_image_additional_temp) { $html .= '<meta property="og:image" content="' . trim(esc_attr($fb_image_additional_temp)) . '"/> '; } } else { //We only show the image size if we only have one image if (intval($fb_image_size_show) == 1 && isset($fb_image_size) && is_array($fb_image_size) != '') { $html .= '<meta property="og:image:width" content="' . intval(esc_attr($fb_image_size[0])) . '"/> <meta property="og:image:height" content="' . intval(esc_attr($fb_image_size[1])) . '"/> '; } } if (intval($fb_image_show_schema) == 1 && trim($fb_image) != '') { $html .= '<meta itemprop="image" content="' . trim(esc_attr($fb_image)) . '"/> '; } if (intval($fb_image_show_twitter) == 1 && trim($fb_image) != '') { $html .= '<meta name="twitter:image:src" content="' . trim(esc_attr($fb_image)) . '"/> '; } if (intval($fb_title_show_twitter) == 1 || intval($fb_url_show_twitter) == 1 || $fb_author_show_twitter == 1 || $fb_publisher_show_twitter == 1 || $fb_image_show_twitter == 1) { $html .= '<meta name="twitter:card" content="' . trim(esc_attr($fb_twitter_card_type)) . '"/> '; } $html .= '<!-- END - ' . $webdados_fb_open_graph_plugin_name . ' --> '; echo $html; }
function widget($args, $instance) { extract($args); $title = apply_filters('widget_title', empty($instance['title']) ? __('Pages', 'wpdance') : $instance['title'], $instance, $this->id_base); echo $before_widget; if ($title) { echo $before_title . $title . $after_title; } ?> <div class="alphabet-products"> <ul> <?php for ($i = ord('A'); $i <= ord('Z'); $i++) { $_cur_char = chr($i); $_search_link = get_search_link(chr($i)); $_search_link = esc_url(add_query_arg(array("post_type" => "product", "producta2z" => "1"), $_search_link)); echo "<li><a class='bold-upper-small' href='{$_search_link}'>{$_cur_char}</a></li>"; } for ($i = 1; $i <= 9; $i++) { $_search_link = get_search_link($i); $_search_link = esc_url(add_query_arg(array("post_type" => "product", "producta2z" => "1"), $_search_link)); echo "<li><a class='bold-upper-small' href='{$_search_link}'>{$i}</a></li>"; } ?> </ul> </div> <?php echo $after_widget; }
function permalink($terms) { if (is_array($terms)) { $terms = implode(' ', array_keys($terms)); } return get_search_link($terms); }
function redirect() { global $wp_rewrite; if (!is_search() || is_admin() || !isset($wp_rewrite) || !is_object($wp_rewrite) || !$wp_rewrite->get_search_permastruct()) { return; } // Set the search base and query $search_base = $wp_rewrite->search_base; $search_query = get_query_var('s'); // Skip the search results if there is exactly one result: http://wpglee.com/2011/04/redirect-when-search-query-only-returns-one-match/ if (option('redirect_single') && $search_query) { global $wp_query; if ($wp_query->post_count == 1) { wp_redirect(esc_url(trailingslashit(get_permalink($wp_query->posts['0']->ID)))); exit; } } // Return a random post when an empty search query is entered // Allows the random results to be filtered (e.g. to limit to a particular category, post types, or anything else accepted by `get_posts`) if (option('redirect_random') && $search_query === '') { $random = get_posts(apply_filters('ubik_search_redirect_random_args', ['numberposts' => 1, 'orderby' => 'rand'])); wp_redirect(esc_url(trailingslashit(get_permalink($random[0]->ID)))); exit; } // "Nice search" rewrite; full credit to Mark Jaquith for this functionality: https://wordpress.org/plugins/nice-search/ if (strpos($_SERVER['REQUEST_URI'], "/{$search_base}/") === false && strpos($_SERVER['REQUEST_URI'], '&') === false) { //wp_redirect( esc_url( trailingslashit( home_url( "/{$search_base}/" . urlencode($search_query) ) ) ) ); wp_redirect(get_search_link()); exit; } }
/** * Redirects search results from /?s=query to /search/query/, converts %20 to +. * * @link http://txfx.net/wordpress-plugins/nice-search/ * @global \WP_Rewrite $wp_rewrite WordPress Rewrite Component. * @since 1.0.0 */ function redirect() { global $wp_rewrite; if (no_rewrite_set($wp_rewrite)) { return; } $search_base = $wp_rewrite->search_base; if (is_search_permalink($search_base)) { wp_redirect(get_search_link()); exit; } }
/** * Redirects search results from /?s=query to /search/query/, converts %20 to + * * @link http://txfx.net/wordpress-plugins/nice-search/ * * You can enable/disable this feature in functions.php (or lib/config.php if you're using Sage): * add_theme_support('soil-nice-search'); */ function redirect() { global $wp_rewrite; if (!isset($wp_rewrite) || !is_object($wp_rewrite) || !$wp_rewrite->get_search_permastruct()) { return; } $search_base = $wp_rewrite->search_base; if (is_search() && !is_admin() && strpos($_SERVER['REQUEST_URI'], "/{$search_base}/") === false) { wp_redirect(get_search_link()); exit; } }
/** * A Breadcrumb Trail Filling Function * * This functions fills a breadcrumb for a search page. */ protected function do_search() { //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_search_query(), $this->opt['Hsearch_template_no_anchor'], array('search', 'current-item'))); //If we're paged, or allowing the current item to be linked, let's link to the first page if ($this->opt['bcurrent_item_linked'] || is_paged() && $this->opt['bpaged_display']) { //Since we are paged and are linking the root breadcrumb, time to change to the regular template $breadcrumb->set_template($this->opt['Hsearch_template']); //Figure out the anchor for the search $breadcrumb->set_url(get_search_link()); } }
/** * Loop pagination function for paginating loops with multiple posts. This should be used on archive, blog, and * search pages. It is not for singular views. * * @since 0.1.0 * @access public * @uses paginate_links() Creates a string of paginated links based on the arguments given. * @param array $args Arguments to customize how the page links are output. * @return string $page_links */ function loop_pagination($args = array()) { global $wp_rewrite, $wp_query; /* If there's not more than one page, return nothing. */ if (1 >= $wp_query->max_num_pages) { return; } /* Get the current page. */ $current = get_query_var('paged') ? absint(get_query_var('paged')) : 1; /* Get the max number of pages. */ $max_num_pages = intval($wp_query->max_num_pages); /* Set up some default arguments for the paginate_links() function. */ $defaults = array('base' => add_query_arg('paged', '%#%'), 'format' => '', 'total' => $max_num_pages, 'current' => $current, 'prev_next' => true, 'show_all' => false, 'end_size' => 1, 'mid_size' => 1, 'add_fragment' => '', 'type' => 'plain', 'before' => '<div class="pagination loop-pagination">', 'after' => '</div>', 'echo' => true); /* Add the $base argument to the array if the user is using permalinks. */ if ($wp_rewrite->using_permalinks()) { $defaults['base'] = str_replace(2, '%#%', esc_url(get_pagenum_link(2))); } //$defaults['base'] = user_trailingslashit( trailingslashit( get_pagenum_link() ) . 'page/%#%' ); /* If we're on a search results page, we need to change this up a bit. */ if (is_search()) { $search_permastruct = $wp_rewrite->get_search_permastruct(); if (!empty($search_permastruct)) { $defaults['base'] = user_trailingslashit(trailingslashit(get_search_link()) . 'page/%#%'); } } /* Allow developers to overwrite the arguments with a filter. */ $args = apply_filters('loop_pagination_args', $args); /* Merge the arguments input with the defaults. */ $args = wp_parse_args($args, $defaults); /* Don't allow the user to set this to an array. */ if ('array' == $args['type']) { $args['type'] = 'plain'; } /* Get the paginated links. */ $page_links = paginate_links($args); /* Remove 'page/1' from the entire output since it's not needed. */ $page_links = str_replace(array('&paged=1\'', '/page/1\'', '/page/1/\''), '\'', $page_links); /* Wrap the paginated links with the $before and $after elements. */ $page_links = $args['before'] . $page_links . $args['after']; /* Allow devs to completely overwrite the output. */ $page_links = apply_filters('loop_pagination', $page_links); /* Return the paginated links for use in themes. */ if ($args['echo']) { echo $page_links; } else { return $page_links; } }
public function __construct() { add_action('template_redirect', function () { global $wp_rewrite; if (!isset($wp_rewrite) || !is_object($wp_rewrite) || !$wp_rewrite->get_search_permastruct()) { return; } if (is_search() && !is_admin() && strpos($_SERVER['REQUEST_URI'], '/' . $wp_rewrite->search_base . '/') === false && strpos($_SERVER['REQUEST_URI'], '&') === false) { wp_redirect(get_search_link()); exit; } }); add_filter('wpseo_json_ld_search_url', function () { return str_replace('/?s=', '/search/', $url); }); }
function td_js_generator() { td_js_buffer::add_variable('td_ajax_url', admin_url('admin-ajax.php')); td_js_buffer::add_variable('td_get_template_directory_uri', get_template_directory_uri()); td_js_buffer::add_variable('tds_snap_menu', td_util::get_option('tds_snap_menu')); td_js_buffer::add_variable('tds_header_style', td_util::get_option('tds_header_style')); td_js_buffer::add_variable('tds_mobile_swipe', td_util::get_option('tds_mobile_swipe')); td_js_buffer::add_variable('td_search_url', get_search_link()); td_js_buffer::add_variable('td_please_wait', str_replace(array('"', "'"), array('`'), __td("Please wait..."))); td_js_buffer::add_variable('td_email_user_pass_incorrect', str_replace(array('"', "'"), array('`'), __td("User or password incorrect!"))); td_js_buffer::add_variable('td_email_user_incorrect', str_replace(array('"', "'"), array('`'), __td("Email or username incorrect!"))); td_js_buffer::add_variable('td_email_incorrect', str_replace(array('"', "'"), array('`'), __td("Email incorrect!"))); //use for more articles on post pages td_js_buffer::add_variable('tds_more_articles_on_post_enable', td_util::get_option('tds_more_articles_on_post_pages_enable')); td_js_buffer::add_variable('tds_more_articles_on_post_time_to_wait', td_util::get_option('tds_more_articles_on_post_pages_time_to_wait')); td_js_buffer::add_variable('tds_more_articles_on_post_pages_distance_from_top', intval(td_util::get_option('tds_more_articles_on_post_pages_distance_from_top'))); td_js_buffer::add("\nvar td_blocks = []; //here we store all the items for the current page\n\n//td_block class - each ajax block uses a object of this class for requests\nfunction td_block() {\n this.id = '';\n this.block_type = 1; //block type id (1-234 etc)\n this.atts = '';\n this.td_cur_cat = '';\n this.td_column_number = '';\n this.td_current_page = 1; //\n this.post_count = 0; //from wp\n this.found_posts = 0; //from wp\n this.max_num_pages = 0; //from wp\n this.is_ajax_running = false;\n this.header_color = '';\n}\n\n "); }
/** * Echo a facet listing from the search results. This should only be used on * the search results page, because Swiftype search results must be present. * * You must modify the Swiftype query parameters to request facets. * * Facets are rendered inside a <div> with class st-facets. * * @param String $term_order Optional. Sort order for faceted terms. Default * is 'count'; if 'alphabetical' faceted * terms will be sorted alphabetically. * * @return void */ function swiftype_render_facets($term_order = 'count') { $results = swiftype_search_results(); $facets = $results['info']['posts']['facets']; if (empty($facets)) { return ''; } $html = '<div class="st-facets">'; foreach ($facets as $facet_field => $facet_values) { if (empty($facet_values)) { continue; } $html .= '<h4 class="st-facet-field st-facet-field-' . sanitize_title_with_dashes($facet_field) . '">' . esc_html($facet_field) . '</h4>'; $html .= '<ul>'; $term_counts = array(); foreach ($facet_values as $facet_term => $facet_count) { if (trim($facet_term) === '') { continue; } $facet_display = $facet_term; // special case for category since it's stored as an ID if ($facet_field == 'category') { $facet_display = get_cat_name($facet_term); if ($facet_display === '') { continue; } } $term_counts[$facet_display] = array('term' => $facet_term, 'count' => $facet_count); } if ($term_order == 'alphabetical') { ksort($term_counts, SORT_FLAG_CASE | SORT_NATURAL); } foreach ($term_counts as $facet_display => $facet_details) { // apparently WordPress's add_query_arg does not properly handle & in a value; escape it with %26 beforehand. $escaped_facet_term = str_replace('&', '%26', $facet_details['term']); $url = add_query_arg(array('st-facet-field' => $facet_field, 'st-facet-term' => $escaped_facet_term), get_search_link()); $html .= "<li><a href=\"" . esc_attr($url) . "\">" . esc_html($facet_display) . "</a> (" . esc_html($facet_details['count']) . ")</li>"; } $html .= '</ul>'; } $html .= '</div>'; echo $html; }
function vw_instant_search() { global $wpdb; if (isset($_GET['s'])) { $q = htmlspecialchars($_GET['s']); $q = mysql_real_escape_string($q); $q = esc_sql($q); } else { echo json_encode(apply_filters('instant_search_res', array())); die; } $query = array('suppress_filters' => true, 'update_post_term_cache' => false, 'update_post_meta_cache' => false, 'post_status' => 'publish', 'order' => 'DESC', 'orderby' => 'post_date', 'posts_per_page' => 6, 's' => $q); query_posts($query); // Check if any posts were found. if (!have_posts()) { $html = '<li class="vw-instant-search-no-result">'; $html .= '<span class="vw-instant-search-result-title">No result was found</span>'; $html .= '</li>'; echo $html; die; } //Create an array with the results $html = ''; while (have_posts()) { the_post(); ob_start(); get_template_part('templates/instant-search-result'); $html .= ob_get_clean(); } $html .= '<li class="vw-instant-search-all-result">'; $html .= '<a href="' . get_search_link() . '"><span class="vw-instant-search-result-title">' . __('View all results »', 'envirra') . '</span></a>'; $html .= '</li>'; echo $html; wp_reset_query(); die; }
/** * 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 $unpaged Whether or not to return the canonical with or without pagination added to the URL. * @return string $canonical */ function canonical($echo = true, $unpaged = false) { $options = get_wpseo_options(); $canonical = false; // Set decent canonicals for homepage, singulars and taxonomy pages if (is_singular()) { if (wpseo_get_value('canonical') && wpseo_get_value('canonical') != '') { $canonical = wpseo_get_value('canonical'); } 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')); } } } } } else { if (is_search()) { $canonical = get_search_link(); } else { if (is_front_page()) { $canonical = home_url('/'); } else { if ($this->is_posts_page()) { $canonical = get_permalink(get_option('page_for_posts')); } else { if (is_tax() || is_tag() || is_category()) { $term = get_queried_object(); $canonical = wpseo_get_term_meta($term, $term->taxonomy, 'canonical'); if (!$canonical) { $canonical = get_term_link($term, $term->taxonomy); } } else { if (function_exists('get_post_type_archive_link') && is_post_type_archive()) { $canonical = get_post_type_archive_link(get_post_type()); } else { if (is_author()) { $canonical = get_author_posts_url(get_query_var('author'), get_query_var('author_name')); } else { if (is_archive()) { if (is_date()) { if (is_day()) { $canonical = get_day_link(get_query_var('year'), get_query_var('monthnum'), get_query_var('day')); } else { if (is_month()) { $canonical = get_month_link(get_query_var('year'), get_query_var('monthnum')); } else { if (is_year()) { $canonical = get_year_link(get_query_var('year')); } } } } } } } } } } } if ($canonical && $unpaged) { return $canonical; } if ($canonical && get_query_var('paged') > 1) { global $wp_rewrite; if (!$wp_rewrite->using_permalinks()) { $canonical = add_query_arg('paged', get_query_var('paged'), $canonical); } else { $canonical = user_trailingslashit(trailingslashit($canonical) . trailingslashit($wp_rewrite->pagination_base) . get_query_var('paged')); } } } if ($canonical && isset($options['force_transport']) && 'default' != $options['force_transport']) { $canonical = preg_replace('/https?/', $options['force_transport'], $canonical); } $canonical = apply_filters('wpseo_canonical', $canonical); if ($canonical && !is_wp_error($canonical)) { if ($echo) { echo '<link rel="canonical" href="' . esc_url($canonical, null, 'other') . '" />' . "\n"; } else { return $canonical; } } }
/** * Gets the items for the breadcrumb trail. This is the heart of the script. It checks the current page * being viewed and decided based on the information provided by WordPress what items should be * added to the breadcrumb trail. * * @since 0.4.0 * @todo Build in caching based on the queried object ID. * @access public * @param array $args Mixed arguments for the menu. * @return array List of items to be shown in the trail. */ function tc_breadcrumb_trail_get_items($args = array()) { global $wp_rewrite; /* Set up an empty trail array and empty path. */ $trail = array(); $path = ''; /* If $show_home is set and we're not on the front page of the site, link to the home page. */ if (!is_front_page() && $args['show_home']) { if (is_multisite() && true === $args['network']) { $trail[] = '<a href="' . network_home_url() . '">' . $args['show_home'] . '</a>'; $trail[] = '<a href="' . esc_url(home_url()) . '" title="' . esc_attr(get_bloginfo('name')) . '" rel="home" class="trail-begin">' . get_bloginfo('name') . '</a>'; } else { $trail[] = '<a href="' . esc_url(home_url()) . '" title="' . esc_attr(get_bloginfo('name')) . '" rel="home" class="trail-begin">' . $args['show_home'] . '</a>'; } } /* If bbPress is installed and we're on a bbPress page. */ if (function_exists('is_bbpress') && is_bbpress()) { $trail = array_merge($trail, tc_breadcrumb_trail_get_bbpress_items()); } elseif (is_front_page()) { if (!is_paged() && $args['show_home'] && $args['front_page']) { if (is_multisite() && true === $args['network']) { $trail[] = '<a href="' . network_home_url() . '">' . $args['show_home'] . '</a>'; $trail[] = get_bloginfo('name'); } else { $trail[] = $args['show_home']; } } elseif (is_paged() && $args['show_home'] && $args['front_page']) { if (is_multisite() && true === $args['network']) { $trail[] = '<a href="' . network_home_url() . '">' . $args['show_home'] . '</a>'; $trail[] = '<a href="' . esc_url(home_url()) . '" title="' . esc_attr(get_bloginfo('name')) . '" rel="home" class="trail-begin">' . get_bloginfo('name') . '</a>'; } else { $trail[] = '<a href="' . esc_url(home_url()) . '" title="' . esc_attr(get_bloginfo('name')) . '" rel="home" class="trail-begin">' . $args['show_home'] . '</a>'; } } } elseif (is_home()) { $home_page = get_page(get_queried_object_id()); $trail = array_merge($trail, tc_breadcrumb_trail_get_parents($home_page->post_parent, '')); if (is_paged()) { $trail[] = '<a href="' . get_permalink($home_page->ID) . '" title="' . esc_attr(get_the_title($home_page->ID)) . '">' . get_the_title($home_page->ID) . '</a>'; } else { $trail[] = get_the_title($home_page->ID); } } elseif (is_singular()) { /* Get singular post variables needed. */ $post = get_queried_object(); $post_id = absint(get_queried_object_id()); $post_type = $post->post_type; $parent = absint($post->post_parent); /* Get the post type object. */ $post_type_object = get_post_type_object($post_type); /* If viewing a singular 'post'. */ if ('post' == $post_type) { /* If $front has been set, add it to the $path. */ $path .= trailingslashit($wp_rewrite->front); /* If there's a path, check for parents. */ if (!empty($path)) { $trail = array_merge($trail, tc_breadcrumb_trail_get_parents('', $path)); } /* Map the permalink structure tags to actual links. */ $trail = array_merge($trail, tc_breadcrumb_trail_map_rewrite_tags($post_id, get_option('permalink_structure'), $args)); } elseif ('attachment' == $post_type) { /* Get the parent post ID. */ $parent_id = $post->post_parent; /* If the attachment has a parent (attached to a post). */ if (0 < $parent_id) { /* Get the parent post type. */ $parent_post_type = get_post_type($parent_id); /* If the post type is 'post'. */ if ('post' == $parent_post_type) { /* If $front has been set, add it to the $path. */ $path .= trailingslashit($wp_rewrite->front); /* If there's a path, check for parents. */ if (!empty($path)) { $trail = array_merge($trail, tc_breadcrumb_trail_get_parents('', $path)); } /* Map the post (parent) permalink structure tags to actual links. */ $trail = array_merge($trail, tc_breadcrumb_trail_map_rewrite_tags($post->post_parent, get_option('permalink_structure'), $args)); } elseif ('page' !== $parent_post_type) { $parent_post_type_object = get_post_type_object($parent_post_type); /* If $front has been set, add it to the $path. */ if ($parent_post_type_object->rewrite['with_front'] && $wp_rewrite->front) { $path .= trailingslashit($wp_rewrite->front); } /* If there's a slug, add it to the $path. */ if (!empty($parent_post_type_object->rewrite['slug'])) { $path .= $parent_post_type_object->rewrite['slug']; } /* If there's a path, check for parents. */ if (!empty($path)) { $trail = array_merge($trail, tc_breadcrumb_trail_get_parents('', $path)); } /* If there's an archive page, add it to the trail. */ if (!empty($parent_post_type_object->has_archive)) { /* Add support for a non-standard label of 'archive_title' (special use case). */ $label = !empty($parent_post_type_object->labels->archive_title) ? $parent_post_type_object->labels->archive_title : $parent_post_type_object->labels->name; $trail[] = '<a href="' . get_post_type_archive_link($parent_post_type) . '" title="' . esc_attr($label) . '">' . $label . '</a>'; } } } } elseif ('page' !== $post_type) { /* If $front has been set, add it to the $path. */ if (isset($post_type_object) && $post_type_object->rewrite['with_front'] && $wp_rewrite->front) { $path .= trailingslashit($wp_rewrite->front); } /* If there's a slug, add it to the $path. */ if (!empty($post_type_object->rewrite['slug'])) { $path .= $post_type_object->rewrite['slug']; } /* If there's a path, check for parents. */ if (!empty($path)) { $trail = array_merge($trail, tc_breadcrumb_trail_get_parents('', $path)); } /* If there's an archive page, add it to the trail. */ if (!empty($post_type_object->has_archive)) { /* Add support for a non-standard label of 'archive_title' (special use case). */ $label = !empty($post_type_object->labels->archive_title) ? $post_type_object->labels->archive_title : $post_type_object->labels->name; $trail[] = '<a href="' . get_post_type_archive_link($post_type) . '" title="' . esc_attr($label) . '">' . $label . '</a>'; } } /* If the post type path returns nothing and there is a parent, get its parents. */ if (empty($path) && 0 !== $parent || 'attachment' == $post_type) { $trail = array_merge($trail, tc_breadcrumb_trail_get_parents($parent, '')); } elseif (0 !== $parent && is_post_type_hierarchical($post_type)) { $trail = array_merge($trail, tc_breadcrumb_trail_get_parents($parent, '')); } /* Display terms for specific post type taxonomy if requested. */ if (!empty($args["singular_{$post_type}_taxonomy"]) && ($terms = get_the_term_list($post_id, $args["singular_{$post_type}_taxonomy"], '', ', ', ''))) { $trail[] = $terms; } /* End with the post title. */ $post_title = single_post_title('', false); if (1 < get_query_var('page') && !empty($post_title)) { $trail[] = '<a href="' . get_permalink($post_id) . '" title="' . esc_attr($post_title) . '">' . $post_title . '</a>'; } elseif (!empty($post_title)) { $trail[] = $post_title; } } elseif (is_archive()) { /* If viewing a taxonomy term archive. */ if (is_tax() || is_category() || is_tag()) { /* Get some taxonomy and term variables. */ $term = get_queried_object(); $taxonomy = get_taxonomy($term->taxonomy); /* Get the path to the term archive. Use this to determine if a page is present with it. */ if (is_category()) { $path = get_option('category_base'); } elseif (is_tag()) { $path = get_option('tag_base'); } else { if ($taxonomy->rewrite['with_front'] && $wp_rewrite->front) { $path = trailingslashit($wp_rewrite->front); } $path .= $taxonomy->rewrite['slug']; } /* Get parent pages by path if they exist. */ if ($path) { $trail = array_merge($trail, tc_breadcrumb_trail_get_parents('', $path)); } /* Add post type archive if its 'has_archive' matches the taxonomy rewrite 'slug'. */ if ($taxonomy->rewrite['slug']) { /* Get public post types that match the rewrite slug. */ $post_types = get_post_types(array('public' => true, 'has_archive' => $taxonomy->rewrite['slug']), 'objects'); /** * If any post types are found, loop through them to find one that matches. * The reason for this is because WP doesn't match the 'has_archive' string * exactly when calling get_post_types(). I'm assuming it just matches 'true'. */ if (!empty($post_types)) { foreach ($post_types as $post_type_object) { if ($taxonomy->rewrite['slug'] === $post_type_object->has_archive) { /* Add support for a non-standard label of 'archive_title' (special use case). */ $label = !empty($post_type_object->labels->archive_title) ? $post_type_object->labels->archive_title : $post_type_object->labels->name; /* Add the post type archive link to the trail. */ $trail[] = '<a href="' . get_post_type_archive_link($post_type_object->name) . '" title="' . esc_attr($label) . '">' . $label . '</a>'; /* Break out of the loop. */ break; } } } } /* If the taxonomy is hierarchical, list its parent terms. */ if (is_taxonomy_hierarchical($term->taxonomy) && $term->parent) { $trail = array_merge($trail, tc_breadcrumb_trail_get_term_parents($term->parent, $term->taxonomy)); } /* Add the term name to the trail end. */ if (is_paged()) { $trail[] = '<a href="' . esc_url(get_term_link($term, $term->taxonomy)) . '" title="' . esc_attr(single_term_title('', false)) . '">' . single_term_title('', false) . '</a>'; } else { $trail[] = single_term_title('', false); } } elseif (is_post_type_archive()) { /* Get the post type object. */ $post_type_object = get_post_type_object(get_query_var('post_type')); /* If $front has been set, add it to the $path. */ if ($post_type_object->rewrite['with_front'] && $wp_rewrite->front) { $path .= trailingslashit($wp_rewrite->front); } /* If there's a slug, add it to the $path. */ if (!empty($post_type_object->rewrite['slug'])) { $path .= $post_type_object->rewrite['slug']; } /* If there's a path, check for parents. */ if (!empty($path)) { $trail = array_merge($trail, tc_breadcrumb_trail_get_parents('', $path)); } /* Add the post type [plural] name to the trail end. */ if (is_paged()) { $trail[] = '<a href="' . esc_url(get_post_type_archive_link($post_type_object->name)) . '" title="' . esc_attr(post_type_archive_title('', false)) . '">' . post_type_archive_title('', false) . '</a>'; } else { $trail[] = post_type_archive_title('', false); } } elseif (is_author()) { /* Get the user ID. */ $user_id = get_query_var('author'); /* If $front has been set, add it to $path. */ if (!empty($wp_rewrite->front)) { $path .= trailingslashit($wp_rewrite->front); } /* If an $author_base exists, add it to $path. */ if (!empty($wp_rewrite->author_base)) { $path .= $wp_rewrite->author_base; } /* If $path exists, check for parent pages. */ if (!empty($path)) { $trail = array_merge($trail, tc_breadcrumb_trail_get_parents('', $path)); } /* Add the author's display name to the trail end. */ if (is_paged()) { $trail[] = '<a href="' . esc_url(get_author_posts_url($user_id)) . '" title="' . esc_attr(get_the_author_meta('display_name', $user_id)) . '">' . get_the_author_meta('display_name', $user_id) . '</a>'; } else { $trail[] = get_the_author_meta('display_name', $user_id); } } elseif (is_time()) { if (get_query_var('minute') && get_query_var('hour')) { $trail[] = get_the_time(__('g:i a', 'breadcrumb-trail')); } elseif (get_query_var('minute')) { $trail[] = sprintf(__('Minute %1$s', 'breadcrumb-trail'), get_the_time(__('i', 'breadcrumb-trail'))); } elseif (get_query_var('hour')) { $trail[] = get_the_time(__('g a', 'breadcrumb-trail')); } } elseif (is_date()) { /* If $front has been set, check for parent pages. */ if ($wp_rewrite->front) { $trail = array_merge($trail, tc_breadcrumb_trail_get_parents('', $wp_rewrite->front)); } if (is_day()) { $trail[] = '<a href="' . get_year_link(get_the_time('Y')) . '" title="' . get_the_time(esc_attr__('Y', 'breadcrumb-trail')) . '">' . get_the_time(__('Y', 'breadcrumb-trail')) . '</a>'; $trail[] = '<a href="' . get_month_link(get_the_time('Y'), get_the_time('m')) . '" title="' . get_the_time(esc_attr__('F', 'breadcrumb-trail')) . '">' . get_the_time(__('F', 'breadcrumb-trail')) . '</a>'; if (is_paged()) { $trail[] = '<a href="' . get_day_link(get_the_time('Y'), get_the_time('m'), get_the_time('d')) . '" title="' . get_the_time(esc_attr__('d', 'breadcrumb-trail')) . '">' . get_the_time(__('d', 'breadcrumb-trail')) . '</a>'; } else { $trail[] = get_the_time(__('d', 'breadcrumb-trail')); } } elseif (get_query_var('w')) { $trail[] = '<a href="' . get_year_link(get_the_time('Y')) . '" title="' . get_the_time(esc_attr__('Y', 'breadcrumb-trail')) . '">' . get_the_time(__('Y', 'breadcrumb-trail')) . '</a>'; if (is_paged()) { $trail[] = get_archives_link(add_query_arg(array('m' => get_the_time('Y'), 'w' => get_the_time('W')), esc_url(home_url())), sprintf(__('Week %1$s', 'breadcrumb-trail'), get_the_time(esc_attr__('W', 'breadcrumb-trail'))), false); } else { $trail[] = sprintf(__('Week %1$s', 'breadcrumb-trail'), get_the_time(esc_attr__('W', 'breadcrumb-trail'))); } } elseif (is_month()) { $trail[] = '<a href="' . get_year_link(get_the_time('Y')) . '" title="' . get_the_time(esc_attr__('Y', 'breadcrumb-trail')) . '">' . get_the_time(__('Y', 'breadcrumb-trail')) . '</a>'; if (is_paged()) { $trail[] = '<a href="' . get_month_link(get_the_time('Y'), get_the_time('m')) . '" title="' . get_the_time(esc_attr__('F', 'breadcrumb-trail')) . '">' . get_the_time(__('F', 'breadcrumb-trail')) . '</a>'; } else { $trail[] = get_the_time(__('F', 'breadcrumb-trail')); } } elseif (is_year()) { if (is_paged()) { $trail[] = '<a href="' . get_year_link(get_the_time('Y')) . '" title="' . esc_attr(get_the_time(__('Y', 'breadcrumb-trail'))) . '">' . get_the_time(__('Y', 'breadcrumb-trail')) . '</a>'; } else { $trail[] = get_the_time(__('Y', 'breadcrumb-trail')); } } } } elseif (is_search()) { if (is_paged()) { $trail[] = '<a href="' . get_search_link() . '" title="' . sprintf(esc_attr__('Search results for "%1$s"', 'breadcrumb-trail'), esc_attr(get_search_query())) . '">' . sprintf(__('Search results for "%1$s"', 'breadcrumb-trail'), esc_attr(get_search_query())) . '</a>'; } else { $trail[] = sprintf(__('Search results for "%1$s"', 'breadcrumb-trail'), esc_attr(get_search_query())); } } elseif (is_404()) { $trail[] = __('404 Not Found', 'breadcrumb-trail'); } /* Check for pagination. */ if (is_paged()) { $trail[] = sprintf(__('Page %d', 'breadcrumb-trail'), absint(get_query_var('paged'))); } elseif (is_singular() && 1 < get_query_var('page')) { $trail[] = sprintf(__('Page %d', 'breadcrumb-trail'), absint(get_query_var('page'))); } /* Allow devs to step in and filter the $trail array. */ return apply_filters('breadcrumb_trail_items', $trail, $args); }
public function testThemeTemplateIsCorrectForSearch() { $this->go_to_with_template(get_search_link('foo')); $this->assertTrue(is_search()); $this->assertSame('search.php', self::get_theme_data('template_file')); }
function ktz_get_AGC_single() { if (ot_get_option('ktz_agc_activated') == "yes") { $orititle = get_the_title(); $orititle = trim($orititle); $termstring = $orititle; if ($orititle != '') { echo '<div class="box-post single relpost">'; echo '<h4 class="ktz-agc-title"><span class="ktz-blocktitle">' . __('Related Search', ktz_theme_textdomain) . '</span></h4>'; echo '<ul class="ktz-agc-single">'; $googleresults = perform_google_web_search_single($termstring); if (is_array($googleresults)) { $i = 0; foreach ($googleresults as $result) { $link = urldecode(CleanFileNameBan(strip_tags($result['Oriurl']))); $i++; if ($i < 5) { echo '<li class="clearfix">'; echo '<div class="content-related">'; echo '<a title="' . CleanFileNameBan(hilangkan_spesial_karakter($result['title'])) . '" href="' . get_search_link(CleanFileNameBan(hilangkan_spesial_karakter($result['title']))) . '">' . CleanFileNameBan(hilangkan_spesial_karakter($result['title'])) . '</a>'; echo '</div></li>'; } } } echo '</ul>'; echo '</div>'; } } }
/** * 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; } }
/** * Retrieve the permalink for the feed of the search results. * * @since 2.5.0 * * @param string $search_query Optional. Search query. * @param string $feed Optional. Feed type. * @return string */ function get_search_feed_link($search_query = '', $feed = '') { global $wp_rewrite; $link = get_search_link($search_query); if (empty($feed)) { $feed = get_default_feed(); } $permastruct = $wp_rewrite->get_search_permastruct(); if (empty($permastruct)) { $link = add_query_arg('feed', $feed, $link); } else { $link = trailingslashit($link); $link .= "feed/{$feed}/"; } $link = apply_filters('search_feed_link', $link, $feed, 'posts'); return $link; }
/** * This function normally outputs the canonical but is also used in other places to retrieve * the canonical URL for the current page. * * @return void */ private function generate_canonical() { $canonical = false; $canonical_override = false; // Set decent canonicals for homepage, singulars and taxonomy pages if (is_singular()) { $obj = get_queried_object(); $canonical = get_permalink($obj->ID); $this->canonical_unpaged = $canonical; $canonical_override = WPSEO_Meta::get_value('canonical'); // Fix paginated pages canonical, but only if the page is truly paginated. if (get_query_var('page') > 1) { $num_pages = substr_count($obj->post_content, '<!--nextpage-->') + 1; if ($num_pages && get_query_var('page') <= $num_pages) { if (!$GLOBALS['wp_rewrite']->using_permalinks()) { $canonical = add_query_arg('page', get_query_var('page'), $canonical); } else { $canonical = user_trailingslashit(trailingslashit($canonical) . get_query_var('page')); } } } } 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(); $canonical_override = WPSEO_Taxonomy_Meta::get_term_meta($term, $term->taxonomy, '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')); } } } $this->canonical_unpaged = $canonical; if ($canonical && get_query_var('paged') > 1) { global $wp_rewrite; if (!$wp_rewrite->using_permalinks()) { if (is_front_page()) { $canonical = trailingslashit($canonical); } $canonical = add_query_arg('paged', get_query_var('paged'), $canonical); } else { if (is_front_page()) { $canonical = wpseo_xml_sitemaps_base_url(''); } $canonical = user_trailingslashit(trailingslashit($canonical) . trailingslashit($wp_rewrite->pagination_base) . get_query_var('paged')); } } } $this->canonical_no_override = $canonical; if (is_string($canonical) && $canonical !== '') { // Force canonical links to be absolute, relative is NOT an option. if (WPSEO_Utils::is_url_relative($canonical) === true) { $canonical = $this->base_url($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_override) && $canonical_override !== '') { $this->canonical = $canonical_override; } else { $this->canonical = $canonical; } }
/** * Ask for specific translations with arguments. * * * @see prepare_translation_arguments() * @param array $args { * * Optional. If left out, some magic happens. * * @type int $site_id Base site * @type int $content_id post or term_taxonomy ID, *not* term ID * @type string $type @see Mlp_Language_Api::get_request_type() * @type bool $strict When TRUE (default) only matching exact * translations will be included * @type string $search_term If you want to translate a search * @type string $post_type For post type archives * @type bool $include_base Include the base site in returned list * * } * @return array Array of Mlp_Translation instances, site IDs are the keys */ public function get_translations(array $args = array()) { /** @type WP_Rewrite $wp_rewrite */ global $wp_rewrite; $arguments = $this->prepare_translation_arguments($args); $key = md5(serialize($arguments)); $content_relations = array(); $cached = wp_cache_get($key, 'mlp'); if (is_array($cached)) { return $cached; } $sites = $this->get_related_sites($arguments['site_id'], $arguments['include_base']); if (empty($sites)) { return array(); } if (!empty($arguments['content_id'])) { // array with site_ids as keys, content_ids as values $content_relations = $this->get_related_content_ids($arguments['site_id'], $arguments['content_id'], $arguments['type']); if (empty($content_relations) && $arguments['strict']) { return array(); } } $translations = array(); $languages = $this->get_all_language_data(); foreach ($sites as $site_id) { if (!isset($languages[$site_id])) { continue; } $translations[$site_id] = array('source_site_id' => $arguments['site_id'], 'target_site_id' => $site_id, 'type' => $arguments['type'], 'target_content_id' => 0, 'target_title' => ''); } reset($translations); foreach ($translations as $site_id => &$arr) { $valid = TRUE; if (!empty($content_relations[$site_id])) { $content_id = $content_relations[$site_id]; $arr['target_content_id'] = $content_id; if ('term' === $arguments['type']) { $term_translation = new Mlp_Term_Translation($this->wpdb, $wp_rewrite); $translation = $term_translation->get_translation($content_id, $site_id); if (!$translation) { $valid = FALSE; } else { $arr = array_merge($arr, $translation); } } elseif ('post' === $arguments['type']) { switch_to_blog($site_id); $translation = $this->get_post_translation($content_relations[$site_id], $arguments['strict']); if (!$translation) { $valid = FALSE; } else { $arr = array_merge($arr, $translation); } restore_current_blog(); } } else { switch_to_blog($site_id); if ('search' === $arguments['type']) { $url = get_search_link($arguments['search_term']); $arr['target_url'] = new Mlp_Url($url); } elseif ('post_type_archive' === $arguments['type'] && !empty($arguments['post_type'])) { $translation = $this->get_post_type_archive_translation($arguments['post_type']); $arr = array_merge($arr, $translation); } // Nothing found, use fallback if allowed if (empty($arr['target_url']) && !$arguments['strict'] || 'front_page' === $arguments['type']) { $arr['target_url'] = get_site_url($site_id, '/'); } if (empty($arr['target_url'])) { $valid = FALSE; } restore_current_blog(); } if (!$valid) { unset($translations[$site_id]); continue; } $data = $languages[$site_id]; if (!isset($data['http_name'])) { if (isset($data['lang'])) { $data['http_name'] = $data['lang']; } else { $data['http_name'] = ''; } } if ('' !== $data['http_name']) { $arr['icon'] = $this->get_flag_by_language($data['http_name'], $site_id); } $arr = new Mlp_Translation($arr, new Mlp_Language($data)); } /** * Filter list of translations before they are used. * * @param array $translations Prepared translations * @param array $arguments Prepared arguments */ $translations = apply_filters('mlp_translations', $translations, $arguments); wp_cache_set($key, $translations, 'mlp'); return $translations; }
/** * @return array An array of URLs to be analyzed. The number of * URLs varies based on the WordPress configuration. */ public static function getUrlsToAnalyze() { $urls = array(); $siteUrl = self::getFrontPageUrl(); $urls['siteUrl'] = $siteUrl; $latestPostUrl = self::getLatestPostUrl(); if ($latestPostUrl != '') { $urls['latestPostUrl'] = $latestPostUrl; } $postsUrl = self::getPostsUrl(); if ($postsUrl != '') { $urls['postsUrl'] = $postsUrl; } $latestSinglePageUrl = self::getLatestSinglePageUrl($siteUrl, $postsUrl); if ($latestSinglePageUrl != '') { $urls['latestSinglePageUrl'] = $latestSinglePageUrl; } $latestArchiveUrl = self::getLatestArchiveUrl(); if ($latestArchiveUrl != '') { $urls['latestArchiveUrl'] = $latestArchiveUrl; } $categoryUrl = self::getCategoryUrl(); if ($categoryUrl != '') { $urls['categoryUrl'] = $categoryUrl; } $urls['searchUrl'] = get_search_link('wordpress'); return $urls; }
public function get_sharing_url($use_post = false, $add_page = true, $source_id = false) { $url = false; if (is_singular() || $use_post !== false) { if (($obj = $this->get_post_object($use_post)) === false) { return $url; } $post_id = empty($obj->ID) || empty($obj->post_type) ? 0 : $obj->ID; if (!empty($post_id)) { if (isset($this->p->mods['util']['post'])) { $url = $this->p->mods['util']['post']->get_options($post_id, 'sharing_url'); } if (!empty($url)) { if ($this->p->debug->enabled) { $this->p->debug->log('custom post sharing_url = ' . $url); } } else { $url = get_permalink($post_id); } if ($add_page && 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() || strpos($url, '?') !== false) { $url = add_query_arg('page', get_query_var('page'), $url); } else { $url = user_trailingslashit(trailingslashit($url) . get_query_var('page')); } } } } $url = apply_filters($this->p->cf['lca'] . '_post_url', $url, $post_id, $use_post, $add_page, $source_id); } else { if (is_search()) { $url = get_search_link(); } elseif (is_front_page()) { $url = apply_filters($this->p->cf['lca'] . '_home_url', home_url('/')); } elseif ($this->is_posts_page()) { $url = get_permalink(get_option('page_for_posts')); } elseif (self::is_term_page()) { $term = $this->get_term_object(); if (!empty($term->term_id)) { if (isset($this->p->mods['util']['taxonomy'])) { $url = $this->p->mods['util']['taxonomy']->get_options($term->term_id, 'sharing_url'); } if (!empty($url)) { if ($this->p->debug->enabled) { $this->p->debug->log('custom taxonomy sharing_url = ' . $url); } } else { $url = get_term_link($term, $term->taxonomy); } } $url = apply_filters($this->p->cf['lca'] . '_term_url', $url, $term); } elseif (self::is_author_page()) { $author = $this->get_author_object(); if (!empty($author->ID)) { if (isset($this->p->mods['util']['user'])) { $url = $this->p->mods['util']['user']->get_options($author->ID, 'sharing_url'); } if (!empty($url)) { if ($this->p->debug->enabled) { $this->p->debug->log('custom user sharing_url = ' . $url); } } else { $url = get_author_posts_url($author->ID); } } $url = apply_filters($this->p->cf['lca'] . '_author_url', $url, $author); } elseif (function_exists('get_post_type_archive_link') && is_post_type_archive()) { $url = get_post_type_archive_link(get_query_var('post_type')); } elseif (is_archive()) { if (is_date()) { if (is_day()) { $url = get_day_link(get_query_var('year'), get_query_var('monthnum'), get_query_var('day')); } elseif (is_month()) { $url = get_month_link(get_query_var('year'), get_query_var('monthnum')); } elseif (is_year()) { $url = get_year_link(get_query_var('year')); } } } if (!empty($url) && $add_page && get_query_var('paged') > 1) { global $wp_rewrite; if (!$wp_rewrite->using_permalinks()) { $url = add_query_arg('paged', get_query_var('paged'), $url); } else { if (is_front_page()) { $base = $GLOBALS['wp_rewrite']->using_index_permalinks() ? 'index.php/' : '/'; $url = home_url($base); } $url = user_trailingslashit(trailingslashit($url) . trailingslashit($wp_rewrite->pagination_base) . get_query_var('paged')); } } } // fallback for themes and plugins that don't use the standard wordpress functions/variables if (empty($url)) { $url = empty($_SERVER['HTTPS']) ? 'http://' : 'https://'; $url .= $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']; // strip out tracking query arguments by facebook, google, etc. $url = preg_replace('/([\\?&])(fb_action_ids|fb_action_types|fb_source|fb_aggregation_id|utm_source|utm_medium|utm_campaign|utm_term|gclid|pk_campaign|pk_kwd)=[^&]*&?/i', '$1', $url); } return apply_filters($this->p->cf['lca'] . '_sharing_url', $url, $use_post, $add_page, $source_id); }
function render_view_loop_selection_form( $view_id = 0 ) { global $WPV_view_archive_loop, $WPV_settings; $WPV_view_archive_loop->_view_edit_options( $view_id, $WPV_settings ); // TODO check if we just need the $WPV_settings above $asterisk = ' <span style="color:red">*</span>'; $asterisk_explanation = __( '<span style="color:red">*</span> A different WordPress Archive is already assigned to this item', 'wpv-views' ); $show_asterisk_explanation = false; // Label and template for "View archive" link. $view_archive_template = '<span style="margin-left: 3px;"></span><a style="text-decoration: none;" target="_blank" href="%s"><i class="icon-external-link icon-small"></i></a>'; // Prepare archive URL for different loops. $recent_posts = get_posts( array( "posts_per_page" => 1 ) ); $default_search_term = __( 'something', 'wpv-views' ); if( !empty( $recent_posts ) ) { $recent_post = reset( $recent_posts ); // Try to get first word of the post and use it as a search term for search-page loop. $recent_post_content = explode( " ", strip_tags( $recent_post->post_content ), 1 ); $first_word_in_post = reset( $recent_post_content ); if( false != $first_word_in_post ) { $search_page_archive_url = get_search_link( $first_word_in_post ); } else { // No first word, the post is empty (wordless after striping html tags, to be precise). $search_page_archive_url = get_search_link( $default_search_term ); } $post_date = new DateTime( $recent_post->post_date ); } else { // No recent post exists, use default values. $search_page_archive_url = get_search_link( $default_search_term ); $post_date = new DateTime(); // now } $post_year = $post_date->format( "Y" ); $post_month = $post_date->format( "n" ); $post_day = $post_date->format( "j" ); /* $loops: Definition of standard WP loops, each array element contains array of "display_name" and "archive_url" * (url to display the archive in frontend). */ $loops = array( 'home-blog-page' => array( "display_name" => __( 'Home/Blog', 'wpv-views' ), "archive_url" => home_url() ), 'search-page' => array( "display_name" => __( 'Search results', 'wpv-views' ), "archive_url" => $search_page_archive_url ), 'author-page' => array( "display_name" => __( 'Author archives', 'wpv-views' ), "archive_url" => get_author_posts_url( get_current_user_id() ) ), 'year-page' => array( "display_name" => __( 'Year archives', 'wpv-views' ), "archive_url" => get_year_link( $post_year ) ), 'month-page' => array( "display_name" => __( 'Month archives', 'wpv-views' ), "archive_url" => get_month_link( $post_year, $post_month ) ), 'day-page' => array( "display_name" => __( 'Day archives', 'wpv-views' ), "archive_url" => get_day_link( $post_year, $post_month, $post_day ) ) ); // === Selection for Standard Archives === // ?> <h3><?php _e( 'Standard Archives', 'wpv-views' ); ?></h3> <div class="wpv-advanced-setting"> <ul class="enable-scrollbar wpv-mightlong-list"> <?php foreach ( $loops as $loop => $loop_definition ) { $show_asterisk = false; $is_checked = ( isset( $WPV_settings['view_' . $loop] ) && $WPV_settings['view_' . $loop] == $view_id ); if ( isset( $WPV_settings['view_' . $loop] ) && $WPV_settings['view_' . $loop] != $view_id && $WPV_settings['view_' . $loop] != 0 ) { $show_asterisk = true; $show_asterisk_explanation = true; } ?> <li> <input type="checkbox" <?php checked( $is_checked ); ?> id="wpv-view-loop-<?php echo esc_attr( $loop ); ?>" name="wpv-view-loop-<?php echo esc_attr( $loop ); ?>" autocomplete="off" /> <label for="wpv-view-loop-<?php echo esc_attr( $loop ); ?>"><?php echo $loop_definition[ "display_name" ]; echo $show_asterisk ? $asterisk : ''; ?></label> <?php if( $is_checked ) { printf( $view_archive_template, $loop_definition[ "archive_url" ] ); } ?> </li> <?php } ?> </ul> <?php if ( $show_asterisk_explanation ) { ?> <span class="wpv-options-box-info"> <?php echo $asterisk_explanation; ?> </span> <?php } ?> </div> <?php // === Selection for Custom Post Archives === // /* Definition of post type archive loops. Keys are post type slugs and each array element contains array of * "display_name" and "archive_url" (url to display the archive in frontend) and "loop".*/ $pt_loops = array(); $show_asterisk_explanation = false; // Only offer loops for post types that already have an archive $post_types = get_post_types( array( 'public' => true, 'has_archive' => true), 'objects' ); foreach ( $post_types as $post_type ) { if ( ! in_array( $post_type->name, array( 'post', 'page', 'attachment' ) ) ) { $pt_loops[ $post_type->name ] = array( 'loop' => 'cpt_' . $post_type->name, 'display_name' => $post_type->labels->name, 'archive_url' => get_post_type_archive_link( $post_type->name ) ); } } if ( count( $pt_loops ) > 0 ) { ?> <h3><?php _e( 'Custom Post Archives', 'wpv-views' ); ?></h3> <div class="wpv-advanced-setting"> <ul class="enable-scrollbar wpv-mightlong-list"> <?php foreach ( $pt_loops as $loop_definition ) { $loop = $loop_definition[ 'loop' ]; $show_asterisk = false; $is_checked = ( isset( $WPV_settings['view_' . $loop] ) && $WPV_settings['view_' . $loop] == $view_id ); if ( isset( $WPV_settings['view_' . $loop] ) && $WPV_settings['view_' . $loop] != $view_id && $WPV_settings['view_' . $loop] != 0 ) { $show_asterisk = true; $show_asterisk_explanation = true; } ?> <li > <input type="checkbox" <?php checked( $is_checked ); ?> id="wpv-view-loop-<?php echo esc_attr( $loop ); ?>" name="wpv-view-loop-<?php echo esc_attr( $loop ); ?>" autocomplete="off" /> <label for="wpv-view-loop-<?php echo esc_attr( $loop ); ?>"> <?php echo $loop_definition[ 'display_name' ]; echo $show_asterisk ? $asterisk : ''; ?> </label> <?php if( $is_checked ) { printf( $view_archive_template, $loop_definition[ 'archive_url' ] ); } ?> </li> <?php } ?> </ul> <?php if ( $show_asterisk_explanation ) { ?> <span class="wpv-options-box-info"> <?php echo $asterisk_explanation; ?> </span> <?php } ?> </div> <?php } // === Selection for Taxonomy Archives === // $taxonomies = get_taxonomies( '', 'objects' ); $exclude_tax_slugs = apply_filters( 'wpv_admin_exclude_tax_slugs', array() ); // TODO get_terms( $taxonomies, array( "fields" => "id", hide_empty => 1 ) ) // and then get_term_link( $term_id, $taxonomy_slug ) // get_terms( $taxonomy_slug, array( "fields" => "id", "hide_empty" => 1, "number" => 1 ) ) ?> <h3><?php _e( 'Taxonomy Archives', 'wpv-views' ); ?></h3> <?php $show_asterisk_explanation = false; ?> <div class="wpv-advanced-setting"> <ul class="enable-scrollbar wpv-mightlong-list"> <?php foreach ( $taxonomies as $category_slug => $category ) { if ( in_array( $category_slug, $exclude_tax_slugs ) ) { continue; } // Only show taxonomies with show_ui set to TRUE if ( !$category->show_ui ) { continue; } $name = $category->name; $show_asterisk = false; $is_checked = ( isset( $WPV_settings['view_taxonomy_loop_' . $name ] ) && $WPV_settings['view_taxonomy_loop_' . $name ] == $view_id ); if ( isset( $WPV_settings['view_taxonomy_loop_' . $name ] ) && $WPV_settings['view_taxonomy_loop_' . $name ] != $view_id && $WPV_settings['view_taxonomy_loop_' . $name ] != 0 ) { $show_asterisk = true; $show_asterisk_explanation = true; } ?> <li> <input type="checkbox" <?php checked( $is_checked ); ?> id="wpv-view-taxonomy-loop-<?php echo esc_attr( $name ); ?>" name="wpv-view-taxonomy-loop-<?php echo esc_attr( $name ); ?>" autocomplete="off" /> <label for="wpv-view-taxonomy-loop-<?php echo esc_attr( $name ); ?>"> <?php echo $category->labels->name; echo $show_asterisk ? $asterisk : ''; ?> </label> <?php if( $is_checked ) { // Get ID of a term that has some posts, if such term exists. $terms_with_posts = get_terms( $category_slug, array( "hide_empty" => 1, "number" => 1 ) ); if( ( $terms_with_posts instanceof WP_Error ) or empty( $terms_with_posts ) ) { printf( '<span style="margin-left: 3px;"></span><span style="color: grey"><i class="icon-external-link icon-small" title="%s"></i></span>', sprintf( __( 'The %s page cannot be viewed because no post has any %s.', 'wpv-views' ), $category->labels->name, $category->labels->singular_name ) ); } else { $term = $terms_with_posts[0]; printf( $view_archive_template, get_term_link( $term, $category_slug ) ); } } ?> </li> <?php } ?> </ul> <?php if ( $show_asterisk_explanation ) { ?> <span class="wpv-options-box-info"> <?php echo $asterisk_explanation; ?> </span> <?php } ?> </div> <?php }
/** * Adds the items to the trail items array for search results. * * @since 1.0.0 * @access protected * @return void */ protected function add_search_items() { if (is_paged()) { $this->items[] = sprintf('<a href="%s">%s</a>', esc_url(get_search_link()), sprintf($this->labels['search'], get_search_query())); } elseif (true === $this->args['show_title']) { $this->items[] = sprintf($this->labels['search'], get_search_query()); } }
function dh_paginate_links($args = array(), $query = null) { global $wp_rewrite, $wp_query; do_action('dh_pagination_start'); if (empty($query)) { $query = $wp_query; } if (1 >= $query->max_num_pages) { return; } $paged = get_query_var('paged') ? absint(get_query_var('paged')) : 1; $max_num_pages = intval($query->max_num_pages); $defaults = array('base' => esc_url_raw(add_query_arg('paged', '%#%')), 'format' => '', 'total' => $max_num_pages, 'current' => $paged, 'prev_next' => true, 'prev_text' => '<i class="fa fa-angle-left"></i>', 'next_text' => '<i class="fa fa-angle-right"></i>', 'show_all' => false, 'end_size' => 1, 'mid_size' => 1, 'add_fragment' => '', 'type' => 'plain', 'before' => '<div class="paginate"><div class="paginate_links">', 'after' => '</div></div>', 'echo' => true, 'use_search_permastruct' => true); $defaults = apply_filters('dh_pagination_args_defaults', $defaults); if ($wp_rewrite->using_permalinks() && !is_search()) { $defaults['base'] = user_trailingslashit(trailingslashit(get_pagenum_link()) . 'page/%#%'); } if (is_search()) { $defaults['use_search_permastruct'] = false; } if (is_search()) { if (class_exists('BP_Core_User') || $defaults['use_search_permastruct'] == false) { $search_query = get_query_var('s'); $paged = get_query_var('paged'); $base = esc_url_raw(add_query_arg('s', urlencode($search_query))); $base = esc_url_raw(add_query_arg('paged', '%#%')); $defaults['base'] = $base; } else { $search_permastruct = $wp_rewrite->get_search_permastruct(); if (!empty($search_permastruct)) { $base = get_search_link(); $base = esc_url_raw(add_query_arg('paged', '%#%', $base)); $defaults['base'] = $base; } } } $args = wp_parse_args($args, $defaults); $args = apply_filters('dh_pagination_args', $args); if ('array' == $args['type']) { $args['type'] = 'plain'; } $pattern = '/\\?(.*?)\\//i'; preg_match($pattern, $args['base'], $raw_querystring); if (!empty($raw_querystring)) { if ($wp_rewrite->using_permalinks() && $raw_querystring) { $raw_querystring[0] = str_replace('', '', $raw_querystring[0]); } $args['base'] = str_replace($raw_querystring[0], '', $args['base']); $args['base'] .= substr($raw_querystring[0], 0, -1); } $page_links = paginate_links($args); $page_links = str_replace(array('&paged=1\'', '/page/1\''), '\'', $page_links); $page_links = $args['before'] . $page_links . $args['after']; $page_links = apply_filters('dh_pagination', $page_links); do_action('dh_pagination_end'); if ($args['echo']) { echo dhecho($page_links); } else { return $page_links; } }
function woo_pagination($args = array(), $query = '') { global $wp_rewrite, $wp_query; do_action('woo_pagination_start'); if ($query) { $wp_query = $query; } // End IF Statement /* If there's not more than one page, return nothing. */ if (1 >= $wp_query->max_num_pages) { return; } /* Get the current page. */ $current = get_query_var('paged') ? absint(get_query_var('paged')) : 1; /* Get the max number of pages. */ $max_num_pages = intval($wp_query->max_num_pages); /* Set up some default arguments for the paginate_links() function. */ $defaults = array('base' => esc_url_raw(add_query_arg('paged', '%#%')), 'format' => '', 'total' => $max_num_pages, 'current' => $current, 'prev_next' => true, 'prev_text' => __('← Previous', 'woothemes'), 'next_text' => __('Next →', 'woothemes'), 'show_all' => false, 'end_size' => 1, 'mid_size' => 1, 'add_fragment' => '', 'type' => 'plain', 'before' => '<div class="pagination woo-pagination">', 'after' => '</div>', 'echo' => true, 'use_search_permastruct' => true); /* Allow themes/plugins to filter the default arguments. */ $defaults = apply_filters('woo_pagination_args_defaults', $defaults); /* Add the $base argument to the array if the user is using permalinks. */ if ($wp_rewrite->using_permalinks() && !is_search()) { $defaults['base'] = user_trailingslashit(trailingslashit(get_pagenum_link()) . 'page/%#%'); } /* Force search links to use raw permastruct for more accurate multi-word searching. */ if (is_search()) { $defaults['use_search_permastruct'] = false; } /* If we're on a search results page, we need to change this up a bit. */ if (is_search()) { /* If we're in BuddyPress, or the user has selected to do so, use the default "unpretty" URL structure. */ if (class_exists('BP_Core_User') || $defaults['use_search_permastruct'] == false) { $search_query = get_query_var('s'); $paged = get_query_var('paged'); $base = add_query_arg('s', urlencode($search_query)); $base = add_query_arg('paged', '%#%'); $defaults['base'] = esc_url_raw($base); } else { $search_permastruct = $wp_rewrite->get_search_permastruct(); if (!empty($search_permastruct)) { $base = get_search_link(); $base = add_query_arg('paged', '%#%', $base); $defaults['base'] = esc_url_raw($base); } } } /* Merge the arguments input with the defaults. */ $args = wp_parse_args($args, $defaults); /* Allow developers to overwrite the arguments with a filter. */ $args = apply_filters('woo_pagination_args', $args); /* Don't allow the user to set this to an array. */ if ('array' == $args['type']) { $args['type'] = 'plain'; } /* Make sure raw querystrings are displayed at the end of the URL, if using pretty permalinks. */ $pattern = '/\\?(.*?)\\//i'; preg_match($pattern, $args['base'], $raw_querystring); if ($wp_rewrite->using_permalinks() && $raw_querystring) { $raw_querystring[0] = str_replace('', '', $raw_querystring[0]); } @($args['base'] = str_replace($raw_querystring[0], '', $args['base'])); @($args['base'] .= substr($raw_querystring[0], 0, -1)); /* Get the paginated links. */ $page_links = paginate_links($args); /* Remove 'page/1' from the entire output since it's not needed. */ $page_links = str_replace(array('&paged=1\'', '/page/1\''), '\'', $page_links); /* Wrap the paginated links with the $before and $after elements. */ $page_links = $args['before'] . $page_links . $args['after']; /* Allow devs to completely overwrite the output. */ $page_links = apply_filters('woo_pagination', $page_links); do_action('woo_pagination_end'); /* Return the paginated links for use in themes. */ if ($args['echo']) { echo $page_links; } else { return $page_links; } }
/** * Adds the items to the trail items array for search results. * * @since 0.6.0 * @access public * @return void */ public function do_search_items() { if (is_paged()) { $this->items[] = '<a href="' . esc_url(get_search_link()) . '">' . sprintf($this->args['labels']['search'], get_search_query()) . '</a>'; } elseif (true === $this->args['show_title']) { $this->items[] = sprintf($this->args['labels']['search'], get_search_query()); } }
/** * Custom callback for outputting comments * * @return void * @author Keir Whitaker */ function hca_search_more_posts_button($args, $search_query) { $default_args = array('see_all_text' => 'See all posts', 'no_items_found' => 'No posts found', 'found_posts' => 0, 'num_posts_to_display' => 4, 'post_type' => 'post'); $current_uri = get_search_link($search_query); $args = wp_parse_args($args, $default_args); if ($args['found_posts'] === 0) { echo '<div class="row"><div class="col-md-12 text-center"><p>' . $args['no_items_found'] . '</p></div></div>'; } elseif ($args['num_posts_to_display'] !== -1 && $args['found_posts'] > $args['num_posts_to_display']) { $url = remove_query_arg('js-post-type', $current_uri); $url = esc_url(add_query_arg('js-post-type', $args['post_type'], $url)); echo '<div class="row"><div class="col-md-12 text-center see-more"><a href="' . $url . '" class="btn btn-large btn-primary text-uppercase">'; echo $args['see_all_text']; echo '</a></div></div>'; } }
/** * Retrieve the permalink for the feed of the search results. * * @since 2.5.0 * * @global WP_Rewrite $wp_rewrite * * @param string $search_query Optional. Search query. * @param string $feed Optional. Feed type. * @return string The search results feed permalink. */ function get_search_feed_link($search_query = '', $feed = '') { global $wp_rewrite; $link = get_search_link($search_query); if (empty($feed)) { $feed = get_default_feed(); } $permastruct = $wp_rewrite->get_search_permastruct(); if (empty($permastruct)) { $link = add_query_arg('feed', $feed, $link); } else { $link = trailingslashit($link); $link .= "feed/{$feed}/"; } /** * Filter the search feed link. * * @since 2.5.0 * * @param string $link Search feed link. * @param string $feed Feed type. * @param string $type The search type. One of 'posts' or 'comments'. */ return apply_filters('search_feed_link', $link, $feed, 'posts'); }
function admin_bar_filter_load() { $Default_bar = $this->Admin_bar; $Delete_bar = array("top-secondary"); foreach ($Delete_bar as $del_name) { if (!empty($Default_bar[$del_name])) { unset($Default_bar[$del_name]); } } // front $Default_bar["dashboard"] = (object) array("id" => "dashboard", "title" => __('Dashboard'), "parent" => "site-name", "href" => admin_url(), "group" => false); foreach ($Default_bar as $node_id => $node) { if ($node->id == 'my-account') { $Default_bar[$node_id]->title = sprintf(__('Howdy, %1$s'), '[user_name]') . '[user_avatar]'; } elseif ($node->id == 'user-info') { $Default_bar[$node_id]->title = '[user_avatar_64]<span class="display-name">[user_name]</span><span class="username">[user_login_name]</span>'; } elseif ($node->id == 'logout') { $Default_bar[$node_id]->href = preg_replace('/&(.*)/', '', $node->href); } elseif ($node->id == 'site-name') { $Default_bar[$node_id]->title = '[blog_name]'; } elseif ($node->id == 'updates') { $Default_bar[$node_id]->title = '[update_total]'; } elseif ($node->id == 'comments') { $Default_bar[$node_id]->title = '[comment_count]'; } } $Filter_bar = array(); $MainMenuIDs = array(); foreach ($Default_bar as $node_id => $node) { if (empty($node->parent)) { $Filter_bar["left"]["main"][$node_id] = $node; $MainMenuIDs[$node_id] = "left"; unset($Default_bar[$node_id]); } elseif ($node->parent == 'top-secondary') { $Filter_bar["right"]["main"][$node_id] = $node; $MainMenuIDs[$node_id] = "right"; unset($Default_bar[$node_id]); } } // meta field add foreach ($Default_bar as $node_id => $node) { if (!isset($node->meta)) { $Default_bar[$node_id]->meta = array(); } } // sub node foreach ($MainMenuIDs as $parent_id => $menu_type) { foreach ($Default_bar as $node_id => $node) { if ($node->parent == $parent_id) { $Filter_bar[$menu_type]["sub"][$node_id] = $node; unset($Default_bar[$node_id]); } } } $Place_types = $this->admin_bar_places(); // sub2 node if (!empty($Default_bar)) { foreach ($Place_types as $place => $place_label) { if (!empty($Filter_bar[$place]["sub"]) && $place != 'front') { foreach ($Filter_bar[$place]["sub"] as $parent_id => $parent_node) { foreach ($Default_bar as $node_id => $node) { if ($node->parent == $parent_id) { $Filter_bar[$place]["sub2"][$node_id] = $node; unset($Default_bar[$node_id]); } } } } } } // sub3 node if (!empty($Default_bar)) { foreach ($Place_types as $place => $place_label) { if (!empty($Filter_bar[$place]["sub2"]) && $place != 'front') { foreach ($Filter_bar[$place]["sub2"] as $parent_id => $parent_node) { foreach ($Default_bar as $node_id => $node) { if ($node->parent == $parent_id) { $Filter_bar[$place]["sub3"][$node_id] = $node; unset($Default_bar[$node_id]); } } } } } } // sub4 node if (!empty($Default_bar)) { foreach ($Place_types as $place => $place_label) { if (!empty($Filter_bar[$place]["sub3"]) && $place != 'front') { foreach ($Filter_bar[$place]["sub3"] as $parent_id => $parent_node) { foreach ($Default_bar as $node_id => $node) { if ($node->parent == $parent_id) { $Filter_bar[$place]["sub4"][$node_id] = $node; unset($Default_bar[$node_id]); } } } } } } // front field $Filter_bar["front"] = array("main" => array(), "sub" => array()); $Filter_bar["front"]["main"]["edit-post_type"] = new stdClass(); $Filter_bar["front"]["main"]["edit-post_type"] = (object) array('id' => 'edit-post_type', 'title' => '', 'href' => '', 'group' => '', 'meta' => array()); $Filter_bar["front"]["main"]["edit-post_type"]->title = sprintf('%1$s [post_type]', __('Edit')); $Filter_bar["front"]["main"]["search"] = new stdClass(); $Filter_bar["front"]["main"]["search"] = (object) array('id' => 'search', 'title' => '', 'href' => '', 'group' => '', 'meta' => array()); $Filter_bar["front"]["main"]["search"]->title = __('Search'); $Filter_bar["front"]["main"]["search"]->href = get_search_link(); // admin field $Filter_bar['left']['main']['view-post_type'] = new stdClass(); $Filter_bar['left']['main']['view-post_type'] = (object) array('id' => 'view-post_type', 'title' => '', 'href' => '', 'group' => '', 'meta' => array()); $Filter_bar['left']['main']['view-post_type']->title = sprintf('%1$s [post_type]', __('View')); if (!empty($this->ActivatedPlugin)) { if (!empty($this->ActivatedPlugin["post_edit_toolbar"])) { $plugin_slug = 'post_item_'; foreach ($Filter_bar['left']['sub'] as $node_id => $node) { if (strstr($node_id, $plugin_slug)) { unset($Filter_bar['left']['sub'][$node_id]); } } $plugin_slug = 'page_item_'; foreach ($Filter_bar['left']['sub'] as $node_id => $node) { if (strstr($node_id, $plugin_slug)) { unset($Filter_bar['left']['sub'][$node_id]); } } } if (!empty($this->ActivatedPlugin["polylang"])) { $plugin_slug = 'languages'; foreach ($Filter_bar['left']['sub'] as $node_id => $node) { if (strstr($node->parent, $plugin_slug)) { unset($Filter_bar['left']['sub'][$node_id]); } } } } return $Filter_bar; }