function get_bodyid() { if (is_home()) { $bodyid = 'home'; } elseif (is_archive() and !is_author() and !is_tax() and !is_tag()) { $categories = get_the_category(); foreach ($categories as $category) { $cat_id = $category->term_id; $cat_parent_id = $category->category_parent; } if ($cat_parent_id) { $cat_name = strtolower(get_the_category_by_id($cat_parent_id)); } else { $cat_name = strtolower(get_the_category_by_id($cat_id)); } $bodyid = $cat_name; } elseif (is_archive() and is_author()) { $bodyid = 'profile'; } elseif (is_archive() and is_tax('nh_cities')) { $term = get_term_by('slug', get_query_var('term'), get_query_var('taxonomy')); $term_name = $term->name; $bodyid = 'cities-' . $term_name; } elseif (is_archive() and is_tag()) { $tags = get_the_tags(); foreach ($tags as $tag) { $tag_name = $tag->name; } $bodyid = $tag_name; } elseif (is_page()) { if (is_page('topics')) { $bodyid = 'topics'; } elseif (is_page('cities')) { $bodyid = 'cities'; } elseif (is_page('login')) { $bodyid = 'settings'; } else { $bodyid = 'general'; } } elseif (is_single()) { $categories = get_the_category(); foreach ($categories as $category) { $cat_id = $category->term_id; $cat_parent_id = $category->category_parent; } if ($cat_parent_id) { $cat_name = strtolower(get_the_category_by_id($cat_parent_id)); $bodyid = $cat_name; } else { $cat_name = strtolower(get_the_category_by_id($cat_id)); $bodyid = $cat_name; } // if (isset($cat_name)) { // $bodyid = $cat_name; // } } elseif (is_search()) { $bodyid = 'search'; } return $bodyid; }
function getAjaxData($category = '', $offset = '10') { $page = $_POST['page']; $postType = $_POST['postType']; $id = $_POST['id']; $offset = $_POST['offset']; $category = $_POST['category']; function validateIntegerInput($input) { $input = abs(intval($input)); filter_var($input, FILTER_SANITIZE_NUMBER_INT); if (!is_int($input) && !filter_var($input, FILTER_VALIDATE_INT)) { echo 'Invalid page input.'; exit(0); } } // Validate cross-site request forgery security token. if (!check_ajax_referer('ajax_fetch_nonce', 'token', false)) { header($_SERVER['SERVER_PROTOCOL'] . ' 403 Forbidden'); get_template_part('templates/index', '403'); exit(0); } if ($page === 'archive') { if ($postType === 'about' || $postType === 'work' || $postType === 'blog') { get_template_part('templates/index', $postType); } else { echo 'Invalid page input.'; } exit(0); // page, postId & postType; categoryId & offset } elseif ($page === 'single') { if ($postType === 'work') { $name = 'work_post'; } elseif ($postType === 'blog') { $name = 'blog_post'; } validateIntegerInput($id); global $post; $post = get_post($id); setup_postdata($post); get_template_part('templates/index', $name); wp_reset_postdata(); exit(0); } elseif ($page === 'category') { validateIntegerInput($id); global $post; $category = $id; $args = array('posts_per_page' => 10, 'offset' => '', 'category' => $category, 'orderby' => 'post_date', 'order' => 'DESC', 'include' => '', 'exclude' => '', 'meta_key' => '', 'meta_value' => '', 'post_type' => 'blog', 'post_mime_type' => '', 'post_parent' => '', 'post_status' => 'publish', 'suppress_filters' => true); $fetchedPosts = get_posts($args); ?> <div id="page_category_<?php echo $category; ?> " data-page-title="<?php echo strip_tags(esc_attr(get_the_category_by_id($category))); ?> "> <div class="title_wrapper"> <div class="titles"> <img src="<?php bloginfo('template_url'); ?> /img/title_blog@2x.png" alt=""> </div> </div> <?php foreach ($fetchedPosts as $post) { setup_postdata($post); ?> <article class="blog_list"> <h1 class="blog_title"><a href="<?php the_permalink(); ?> " data-link-type="postNavigation" data-page="single" data-post-type="blog" data-post-id="<?php the_ID(); ?> "><?php the_title(); ?> </a></h1> <h4 class="blog_date_categories_tags"><?php the_time('F j, Y'); ?> • <?php custom_the_category(', ', ''); the_tags(' • '); ?> </h4> </article><?php wp_reset_postdata(); } ?> </div> <?php exit(0); // Add if check here, so our final else can output a 404 error. } elseif (isset($offset) && isset($category)) { // Infinite scroll. global $post; validateIntegerInput($offset); validateIntegerInput($category); $args = array('posts_per_page' => 10, 'offset' => $offset, 'category' => $category, 'orderby' => 'post_date', 'order' => 'DESC', 'include' => '', 'exclude' => '', 'meta_key' => '', 'meta_value' => '', 'post_type' => 'blog', 'post_mime_type' => '', 'post_parent' => '', 'post_status' => 'publish', 'suppress_filters' => true); $fetchedPosts = get_posts($args); foreach ($fetchedPosts as $post) { setup_postdata($post); ?> <article class="blog_list"> <h1 class="blog_title"><a href="<?php the_permalink(); ?> " data-link-type="postNavigation" data-page="single" data-post-type="blog" data-post-id="<?php the_ID(); ?> "><?php the_title(); ?> </a></h1> <h4 class="blog_date_categories_tags"><?php the_time('F j, Y'); ?> • <?php custom_the_category(', ', ''); the_tags(' • '); ?> </h4> </article> <?php wp_reset_postdata(); } exit(0); } else { get_template_part('templates/index', '404'); exit(0); } }
function _postExpiratorGetCatNames($cats) { $out = array(); foreach ($cats as $cat) { $out[$cat] = get_the_category_by_id($cat); } return $out; }
function breadcrumbs() { if (is_front_page()) { return; } echo '<nav id="breadcrumbs">'; echo '<ol class="breadcrumbs">'; // Home Link $link = home_url('/'); $name = 'Home'; $this->breadcrumb($link, $name); // Post if (is_single() && is_singular('post')) { global $post; $categories = get_the_category($post->ID); foreach ($categories as $category) { $ID = $category->term_id; $ancestors = get_ancestors($ID, 'category'); foreach (array_reverse($ancestors) as $ancestor) { $link = get_category_link($ancestor); $name = get_the_category_by_id($ancestor); $this->breadcrumb($link, $name); } $link = get_category_link($ID); $name = $category->name; $this->breadcrumb($link, $name); } $link = get_permalink($post->ID); $name = get_the_title($post->ID); $this->page($link, $name); } // Attachment if (is_attachment()) { global $post; $parent = get_post_field('post_parent', $post->ID); $categories = get_the_category($parent); foreach ($categories as $category) { $ID = $category->term_id; $ancestors = get_ancestors($ID, 'category'); foreach (array_reverse($ancestors) as $ancestor) { $link = get_category_link($ancestor); $name = get_the_category_by_id($ancestor); $this->breadcrumb($link, $name); } $link = get_category_link($ID); $name = $category->name; $this->breadcrumb($link, $name); } $link = get_permalink($parent); $name = get_the_title($parent); $this->breadcrumb($link, $name); $link = get_permalink($post->ID); $name = get_the_title($post->ID); $this->page($link, $name); } // Page if (is_page()) { global $post; $ancestors = get_ancestors($post->ID, 'page'); foreach (array_reverse($ancestors) as $ancestor) { $link = get_permalink($ancestor); $name = get_the_title($ancestor); $this->breadcrumb($link, $name); } $link = get_permalink($post->ID); $name = get_the_title($post->ID); $this->page($link, $name); } // Custom Post Type // Category if (is_category()) { $ID = get_query_var('cat'); $category = get_category($ID, false); $ancestors = get_ancestors($ID, 'category'); foreach (array_reverse($ancestors) as $ancestor) { $link = get_category_link($ancestor); $name = get_the_category_by_id($ancestor); $this->breadcrumb($link, $name); } $link = get_category_link($ID); $name = $category->cat_name; $this->breadcrumb($link, $name); } // Tag if (is_tag()) { $ID = get_query_var('tag_id'); $link = get_tag_link($ID); $name = single_tag_title('', false); $this->breadcrumb($link, $name); } // Custom Taxonomy // Author if (is_author()) { $ID = get_query_var('author'); $link = get_author_posts_url($ID); $author = get_userdata($ID); $name = $author->display_name; $this->breadcrumb($link, $name); } // Search if (is_search()) { $link = get_search_link(); $name = get_search_query(); $this->breadcrumb($link, $name); } // Date if (is_date()) { // Query Variables $year = get_query_var('year'); $month = get_query_var('monthnum'); $day = get_query_var('day'); // Year Link if (is_year()) { $class = ''; } $link = get_year_link($year); $name = get_the_date('Y'); $this->breadcrumb($link, $name); // Month Link if (!is_year()) { if (is_month()) { $class = ''; } $link = get_month_link($year, $month); $name = get_the_date('F'); $this->breadcrumb($link, $name); } // Day Link if (!is_year() && !is_month()) { if (is_day()) { $class = ''; } $link = get_month_link($year, $month, $day); $name = get_the_date('j'); $this->breadcrumb($link, $name); } } // 404 if (is_404()) { echo '<li class="page">Error 404: Not Found</li>'; } // Page Number for Archives $total = get_query_var('max_num_pages') ? get_query_var('max_num_pages') : 1; $page = get_query_var('paged') ? get_query_var('paged') : 1; if (!is_singular() and !is_404() and $total > 1) { printf('<li class="page">Page %s of %s</li>', $page, $total); } // Page Numbers for Posts and Pages? echo '</ol>'; echo '</nav>'; }
function breadcrumbs_and_search() { echo '<div class="breadcrumbs-and-search">'; // Only show breadcrumbs on category and post pages if (!is_home() && !is_front_page() && !is_page()) { echo '<div class="breadcrumbs">'; echo '<a href="'; echo get_option('home'); echo '">'; echo 'Blog'; echo "</a>"; if (is_single()) { echo " » "; the_category(' » ', 'multiple'); echo " » "; the_title(); } elseif (is_category()) { echo " » "; // get a list of the category's parent $category_list = get_category_parents(get_query_var('cat'), true, ' » '); // remove current category from list (in order to display without a link or trailing arrow) $categories = explode(' » ', $category_list); array_pop($categories); array_pop($categories); foreach ($categories as $category) { echo $category . " » "; } // and display current category name, without a link or trailing arrow echo get_the_category_by_id(get_query_var('cat')); } elseif (is_page()) { echo " » "; echo the_title(); } elseif (is_search()) { echo " » Search results for: "; echo '"<em>'; echo the_search_query(); echo '</em>"'; } elseif (is_tag()) { echo " » "; echo "Tag archive: "; echo full_tag_string(); } echo '</div>'; } // ! is_home() && ! is_front_page() && ! is_page() // Search box echo '<div class="search-box">'; get_search_form(); echo '<i class="icon-search"></i>'; echo '</div>'; echo '</div>'; // .breadcrumbs-and-search }
?> /images/nothumb200.png" class="attachment-featured wp-post-image" alt="<?php the_title(); ?> "> <?php } ?> <span class="bbtitle"><?php the_title(); ?> </span> <?php $f3cat = $options['mts_featured_third_cat']; if ($i == 1 && $f3cat) { echo '<span class="bbcat">' . get_the_category_by_id($f3cat) . '</span>'; } else { echo ''; } ?> </a> </div> <?php $i++; } } ?> </div> <div id="frontLastCatBox"> <div class="leftLastCatBox">
$left_side_bar = get_the_category_by_id($zboomsmusic['left_catagory_selector']); $internation = new WP_Query(array('post_type' => 'post', 'posts_per_page' => 3, 'category_name' => $left_side_bar)); while ($internation->have_posts()) { $internation->the_post(); ?> <h1><?php the_title(); ?> </h1> <?php } ?> </div> <div class="col-1-3"> <?php $right_side_category = get_the_category_by_id($zboomsmusic['right_catagory_selector']); $national = new WP_Query(array('post_type' => 'post', 'posts_per_page' => 3, 'category_name' => $right_side_category)); while ($national->have_posts()) { $national->the_post(); ?> <h1><?php the_title(); ?> </h1> <?php } ?> </div> </div> </div> </section>