/** * Subnav of current category's topmost parent's children, outputted as widget * todo - make it an actual widget */ function category_subnav() { global $post; if (is_category() || is_single()) { $categories = get_the_category(); $category = array_shift($categories); $top_parent = $category->category_parent ? $category->category_parent : $category->cat_ID; $top_parent_name = get_cat_name($top_parent); $top_parent_children = wp_list_categories(array('child_of' => $top_parent, 'title_li' => '', 'echo' => 0)); if ($top_parent_children != '<li>No categories</li>') { ?> <nav class="widget widget-subnav"> <h1 class="widget-title nav-title">'<?php echo $top_parent_name; ?> </h1> <div class="widget-content"> <ul class="menu menu-secondary"> <?php echo $top_parent_children; ?> </ul> </div> </nav> <?php } } }
/** @see WP_Widget::widget */ function widget($args, $instance) { extract($args); $category_id = $instance['category_id']; echo $before_widget; ?> <?php echo "<h2>" . get_cat_name($category_id) . "</h2>"; ?> <ul> <?php global $post; $args = array('category' => $category_id, "numberposts" => -1, "orderby" => "title", "order" => "ASC"); $myposts = get_posts($args); foreach ($myposts as $post) { setup_postdata($post); ?> <li><a href="<?php the_permalink(); ?> "><?php the_title(); ?> </a></li> <?php } ?> </ul> <?php wp_reset_query(); echo $after_widget; }
function wolf_breadcrumbs_get_category_links($page_id = '') { if (strlen(trim($page_id)) > 0) { $cat_name = ''; $cat_url = ''; $cats = get_the_category($page_id); if (count($cats) > 0) { $cat = $cats[0]; $cat_id = $cat->cat_ID; $cat_name = $cat->cat_name; $cat_url = get_category_link($cat_id); } } else { if (single_tag_title('', false == '')) { $cat_id = get_query_var('cat'); $cat_name = get_cat_name($cat_id); $cat_url = get_category_link($cat_id); } else { $cat_url = get_tag_link(get_query_var('tag_id')); $cat_name = single_tag_title('', false); } } $cat_link = '<li>'; $cat_link .= '<a href="' . $cat_url . '" itemprop="url"><span itemprop="title">' . $cat_name . '</span></a>'; if (strlen(trim($page_id)) > 0 && strlen(trim($cat_name)) > 0) { $cat_link .= '<span class="divider">/</span>'; } $cat_link .= '</li>'; return $cat_link; }
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; } }
function my_rest_prepare_post($data, $post, $request) { $_data = $data->data; $thumbnail_id = get_post_thumbnail_id($post->ID); $thumbnail = wp_get_attachment_image_src($thumbnail_id); $_data['featured_image_thumbnail_url'] = $thumbnail[0]; $categories = get_categories(); $_data['all_categories'] = $categories; unset($_data['author']); unset($_data['comment_status']); unset($_data['ping_status']); unset($_data['modified']); unset($_data['modified_gmt']); unset($_data['date_gmt']); unset($_data['guid']); unset($_data['slug']); unset($_data['sticky']); $tags_arr = array(); foreach ($_data['tags'] as $tagID) { $tag = get_tag($tagID); // add name field to the array $tags_arr[] = array('ID' => $tagID, 'name' => $tag->name); } $_data['tags'] = $tags_arr; // assign the new tags array to the JSON field $categories_arr = array(); foreach ($_data['categories'] as $catID) { // add name field to the array $categories_arr[] = array('ID' => $catID, 'name' => get_cat_name($catID)); } $_data['categories'] = $categories_arr; // assign the new tags array to the JSON field $data->data = $_data; return $data; }
function Grafik_Functions_Shortcode_TypeCategories($atts, $content = '') { global $wp_query; global $GRAFIK_MODE; $callback_output = ''; $a = shortcode_atts(array('type' => 'post', 'class' => '', 'id' => ''), $atts, 'TypeCategories'); // Construct the query... $callback_query = new WP_Query(array('post_type' => $a['type'], 'posts_per_page' => -1)); // Loop the query... $callback_categories = array(); if ($callback_query->have_posts()) { while ($callback_query->have_posts()) { $callback_query->the_post(); $callback_post = get_post(); $callback_postcats = wp_get_post_categories($callback_post->ID); foreach ($callback_postcats as $key => $val) { $callback_categories[$val]++; } } wp_reset_postdata(); } else { $callback_output .= '<span class="empty-message">' . $a['empty_msg'] . '</span>'; } // Loop the results... foreach ($callback_categories as $key => $val) { $callback_output .= '<li class="ge-typecategories-item">' . '<a href="' . esc_url(get_category_link($key)) . '" class="ge-typecategories-link">' . '<span class="ge-typecategories-name">' . get_cat_name($key) . '</span>' . '<span class="ge-typecategories-count">' . $val . '</span>' . '</a>' . '</li>'; } if (empty($callback_output)) { return ''; } return '<div class="ge-typecategories-container' . (empty($a['class']) ? null : ' ' . $a['class']) . '"' . (empty($a['id']) ? null : ' id="' . $a['id'] . '"') . '>' . '<div class="ge-typecategories-content">' . $content . '</div>' . '<ul class="ge-typecategories-list">' . $callback_output . '</ul>' . '</div>'; }
function form($instance) { $default = array('title' => 'Widget Demo', 'number_post' => '5', 'current_category' => ''); // Gộp các giá trị của $default vào $instance để nó trở thành giá trị mặc định $instance = wp_parse_args((array) $instance, $default); // Gán giá trị ($instance['title'] cho $title (khởi tạo biến $title)) $title = esc_attr($instance['title']); $number_post = esc_attr($instance['number_post']); // Get title echo "<p>Title:</p>"; echo "<p><input type=\"text\" name=\"" . $this->get_field_name('title') . "\" value=\"" . $title . "\" /></p>"; // Select category $all_categories = get_all_category_ids(); echo "<p>Category:</p>"; echo "<p><select id=\"" . $this->get_field_id('current_category') . "\" name=\"" . $this->get_field_name('current_category') . "\" >"; foreach ($all_categories as $category) { if ($category == $instance['current_category']) { echo "<option value=\"" . $category . "\" selected=\"selected\">" . get_cat_name($category) . "</option>"; } else { echo "<option value=\"" . $category . "\">" . get_cat_name($category) . "</option>"; } } echo "</select></p>"; // Get count echo "<p>Show number posts:</p>"; echo "<p><input type=\"text\" name=\"" . $this->get_field_name('number_post') . "\" value=\"" . $number_post . "\" /></p>"; }
/** * Front-end display of widget. * * @see WP_Widget::widget() * @since 1.0.0 * * @param array $args Widget arguments. * @param array $instance Saved values from database. */ function widget($args, $instance) { // Extract args extract($args, EXTR_SKIP); $category_id = empty($instance['category_id']) ? 1 : $instance['category_id']; $post_num = empty($instance['post_num']) ? 5 : $instance['post_num']; $use_cat_title = empty($instance['use_cat_title']) ? 0 : $instance['use_cat_title']; $title_link = empty($instance['title_link']) ? 0 : $instance['title_link']; 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']) ? __('Listen to Broadcast', 'wpsp') : $instance['title'], $instance, $this->id_base); } 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; } global $post; $args = array(); $defaults = array('post_type' => 'post', 'posts_per_page' => (int) $post_num, 'post__not_in' => array($post->ID), 'tax_query' => array('relation' => 'AND', array('taxonomy' => 'post_format', 'field' => 'slug', 'terms' => array('post-format-audio')), array('taxonomy' => 'category', 'field' => 'term_id', 'terms' => array($category_id)))); $args = wp_parse_args($args, $defaults); extract($args); $custom_query = new WP_Query($args); if ($custom_query->have_posts()) { while ($custom_query->have_posts()) { $custom_query->the_post(); get_template_part('partials/content', 'radio'); } wp_reset_postdata(); } echo $after_widget; return $instance; }
/** * Generates the tabs for posts * * @param array $content * @return array */ public static function get_tab_posts($content) { // Set up date filter self::date_range($content['from_date'], $content['to_date']); // Set up results array $results = array('title' => '{Needs to be changed}', 'tabs' => array()); // Get posts foreach ($content['categories'] as $cat_id) { // If parent skip if (self::is_parent($cat_id)) { continue; } // Get posts $query_results = query_posts(array('cat' => $cat_id, 'orderby' => 'date', 'order' => 'desc', 'posts_per_page' => $content['posts_number'] === 'All' ? self::$result_limit[$content['layout']] : 1)); // Remove filter wp_reset_query(); remove_filter('posts_where', array('Posts_Widget', 'date_filter')); // Get custom fields $cat_name = get_cat_name($cat_id); $results['tabs'][$cat_name] = array(); foreach ($query_results as $result) { $result->fields = (object) get_fields($result->ID); $results['tabs'][$cat_name][] = $result; } } return $results; }
/** * Front-end display of widget. * * @see WP_Widget::widget() * @since 1.0.0 * * @param array $args Widget arguments. * @param array $instance Saved values from database. */ function widget($args, $instance) { // Extract args 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']; 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', 'wpsp') : $instance['title'], $instance, $this->id_base); } $no_sub_text = '<p>' . __('No sub-categories', 'wpsp') . '</p>'; $subs = wp_list_categories(array('child_of' => $category_id, 'hide_empty' => $hide_empty_cats, 'show_count' => $show_post_count, 'title_li' => null, 'show_option_none' => '', 'echo' => 0)); 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 (!empty($subs)) { echo '<ul>' . $subs . '</ul>'; } else { echo $no_sub_text; } echo $after_widget; return $instance; }
function widget($args, $advcat_instance) { extract($args); $title = apply_filters('widget_title', empty($advcat_instance['title']) ? 'Categories' : $advcat_instance['title'], $advcat_instance, $this->id_base); $numCols = isset($advcat_instance['numCols']) ? $advcat_instance['numCols'] : false; if (!($cats = $advcat_instance["cats"])) { $cats = ''; } $advcat_widget = null; $advcat_widget = new WP_Query($advcat_args); echo $before_widget; echo '<div id="adv-recent-cats" class="widget-inner">'; // Widget title if ($advcat_instance["title"] != '') { echo $before_title; echo $advcat_instance["title"]; echo $after_title; } // Post list in widget if ($cats != '') { echo "<ul class='row'>\n"; foreach ($cats as $cat) { if ($numCols) { echo '<li class="advwidget-item col-xs-6">'; } else { echo '<li class="advwidget-item col-xs-12">'; } // Get the ID of a given category $category_id = $cat; // Get the URL of this category $category_link = get_category_link($category_id); // Get te Name of this category $category_name = get_cat_name($category_id); ?> <!-- Print a link to this category --> <a href="<?php echo esc_url($category_link); ?> "><?php echo $category_name; ?> </a> </li> <?php } //end for each ?> <?php //endif; ?> <?php wp_reset_query(); echo "</ul>\n"; } //end if array not empty echo '</div>'; echo $after_widget; }
function widget($args, $instance) { // outputs the content of the widget extract($args); $this->category_JS(); $title = apply_filters('widget_title', $instance['title']); if ($args['id'] == 'sidebar-footerwidgetarea') { $footer_width = 'span' . circleflip_calculate_widget_width(); } else { $footer_width = ''; } ?> <li class="categoryCount widget customWidget <?php echo esc_attr($footer_width); ?> "> <?php if ($title != null) { ?> <div class="widgetDot"></div> <h3 class="widgetTitle grid2"><?php echo esc_html($title); ?> </h3> <?php } $category_ids = get_terms('category', array('fields' => 'ids', 'get' => 'all')); foreach ($category_ids as $cat_id) { $cat_name = get_cat_name($cat_id); if ($cat_name != 'Uncategorized') { ?> <p class="widgetcategory_with_count textwidget"> <span class="left"><a href="<?php echo esc_url(get_category_link($cat_id)); ?> "><?php echo esc_html($cat_name); ?> </a></span> <?php $postsInCat = get_term_by('name', $cat_name, 'category'); $postsInCat = $postsInCat->count; ?> <span class="right"><?php echo '(' . $postsInCat . ')'; ?> </span> </p> <?php } } ?> </li> <?php }
public static function get_video_category_link() { $category_ids = get_all_category_ids(); foreach ($category_ids as $cat_id) { if (!strcmp(get_cat_name($cat_id), "video")) { echo get_category_link($cat_id); } } }
function list_type($category, $type) { echo "<h1>" . get_cat_name(get_category_by_slug($category)->cat_ID) . ":</h1>\n"; $files = new WP_Query(array('category_name' => $category, 'post_type' => $type, 'order' => 'ASC', 'orderby' => 'title')); while ($files->have_posts()) { $files->the_post(); echo "<p>" . the_post_thumbnail() . "<strong>" . get_the_title() . "</strong>: " . get_the_content() . "</p>\n"; } }
protected function constantTest() { $post_id_1 = 0; $time = microtime(true); for ($i = 0; $i < $this->runNumber; $i++) { get_cat_name(1); } $time = microtime(true) - $time; $this->enterResult($time); }
public function getCategoryNewsTitle() { if (isset($this->categoryNewsTitle)) { return $this->categoryNewsTitle; } if ($this->isCategoryNewsId()) { return $this->categoryNewsTitle = get_cat_name($this->getCategoryNewsId()); } return $this->categoryNewsTitle = ""; }
function find_category_by_name($name) { $cat = null; $category_ids = get_all_category_ids(); foreach ($category_ids as $cat_id) { if (!strcmp(get_cat_name($cat_id), "Blog")) { $cat = $cat_id; } } return $cat; }
public function getCategories($theCategories) { if (!$theCategories) { return array(); } $array = array(); foreach ($theCategories as $category) { $params = array('name' => get_cat_name($category->cat_ID), 'link' => get_category_link($category)); $array[] = new Category($params + get_object_vars($category)); } return $array; }
function mycatlist_func($atts, $content = null) { $atts = shortcode_atts(array('cat' => '0'), $atts); $catid = $atts['cat']; add_filter('post_limits', 'cat_post_limit'); global $myOffset; $myOffset = 1; $temp = $wp_query; $wp_query = null; $wp_query = new WP_Query(); $wp_query->query('cat=' . $catid . '&offset=' . $myOffset . '&posts_per_page=' . intval(get_option('posts_per_page')) . '&paged=' . $paged); $pages = $wp_query->max_num_pages; ob_start(); ?> <h2> <?php echo get_cat_name($catid); ?> </h2> <ul> <?php while ($wp_query->have_posts()) { $wp_query->the_post(); ?> <li><a href="<?php the_permalink(); ?> " rel="bookmark" title="<?php the_title(); ?> "><?php the_title(); ?> </a></li> <?php } ?> </ul> <div class="navigation"><?php echo mukesh_pagination($pages); ?> </div> <?php $myoutput = ob_get_contents(); ob_end_clean(); $wp_query = null; $wp_query = $temp; remove_filter('post_limits', 'cat_post_limit'); return $myoutput; }
function catDropDown($thisCatID) { if ($thisCatID[1] == "0") { $thisCatID[1] = 1; } $category_ids = get_all_category_ids(); echo '<OPTION ' . (isset($thisCatID[0]) && is_null($thisCatID[0]) ? 'selected' : '') . ' VALUE=NULL>Not in Use</OPTION>'; foreach ($category_ids as $cat_id) { $cat_name = get_cat_name($cat_id); echo '<OPTION ' . selected(true, in_array($cat_id, $thisCatID), false) . ' VALUE="' . $cat_id . '">' . $cat_name . '</OPTION>'; } }
function rpf_custom_template($sourcelink, $feed_id) { global $rpf_options; $custom_template = $rpf_options['custom_template']; if (false === strpos($custom_template, '%SOURCE_URL%')) { $custom_template .= ' <a href="%SOURCE_URL%">%SOURCE_URL%</a> '; } $feed = rpf_get_feed($feed_id); $user = get_userdata($feed['author']); $author = $user->nickname; $category = get_cat_name($feed['category']); $feed_url = $feed['url']; $feed_name = $feed['name']; $custom_template = str_replace(array('%SOURCE_URL%', '%AUTHOR%', '%CATEGORY%', '%FEED_URL%', '%FEED_NAME%'), array($sourcelink, $author, $category, $feed_url, $feed_name), $custom_template); return $custom_template; }
function render() { global $comicpress_manager; if ($comicpress_manager->get_subcomic_directory() !== false) { $comicpress_manager->messages[] = sprintf(__("<strong>Reminder:</strong> You are managing the <strong>%s</strong> comic subdirectory.", 'comicpress-manager'), get_cat_name(get_option('comicpress-manager-manage-subcomic'))); } // need to do checks better // if ($comicpress_manager->get_cpm_option('cpm-skip-checks') != 1) { // if (!function_exists('get_comic_path')) { // $comicpress_manager->warnings[] = __('<strong>It looks like you\'re running an older version of ComicPress.</strong> Storyline, hovertext, and transcript are fully supported in <a href="http://comicpress.org/">ComicPress 2.7</a>. You can use hovertext and transcripts in earlier themes by using <tt>get_post_meta($post->ID, "hovertext", true)</tt> and <tt>get_post_meta($post->ID, "transcript", true)</tt>.', 'comicpress-manager'); // } // } if (count($_POST) == 0 && isset($_GET['upload'])) { $comicpress_manager->warnings[] = sprintf(__("Your uploaded files were larger than the <strong><tt>post_max_size</tt></strong> setting, which is currently <strong><tt>%s</tt></strong>. Either upload fewer/smaller files, upload them via FTP/SFTP, or increase your server's <strong><tt>post_max_size</tt></strong>.", 'comicpress-manager'), ini_get('post_max_size')); } include $this->_partial_path('upload'); }
/** * Get the categories from blog * @return array ID and category names */ function GetCategories() { global $wpdb; $categories = get_all_category_ids(); $separator = '|'; $output = array(); if ($categories) { foreach ($categories as $category) { $temp_catname = get_cat_name($category); if ($temp_catname !== "Uncategorized") { $output[$category] = $temp_catname; } } } else { $output = 'test'; } return $output; }
/** * 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 tfuse_shortcode_blog_categories($atts, $content = null) { extract(shortcode_atts(array('title' => '', 'cat' => ''), $atts)); $out = ''; $categories = explode(',', $cat); if (!empty($categories)) { $categories = array_reverse($categories); $out .= '<div class="widget widget_categories"> <h3 class="widget-title">' . $title . '</h3> <ul>'; foreach ($categories as $category) { $term = get_term_by('id', $category, 'category'); $out .= '<li><a href="' . get_category_link($category) . '">' . get_cat_name($category) . ' <span class="count">(' . $term->count . ')</span></a></li>'; } $out .= '</ul> </div>'; } return $out; }
function form($instance) { $default = array('number_post_1' => '5', 'current_category_1' => '', 'number_post_2' => '5', 'current_category_2' => ''); // Initilize default values ($instance) $instance = wp_parse_args((array) $instance, $default); // Create param, method esc_attr($instance['number_post_1']) : get value number_post_1 $number_post_1 = esc_attr($instance['number_post_1']); $number_post_2 = esc_attr($instance['number_post_2']); /* Display column 1 */ // Select category $all_categories = get_all_category_ids(); echo "<p><strong>COLUMN 1:</strong></p>"; echo "<p>Category:</p>"; echo "<p><select id=\"" . $this->get_field_id('current_category_1') . "\" name=\"" . $this->get_field_name('current_category_1') . "\" >"; foreach ($all_categories as $category) { if ($category == $instance['current_category_1']) { echo "<option value=\"" . $category . "\" selected=\"selected\">" . get_cat_name($category) . "</option>"; } else { echo "<option value=\"" . $category . "\">" . get_cat_name($category) . "</option>"; } } echo "</select></p>"; // Display number post in a category echo "<p>Show number posts:</p>"; echo "<p><input type=\"text\" name=\"" . $this->get_field_name('number_post_1') . "\" value=\"" . $number_post_1 . "\" /></p>"; /* Display column 2 */ // Select category echo "<p><strong>COLUMN 2:</strong></p>"; echo "<p>Category:</p>"; echo "<p><select id=\"" . $this->get_field_id('current_category_2') . "\" name=\"" . $this->get_field_name('current_category_2') . "\" >"; foreach ($all_categories as $category) { if ($category == $instance['current_category_2']) { echo "<option value=\"" . $category . "\" selected=\"selected\">" . get_cat_name($category) . "</option>"; } else { echo "<option value=\"" . $category . "\">" . get_cat_name($category) . "</option>"; } } echo "</select></p>"; // Display number post in a category echo "<p>Show number posts:</p>"; echo "<p><input type=\"text\" name=\"" . $this->get_field_name('number_post_2') . "\" value=\"" . $number_post_2 . "\" /></p>"; }
function mytheme_wp_title($title) { global $paged, $page; if (is_feed()) { return $title; } // Add the site name. if (is_home()) { $title = 'Blog Web & Design'; } if (!is_front_page()) { $title = get_the_title(); if (is_category()) { $catID = get_query_var('cat'); $title = get_cat_name($catID); } $title .= ' | ' . get_bloginfo('description'); } return $title; }
function wpgrade_main_category($category, $shout = true) { if (!empty($category)) { $parent = get_cat_name($category[0]->category_parent); if (!empty($parent)) { if ($shout) { echo strtolower($parent); } else { return strtolower($parent); } } else { if ($shout) { echo strtolower($category[0]->cat_name); } else { return strtolower($category[0]->cat_name); } } } else { return ''; } }
function get_page_title($prefix = "", $separator = "") { $title = ""; if (is_category()) { $category = get_category(get_query_var('cat'), false); $title = get_cat_name($category->cat_ID); } if (is_post_type_archive()) { $title = get_post_type_singular_name(); } if (is_single() || is_page()) { $title = get_the_title(); } if (is_search()) { $title = "Ricerca"; } if (is_front_page()) { return $prefix; } return "{$prefix}{$separator}{$title}"; }
/** @see WP_Widget::widget */ function widget($args, $instance) { if (is_user_logged_in()) { $tmp_cat_id = get_query_var("cat"); // Only show if on category archive pages if (!isset($tmp_cat_id) || $tmp_cat_id == 0) { return; } $instance = array_merge($this->defaults, $instance); $tmp_cat_name = get_cat_name($tmp_cat_id); //error_log("cat id: "); //error_log($tmp_cat_id); // Set link & Title name $tmp_link_name = str_replace('#category#', $tmp_cat_name, $instance['link_name']); $tmp_title_name = str_replace('#category#', $tmp_cat_name, $instance['title']); echo $args['before_widget']; if (!empty($instance['title'])) { echo $args['before_title']; //echo $instance['title']; echo $tmp_title_name; echo $args['after_title']; } ?> <div class="frontier-category-post-widget"> <?php //echo "Category: "; //echo $tmp_cat_name."(".$tmp_cat_id.")"; echo '<p><center><a href="' . frontier_post_add_link(null, $tmp_cat_id) . '&frontier_new_cat_widget=true' . '">' . $tmp_link_name . '</a></center></p>'; ?> </div> <?php echo $args['after_widget']; } else { // echo "<p>".__("You need to login to see your posts", "frontier-post")."</p>"; } }