function inti_get_categories_meta($args = '') { $count = 0; $categories_list = ''; $categories = get_the_category(); foreach ($categories as $category) { $count++; if ($args['show_uncategorized']) { $categories_list .= '<a href="' . get_category_link($category->term_id) . '" title="' . sprintf(__('View all posts in %s', 'inti'), $category->name) . '"><span class="label category">' . $category->name . '</span></a>'; if ($count != count($categories)) { $categories_list .= ' '; //separator } } else { if ($category->slug != 'uncategorized' || $category->name != 'Uncategorized') { $categories_list .= '<a href="' . get_category_link($category->term_id) . '" title="' . sprintf(__('View all posts in %s', 'inti'), $category->name) . '"><span class="label category">' . $category->name . '</span></a>'; if ($count != count($categories)) { $categories_list .= ' '; //separator } } } } return $categories_list; }
function get_gallery_post() { if (isset($_POST['id']) && !empty($_POST['id'])) { $projectsCats = array('cocheras', 'terrazas', 'habitaciones', 'antes-despues'); $id = $_POST['id']; $post = get_post($id); $gallery = get_post_gallery($post->ID, false); $category = get_the_category($post->ID); $cat_elements = array(); $cat_info = array(); foreach ($projectsCats as $cat) { $catdata = get_category_by_slug($cat); $args = array('category_name' => $cat, 'orderby' => 'meta_value_num', 'meta_key' => 'order', 'order' => 'ASC', 'posts_per_page' => 3); $projects = new WP_Query($args); array_push($cat_info, $catdata); array_push($cat_elements, $projects); } if ($gallery !== false) { $gallerydata = array(); $images = explode(',', $gallery['ids']); foreach ($images as $key => $image) { $imagedata = wp_prepare_attachment_for_js($image); array_push($gallerydata, $imagedata); } $post_info = array('post' => $post, 'category' => $category, 'categories' => $cat_elements, 'cat_info' => $cat_info, 'gallery' => $gallerydata); echo json_encode($post_info); } die; } else { echo 'error'; die; } die; }
function get_category() { $buffy = ''; //read the post meta to get the custom primary category $td_post_theme_settings = get_post_meta($this->post->ID, 'td_post_theme_settings', true); if (!empty($td_post_theme_settings['td_primary_cat'])) { //we have a custom category selected $selected_category_obj = get_category($td_post_theme_settings['td_primary_cat']); } else { //get one auto $categories = get_the_category($this->post->ID); if (!empty($categories[0])) { if ($categories[0]->name === TD_FEATURED_CAT and !empty($categories[1])) { $selected_category_obj = $categories[1]; } else { $selected_category_obj = $categories[0]; } } } if (!empty($selected_category_obj)) { //@todo catch error here $buffy .= '<a href="' . get_category_link($selected_category_obj->cat_ID) . '">' . $selected_category_obj->name . '</a>'; } //return print_r($post, true); return $buffy; }
function widget($args, $instance) { extract($args, EXTR_SKIP); $category_id = empty($instance['category_id']) ? 1 : $instance['category_id']; $use_cat_title = empty($instance['use_cat_title']) ? 0 : $instance['use_cat_title']; $hide_empty_cats = empty($instance['hide_empty_cats']) ? 0 : $instance['hide_empty_cats']; $show_post_count = empty($instance['show_post_count']) ? 0 : $instance['show_post_count']; $title_link = empty($instance['title_link']) ? 0 : $instance['title_link']; $excluded = empty($instance['excluded']) ? '' : $instance['excluded']; $sub_subs = empty($instance['sub_subs']) ? 0 : $instance['sub_subs']; $dropdown = empty($instance['dropdown']) ? 0 : $instance['dropdown']; $post_is_parent = empty($instance['post_is_parent']) ? 0 : $instance['post_is_parent']; $dropdown_text = empty($instance['dropdown_text']) ? __('Select Sub-category', 'sub-categories-widget') : $instance['dropdown_text']; $list_order = empty($instance['list_order']) ? 0 : $instance['list_order']; if ($post_is_parent) { $category = get_the_category(); $category_id = $category ? $category[0]->cat_ID : 1; } if ($use_cat_title) { $title = apply_filters('widget_title', get_cat_name($category_id), $instance, $this->id_base); } else { $title = apply_filters('widget_title', empty($instance['title']) ? __('Sub Categories', 'sub-categories-widget') : $instance['title'], $instance, $this->id_base); } $parent = $sub_subs == 1 ? 'child_of' : 'parent'; $order = $list_order == 1 ? 'DESC' : 'ASC'; $no_sub_text = '<p>' . __('No sub-categories', 'sub-categories-widget') . '</p>'; $subs = wp_list_categories(array($parent => $category_id, 'hide_empty' => $hide_empty_cats, 'show_count' => $show_post_count, 'exclude' => $excluded, 'title_li' => null, 'show_option_none' => '', 'echo' => 0, 'orderby' => 'ID', 'order' => $order)); if ($post_is_parent == 0 || $post_is_parent == 1 && !empty($subs)) { echo $before_widget; if ($title_link) { echo $before_title . '<a href="' . get_category_link($category_id) . '">' . $title . '</a>' . $after_title; } else { echo $before_title . $title . $after_title; } if ($dropdown == 0) { if (!empty($subs)) { echo '<ul>' . $subs . '</ul>'; } else { echo $no_sub_text; } } else { $subs = wp_dropdown_categories(array('id' => 'sub-cat-' . $this->number, 'show_option_none' => $dropdown_text, $parent => $category_id, 'hide_empty' => $hide_empty_cats, 'show_count' => $show_post_count, 'exclude' => $excluded, 'hide_if_empty' => true, 'echo' => false, 'orderby' => 'ID', 'order' => $order)); if (!empty($subs)) { echo $subs; echo '<script type="text/javascript"> /* <![CDATA[ */ var dropdown' . $this->number . ' = document.getElementById("sub-cat-' . $this->number . '"); function onSubCatChange() { if (dropdown' . $this->number . '.options[dropdown' . $this->number . '.selectedIndex].value > 0) { location.href = "' . get_option('home') . '?cat="+dropdown' . $this->number . '.options[dropdown' . $this->number . '.selectedIndex].value; } } dropdown' . $this->number . '.onchange = onSubCatChange; /* ]]> */ </script>'; } else { echo $no_sub_text; } } echo $after_widget; } }
public static function find($postID) { $cat=get_the_category($postID); if(empty($cat)) return NULL; return new TCategory($cat); }
public function fetchCategoryPosts(SearchArgs $args) { $i = 0; $posts = null; $category = $this->fetchCategoryBySlug($args->slug); if ($category->getTermid() != null) { $search_array = array('posts_per_page' => $args->posts_per_page, 'offset' => $args->offset, 'cat' => $category->getTermid(), 'm' => $args->monthnum, 'orderby' => $args->orderby, 'order' => $args->order); query_posts($search_array); while (have_posts()) { the_post(); $post = get_post(); if (!$args->childrenOnly) { $posts[$i++] = new Post($post); } else { foreach (get_the_category($post->ID) as $cat) { if ($cat->term_id == $category->getTermid()) { $posts[$i++] = new Post($post); break; } } } } //wp_reset_query(); } return $posts; }
function get_post_class($class = '', $post_id = null) { $post = get_post($post_id); $classes = array(); $classes[] = $post->post_type; /* // sticky for Sticky Posts if ( is_sticky($post->ID) && is_home()) $classes[] = 'sticky'; */ // hentry for hAtom compliace $classes[] = 'hentry'; // Categories foreach ((array) get_the_category($post->ID) as $cat) { if (empty($cat->slug)) { continue; } $classes[] = 'category-' . $cat->slug; } // Tags foreach ((array) get_the_tags($post->ID) as $tag) { if (empty($tag->slug)) { continue; } $classes[] = 'tag-' . $tag->slug; } if (!empty($class)) { if (!is_array($class)) { $class = preg_split('#\\s+#', $class); } $classes = array_merge($classes, $class); } return apply_filters('post_class', $classes, $class, $post_id); }
static function getWordpressData() { /** * Get all global page data */ $blogDataParams = array( 'url', 'wpurl', 'description', 'rdf_url' , 'rss_url', 'rss2_url' , 'atom_url', 'comments_atom_url', 'comments_rss2_url', 'pingback_url' , 'stylesheet_url', 'stylesheet_directory', 'template_directory' , 'template_url', 'admin_email', 'charset', 'html_type', 'version' , 'language', 'text_direction', 'name' ); $blogData = array(); foreach($blogDataParams as $blogDataParam) { $blogData[self::toCamelCase($blogDataParam)] = get_bloginfo($blogDataParam); } $blogData = array_merge($blogData, array( 'title' => wp_title(' | ', false, 'right') . get_bloginfo('name'), 'archiveLinksHTML' => wp_get_archives('type=monthly&limit=5&format=link&echo=0'), 'bodyClasses' => self::getEchoFunctionContents('body_class'), 'posts' => array() )); /** * Get posts data */ while (have_posts()) { the_post(); $postId = get_the_ID(); // Get category data $categories = get_the_category(); $categoryNames = array(); foreach($categories as $category) { array_push($categoryNames, $category->cat_name); } // Add all relevant post data to the posts array array_push( $blogData['posts'], array_merge( get_object_vars(get_post($postId)), array( 'classes' => get_post_class(), 'comments' => get_comments(array('post_id' => $postId)), 'custom' => get_post_custom(), 'permalink' => get_permalink(), 'categories' => $categories, 'categoryNames' => $categoryNames, 'categoriesStr' => implode(',', $categoryNames) ) ) ); } return $blogData; }
function dtheme_keywords() { global $s, $post; $keywords = ''; if (is_single()) { if (get_the_tags($post->ID)) { foreach (get_the_tags($post->ID) as $tag) { $keywords .= $tag->name . ', '; } } foreach (get_the_category($post->ID) as $category) { $keywords .= $category->cat_name . ', '; } $keywords = substr_replace($keywords, '', -2); } elseif (is_home()) { $keywords = dopt('d_keywords'); } elseif (is_tag()) { $keywords = single_tag_title('', false); } elseif (is_category()) { $keywords = single_cat_title('', false); } elseif (is_search()) { $keywords = esc_html($s, 1); } else { $keywords = trim(wp_title('', false)); } if ($keywords) { echo "<meta name=\"keywords\" content=\"{$keywords}\" />\n"; } }
function flatbook_post_metas() { $user = get_the_author(); $date = get_the_date('F j'); $cats = get_the_category(); $tags = get_the_tags(); $comm = get_comments_number(); $type = get_post_format(); if (false === $type) { $type = __('standard', 'flatbook'); } echo '<div class="entry-metas">'; if ($type) { echo '<span class="format"><i class="fa fa-inbox"></i>' . $type . '</span>'; } if ($date) { echo '<span class="posted-on"><i class="fa fa-dashboard"></i>' . $date . '</span>'; } if ($user) { echo '<span class="byline"><i class="fa fa-user"></i>' . $user . '</span>'; } if ($cats) { echo '<span class="cats"><i class="fa fa-folder-open"></i>' . $cats[0]->cat_name . '</span>'; } if ($tags) { echo '<span class="tags"><i class="fa fa-tags"></i>' . $tags[0]->name . '</span>'; } if ($comm) { echo '<span class="comments"><i class="fa fa-comments"></i>' . $comm . __(' Comment', 'flatbook') . '</span>'; } echo '</div>'; }
function sourdough_get_categories($sep = ', ', $before = '', $after = '') { /* Echoes the categories with the parent of each as a css class. Allows you to style each category link based on it's parent. Must be used within the loop. Example: <a href="/category" class="parent-class">cagtegory Name</a> */ $total_cats = count(get_the_category()); $i = 0; foreach (get_the_category() as $cat) { ++$i; $parent = get_category($cat->parent); $link = get_category_link($cat->cat_ID); echo $before; if (!$parent->errors) { echo '<a href="' . $link . '" title="' . $cat->name . '" class="' . $parent->slug . '">' . $cat->name . '</a>'; } else { echo '<a href="' . $link . '" title="' . $cat->name . '">' . $cat->name . '</a>'; } if ($i < $total_cats) { echo $sep; } echo $after; } }
function render_related_string() { $settings = C_NextGen_Settings::get_instance(); $type = $settings->appendType; $maxImages = $settings->maxImages; $sluglist = array(); switch ($type) { case 'tags': if (function_exists('get_the_tags')) { $taglist = get_the_tags(); if (is_array($taglist)) { foreach ($taglist as $tag) { $sluglist[] = $tag->slug; } } } break; case 'category': $catlist = get_the_category(); if (is_array($catlist)) { foreach ($catlist as $cat) { $sluglist[] = $cat->category_nicename; } } break; } $taglist = implode(',', $sluglist); if ($taglist === 'uncategorized' || empty($taglist)) { return; } $renderer = C_Component_Registry::get_instance()->get_utility('I_Displayed_Gallery_Renderer'); $view = C_Component_Registry::get_instance()->get_utility('I_Component_Factory')->create('mvc_view', ''); $retval = $renderer->display_images(array('source' => 'tags', 'container_ids' => $taglist, 'display_type' => NEXTGEN_GALLERY_BASIC_THUMBNAILS, 'images_per_page' => $maxImages, 'maximum_entity_count' => $maxImages, 'template' => $view->get_template_abspath('photocrati-nextgen_gallery_display#related'), 'show_all_in_lightbox' => FALSE, 'show_slideshow_link' => FALSE, 'disable_pagination' => TRUE)); return apply_filters('ngg_show_related_gallery_content', $retval, $taglist); }
public function get_data_original($num = '', $post_id = null) { global $wpdb, $post; if (!isset($post_id)) { $post_id = $post->ID; } if (empty($post_id)) { return false; } $current_categories = get_the_category($post_id); if (!$current_categories) { return false; } $categories = array(); foreach ((array) $current_categories as $category) { $categories[] = absint($category->term_id); } $category_list = implode(',', $categories); if ($num == '') { $option = get_option('sirp_options'); $num = $option['display_num']; } $q = "SELECT ID FROM {$wpdb->posts} AS p\n\t\t\tINNER JOIN {$wpdb->term_relationships} AS tr ON (p.ID = tr.object_id)\n\t\t\tINNER JOIN {$wpdb->term_taxonomy} AS tt ON (tr.term_taxonomy_id = tt.term_taxonomy_id)\n\t\t\tWHERE (tt.taxonomy = 'category' AND tt.term_id IN ({$category_list}))\n\t\t\tAND p.post_status = 'publish'\n\t\t\tAND p.post_type = 'post'\n\t\t\tAND p.ID != {$post_id}\n\t\t\tGROUP BY tr.object_id\n\t\t\tORDER BY post_date DESC" . $wpdb->prepare(" LIMIT %d", $num); return $wpdb->get_results($q, ARRAY_A); }
function get_the_category_list($separator = '', $parents = '') { $categories = get_the_category(); if (empty($categories)) { return apply_filters('the_category', __('Uncategorized'), $separator, $parents); } $thelist = ''; if ('' == $separator) { $thelist .= '<ul class="post-categories">'; foreach ($categories as $category) { $thelist .= "\n\t<li>"; switch (strtolower($parents)) { case 'multiple': if ($category->category_parent) { $thelist .= get_category_parents($category->category_parent, TRUE); } $thelist .= '<a href="' . get_category_link($category->cat_ID) . '" title="' . sprintf(__("View all posts in %s"), $category->cat_name) . '" rel="category tag">' . $category->cat_name . '</a></li>'; break; case 'single': $thelist .= '<a href="' . get_category_link($category->cat_ID) . '" title="' . sprintf(__("View all posts in %s"), $category->cat_name) . ' rel="category tag">'; if ($category->category_parent) { $thelist .= get_category_parents($category->category_parent, FALSE); } $thelist .= $category->cat_name . '</a></li>'; break; case '': default: $thelist .= '<a href="' . get_category_link($category->cat_ID) . '" title="' . sprintf(__("View all posts in %s"), $category->cat_name) . '" rel="category tag">' . $category->cat_name . '</a></li>'; } } $thelist .= '</ul>'; } else { $i = 0; foreach ($categories as $category) { if (0 < $i) { $thelist .= $separator . ' '; } switch (strtolower($parents)) { case 'multiple': if ($category->category_parent) { $thelist .= get_category_parents($category->category_parent, TRUE); } $thelist .= '<a href="' . get_category_link($category->cat_ID) . '" title="' . sprintf(__("View all posts in %s"), $category->cat_name) . '" rel="category tag">' . $category->cat_name . '</a>'; break; case 'single': $thelist .= '<a href="' . get_category_link($category->cat_ID) . '" title="' . sprintf(__("View all posts in %s"), $category->cat_name) . '" rel="category tag">'; if ($category->category_parent) { $thelist .= get_category_parents($category->category_parent, FALSE); } $thelist .= "{$category->cat_name}</a>"; break; case '': default: $thelist .= '<a href="' . get_category_link($category->cat_ID) . '" title="' . sprintf(__("View all posts in %s"), $category->cat_name) . '" rel="category tag">' . $category->cat_name . '</a>'; } ++$i; } } return apply_filters('the_category', $thelist, $separator, $parents); }
function list_categories_from_current_blog_post() { $postCats = get_the_category(); if ($postCats) { ?> <h5>Catorgories</h5> <ul> <?php //the_terms($post->ID,"service_type", '', ', ', ' '); ?> <?php //customPostTypeCatList('post'); $separator = ''; $output = ''; if ($postCats) { foreach ($postCats as $category) { $output .= '<li><a href="' . get_category_link($category->term_id) . '" title="' . esc_attr(sprintf(__("View all posts in %s"), $category->name)) . '">' . $category->cat_name . '</a></li>' . $separator; } echo trim($output, $separator); } } echo '</ul>'; }
/** * Prints HTML with meta information for the categories, tags and comments. */ function smittenkitchen_primary_category() { if ('post' == get_post_type()) { $categories = get_the_category(get_the_ID()); // For each category, derive a list of top-level parent categories. $parent_categories = array(); foreach ($categories as $category) { if (0 === $category->category_parent) { $top_level_parent = $category->name; } else { // Get the top-level parent. $all_parents = get_category_parents($category->term_id, false, '&&&'); $all_parents = explode('&&&', $all_parents); $top_level_parent = $all_parents[0]; } // Add category to our array. if (!in_array($top_level_parent, $parent_categories)) { $parent_categories[] = $top_level_parent; } } // Join strings together! $parent_category_string = implode(', ', $parent_categories); if ($parent_category_string && smittenkitchen_categorized_blog()) { printf('<span class="smittenkitchen-primary-category">' . esc_html__('%1$s', 'smittenkitchen') . '</span>', $parent_category_string); // WPCS: XSS OK. } } }
function rkv_post_details() { // get variables global $post; $categories = get_the_category($post->ID); $post_date = get_the_date('M jS, Y'); $schm_date = get_the_date('c'); $auth_id = get_the_author_meta('ID'); $auth_name = get_the_author_meta('display_name'); $auth_url = $auth_id == 1 ? get_bloginfo('url') . '/about/' : get_author_posts_url($auth_id); echo '<p class="post-details">'; echo '<span class="detail-item"><span class="vcard author"><i class="icon icon-user"></i> <a class="url fn n" href="' . $auth_url . '" rel="author me" title="View all posts by ' . $auth_name . '">' . $auth_name . '</a></span></span>'; if (comments_open()) { echo '<span title="' . $schm_date . '" class="detail-item date published updated time"><i class="icon icon-calendar"></i> ' . $post_date . '</span>'; echo '<span class="detail-item detail-last detail-comment"><i class="icon icon-comments"></i> '; echo comments_popup_link('Leave a Comment', '1 Comment', '% Comments', '', ''); echo '</span>'; } else { echo '<span title="' . $schm_date . '" class="detail-item date published updated time detail-last"><i class="icon icon-calendar"></i> ' . $post_date . '</span>'; } if ($categories) { echo '<span class="detail-item detail-category pull-right">'; foreach ($categories as $category) { $cat_name = $category->cat_name; $cat_link = get_category_link($category->cat_ID); echo '<a class="label label-primary" title="View all posts in ' . $cat_name . '" href="' . $cat_link . '">' . $cat_name . '</a>'; } echo '</span>'; } echo '</p>'; }
function wpthemes_post_class($class = '', $post_id = null) { $post = get_post($post_id); $classes = array(); $classes[] = $post->post_type; if (is_sticky($post->ID) && is_home()) { $classes[] = 'sticky'; } $classes[] = 'hentry'; foreach ((array) get_the_category($post->ID) as $cat) { if (empty($cat->slug)) { continue; } $classes[] = 'category-' . $cat->slug; } foreach ((array) get_the_tags($post->ID) as $tag) { if (empty($tag->slug)) { continue; } $classes[] = 'tag-' . $tag->slug; } if (!empty($class)) { if (!is_array($class)) { $class = preg_split('#\\s+#', $class); } $classes = array_merge($classes, $class); } return apply_filters('post_class', $classes, $class, $post_id); }
function vw_render_categories($classes = '') { $categories = get_the_category(); $html = ''; if (is_sticky()) { $html .= '<div class="label label-sticky ' . $classes . '" title="' . __('Sticky Post', 'envirra') . '"><i class="icon-entypo-megaphone"></i></div>'; } if ('post' == get_post_type()) { if ('1' == get_post_meta(get_the_id(), 'vw_enable_review', true)) { $avg_score = get_post_meta(get_the_id(), 'vw_review_average_score', true); $html .= '<div class="label label-review ' . $classes . '" title="' . __('Classificação', 'envirra') . '"><i class="icon-entypo-star"></i> ' . $avg_score . '</div>'; } else { // Show post format if not a review if ('gallery' == get_post_format()) { $html .= '<div class="label label-light ' . $classes . '" title="' . __('Gallery Post', 'envirra') . '"><i class="icon-entypo-picture"></i></div>'; } else { if ('video' == get_post_format()) { $html .= '<div class="label label-light ' . $classes . '" title="' . __('Video Post', 'envirra') . '"><i class="icon-entypo-play"></i></div>'; } else { if ('audio' == get_post_format()) { $html .= '<div class="label label-light ' . $classes . '" title="' . __('Audio Post', 'envirra') . '"><i class="icon-entypo-note-beamed"></i></div>'; } } } } } if ($categories) { foreach ($categories as $category) { $html .= '<a class="label ' . $classes . '" href="' . get_category_link($category->term_id) . '" title="' . esc_attr(sprintf(__("Ver Artigos na Categoria %s", 'envirra'), $category->name)) . '" rel="category">' . $category->cat_name . '</a>'; } } echo $html; }
function show_category($cid = 1) { $args = array('showposts' => 4, 'cat' => $cid, 'orderby' => 'post_date', 'order' => 'desc'); query_posts($args); global $the_post; $category = ''; while (have_posts()) { the_post(); $cat = get_the_category(get_the_ID()); $link = get_permalink(get_the_ID()); $src = get_the_post_thumbnail(get_the_ID(), 'index_thumb'); $c_name = $cat[0]->name; $title = get_the_title(); echo $category .= <<<EOF <div class="box"> <a href="{$link}"> <div class="boximg">{$src}</div> <div class="category">{$c_name}</div> <p>{$title}</p> </a> </div> EOF; } wp_reset_query(); return $category; }
function homeType($classes) { // Add the class when needed $HomebgType = get_option('_tdCore-home-bgType'); $iC = ''; $end = ''; foreach (get_the_category() as $category) { $postcat = $category->cat_ID; $catname = $category->cat_name; $catslug = $category->category_nicename; if (is_category($catslug)) { $end = $postcat; } } $args = array('orderby' => 'name', 'order' => 'ASC'); $categories = get_categories($args); foreach ($categories as $cat) { $iC++; if ($cat->name != '') { if ($end == $cat->cat_ID) { $catname = $cat->name; $count = get_option('portfolioType' . $iC); $count = strtolower($count); $classes[] = 'body-' . $count; } } } if (is_front_page()) { $classes[] = 'body-' . $HomebgType; } return $classes; }
public static function es_notification_prepare($post_id = 0) { global $wpdb; $prefix = $wpdb->prefix; $arrNotification = array(); if ($post_id > 0) { $post_type = get_post_type($post_id); $sSql = "SELECT * FROM `" . $prefix . "es_notification` where (es_note_status = 'Enable' or es_note_status = 'Cron') "; if ($post_type == "post") { $category = get_the_category($post_id); $totcategory = count($category); if ($totcategory > 0) { for ($i = 0; $i < $totcategory; $i++) { if ($i == 0) { $sSql = $sSql . " and ("; } else { $sSql = $sSql . " or"; } $sSql = $sSql . " es_note_cat LIKE '%##" . $category[$i]->cat_name . "##%'"; if ($i == $totcategory - 1) { $sSql = $sSql . ")"; } } $arrNotification = $wpdb->get_results($sSql, ARRAY_A); //print_r($arrNotification); } } else { $sSql = $sSql . " and es_note_cat LIKE '%##{T}" . $post_type . "{T}##%'"; $arrNotification = $wpdb->get_results($sSql, ARRAY_A); //print_r($arrNotification); } } //die(); return $arrNotification; }
function parseLink($permalink, $post) { if ('' != $permalink && !in_array($post->post_status, array('draft', 'pending'))) { $category = ''; if (strpos($permalink, '%scategory%') !== false) { $cat = null; $category_permalink = get_post_meta($post->ID, '_category_permalink', true); if ($category_permalink) { $cat = get_category($category_permalink); } if (!$cat) { $cats = get_the_category($post->ID); usort($cats, '_usort_terms_by_ID'); // order by ID $cat = $cats[0]; } $category = $cat->slug; if ($parent = $cat->parent) { $category = get_category_parents($parent, false, '/', true) . $category; } // show default category in permalinks, without // having to assign it explicitly if (empty($category)) { $default_category = get_category(get_option('default_category')); $category = is_wp_error($default_category) ? '' : $default_category->slug; } } $p = str_replace('%scategory%', $category, $permalink); return $p; } return $permalink; }
function getImageByPost($post) { $cate = get_the_category(); //echo $cate[0]->cat_ID; //$post->post_parent->term_id if (has_post_thumbnail($post->ID)) { $image = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'medium'); $image = $image[0]; return $image; } elseif (strlen($catImageUrl = getCategoryImage($cate[0]->cat_ID)) > 0) { return $catImageUrl; } elseif (strlen(getFirstImage($post->ID)) > 0) { $image = getFirstImage($post->ID); return $image; } else { $theme = get_option('themes'); if ($theme == '10') { return get_stylesheet_directory_uri() . '/asset/img/themes/post-default10.jpg'; // TODO 常量化 } elseif ($theme == 11) { return get_stylesheet_directory_uri() . '/asset/img/themes/post-default11.jpg'; } elseif ($theme == 12) { return get_stylesheet_directory_uri() . '/asset/img/themes/post-default12.jpg'; } else { return get_stylesheet_directory_uri() . '/asset/img/themes/post-default10.jpg'; // TODO } } }
function related_post_shortcode($atts, $content = null) { $a = shortcode_atts(array('id' => 0), $atts); if ($a['id'] === 0) { $categories = get_the_category(); $category_id = $categories[0]->cat_ID; $posts = query_posts(array('showposts' => 1, 'orderby' => 'rand', 'cat' => $category_id, 'date_query' => array('column' => 'post_date', 'after' => '- 90 days'))); $postID = $posts[0]->ID; } else { $postID = $a['id']; } $post = get_post(intval($postID)); $post_trim = preg_replace('/((\\w+\\W*){16}(\\w+))(.*)/', '${1}', $post->post_content); $section_title = get_option('related_post_shortcode_title_custom') ? get_option('related_post_shortcode_title_custom') : __('You may also like', 'related-post-shortcode'); $excerpt = strip_tags($post_trim) . '...'; $excerptContainer = get_option('related_post_shortcode_display_excerpt') ? '<div class="rps-excerpt">' . $excerpt . '</div>' : ''; return ' <div class="rps-container" > <a class="rps-thumb" href="' . get_permalink($postID) . '" >' . get_the_post_thumbnail($postID, 'thumbnail') . '</a> <div class="rps-desc"> <span class="rps-container-title">' . $section_title . '</span> <a href="' . get_permalink($postID) . '" class="rps-title">' . get_the_title($postID) . '</a>' . $excerptContainer . ' </div> </div> '; }
function bavota_breadcrumbs() { if (!is_front_page()) { echo '<a href="' . home_url('/') . 'blog">Blog</a><span class="divider"> <i class="icon-angle-right"></i> </span>'; } if (is_category() || is_single()) { $category = get_the_category(); $ID = $category[0]->cat_ID; // echo get_category_parents($ID, TRUE, ' ', FALSE ); // was causing errors in the error_log echo is_wp_error($cat_parents = get_category_parents($ID, TRUE, ' ', FALSE)) ? '' : $cat_parents; } $mytitle = get_the_title(); if (strlen($mytitle) > 22) { $mytitle = substr($mytitle, 0, 38) . "..."; } if (is_single() || is_page()) { echo ' <span class="divider"> <i class="icon-angle-right"></i> </span> '; echo $mytitle; } if (is_tag()) { echo "Tag: " . single_tag_title('', FALSE); } if (is_404()) { echo "404 - Page not Found"; } if (is_search()) { echo "Search"; } if (is_year()) { echo get_the_time('Y'); } }
/** * Build object from posts * * @param String $posts of HTML to parse * * @return Mixed collection of posts */ public static function build($posts) { $collection = []; $document = new \DOMDocument(); $document->loadHTML($posts); $iterator = 0; $articles = $document->getElementsByTagName("li"); foreach ($articles as $article) { $post = new \StdClass(); $links = $article->getElementsByTagName("a"); $images = $article->getElementsByTagName("img"); $excerpts = $article->getElementsByTagName("small"); foreach ($links as $link) { if (0 == $iterator % 2) { $iterator++; continue; } $iterator++; $post->link = $link->getAttributeNode('href')->value; $post->title = $link->textContent; $post->category = get_the_category(url_to_postid($post->link))[0]->name; } foreach ($images as $image) { $post->image = $image->getAttributeNode('src')->value; } foreach ($excerpts as $excerpt) { $post->excerpt = $excerpt->textContent; } $collection[] = $post; } return $collection; }
function ac_output_first_category($class = '', $span_wrap = false) { global $post; $output_category = ''; $gpt = get_post_type(get_the_ID()); if (has_filter('ac_output_first_category_class_filter')) { $applied_class = apply_filters('ac_output_first_category_class_filter', $class); if (!empty($applied_class)) { $show_class = 'class="' . esc_attr($applied_class) . '" '; } else { $show_class = ''; } } elseif (!empty($class)) { $show_class = 'class="' . esc_attr($class) . '" '; } else { $show_class = ''; } $category = get_the_category(); if ($category) { $output_category = '<a href="' . get_category_link($category[0]->term_id) . '" ' . $show_class . 'title="' . sprintf(__("View all posts in %s", "justwrite"), $category[0]->name) . '" ' . '>' . $category[0]->name . '</a> '; } if (!$span_wrap) { if ($gpt != 'page' && !empty($category)) { echo $output_category; } } else { $output_category = '<span ' . $show_class . '>' . $category[0]->name . '</span> '; echo $output_category; } }
/** * Add breadcrumbs functionality to your WordPress theme * * Once you have included the function in your functions.php file * you can then place the following anywhere in your theme templates * if(function_exists('bootstrap_breadcrumbs')) bootstrap_breadcrumbs(); * * credit to: c.bavota - http://bavotasan.com (thanks for the code start) */ function bootstrap_breadcrumbs() { echo '<ol class="breadcrumb">'; echo '<li><a href="' . home_url('/') . '">Home</a></li>'; // are we at "blog home"? if (is_home()) { echo '<li><a href="#">Blogs</a></li>'; } // where else do we want breadcrumbs if (!is_page_template('pt-home.php') && !is_home()) { // check if we're in a commerce plugin if (function_exists('is_woocommerce') && is_woocommerce()) { echo '<li><a href="/publications/order/">Shop</a></li>'; $product_cats = wp_get_post_terms(get_the_ID(), 'product_cat'); echo '<li><a href="/publications/order/' . str_replace(" ", "-", $product_cats[0]->name) . '">' . $product_cats[0]->name . '</a></li>'; } // breadcrumb wordpress structures if (is_category() || is_single() || is_single('aof')) { if (get_the_category()) { $category = get_the_category(); echo '<li><a href="/blog/category/' . str_replace(" ", "-", $category[0]->cat_name) . '">' . $category[0]->cat_name . '</a></li>'; } if (is_single()) { echo '<li class="active">'; the_title(); echo '</li>'; } } elseif (is_page()) { echo '<li class="active">'; the_title(); echo '</li>'; } } echo '</ol>'; }
function get_permalink($id = false) { $rewritecode = array('%year%', '%monthnum%', '%day%', '%hour%', '%minute%', '%second%', '%postname%', '%post_id%', '%category%', '%author%', '%pagename%'); $permalink = get_settings('permalink_structure'); $postHandler =& wp_handler('Post'); if ($id) { $id = intval($id); if ($permalink == '') { return wp_siteurl() . '/index.php?p=' . $id; } if (!isset($GLOBALS['permalink_cache'][wp_id()]) || !isset($GLOBALS['permalink_cache'][wp_id()][$id])) { $postObject =& $postHandler->get($id); $GLOBALS['permalink_cache'][wp_id()][$id] =& $postObject->exportWpObject(); } $idpost = $GLOBALS['permalink_cache'][wp_id()][$id]; } else { $idpost = $GLOBALS['post']; } if ('' != $permalink) { $unixtime = strtotime($idpost->post_date); $cats = get_the_category($idpost->ID); $category = $cats[0]->category_nicename; $authordata = get_userdata($idpost->post_author); $author = $authordata->user_login; $rewritereplace = array(date('Y', $unixtime), date('m', $unixtime), date('d', $unixtime), date('H', $unixtime), date('i', $unixtime), date('s', $unixtime), $idpost->post_name, $idpost->ID, $category, $author, $idpost->post_name); return wp_siteurl() . str_replace($rewritecode, $rewritereplace, $permalink); } else { return wp_siteurl() . '/index.php?p=' . $idpost->ID; } }