function multi_lingual_category_template($template) { $template_name = basename($template); if (!($template_name === 'category.php' || $template_name === 'archive.php' || $template_name === 'index.php')) { return $template; } $current_lang = apply_filters('wpml_current_language', NULL); $default_lang = apply_filters('wpml_default_language', NULL); if ($current_lang === $default_lang) { return $template; } $category_id = get_query_var('cat'); $id_in_default_lang = apply_filters('wpml_object_id', $category, 'category', FALSE, $default_lang); if (!$id_in_default_lang) { return $template; } $category = get_category($id_in_default_lang); if (!$category) { return $template; } $template_name = 'category-' . $category->slug . '.php'; $template_path = locate_template($template_name); if ($template_path) { return $template_path; } return $template; }
function upgrade_terms() { global $wpdb; $table = $wpdb->prefix . $this->terms_table; if ($wpdb->get_var("SHOW TABLES LIKE '{$table}'") == $table) { if (is_array($this->categories)) { foreach ($this->categories as $id => $category) { $object =& get_category($id); if ($object && is_array($category['head'])) { $robots = is_array($category['head']['meta']['robots']) ? serialize($category['head']['meta']['robots']) : ''; $query = "INSERT INTO {$table} (term_id, name, taxonomy, title, description, keywords, robots, headline, content) VALUES ('{$id}', '{$object->name}', '{$object->taxonomy}', '" . urldecode($category['head']['title']) . "', '" . urldecode($category['head']['meta']['description']) . "', '" . urldecode($category['head']['meta']['keywords']) . "', '{$robots}', '', '')"; $wpdb->query($query); } } } if (is_array($this->tags)) { foreach ($this->tags as $id => $tag) { $object =& get_tag($id); if ($object && is_array($tag['head'])) { $robots = is_array($tag['head']['meta']['robots']) ? serialize($tag['head']['meta']['robots']) : ''; $query = "INSERT INTO {$table} (term_id, name, taxonomy, title, description, keywords, robots, headline, content) VALUES ('{$id}', '{$object->name}', '{$object->taxonomy}', '" . urldecode($tag['head']['title']) . "', '" . urldecode($tag['head']['meta']['description']) . "', '" . urldecode($tag['head']['meta']['keywords']) . "', '{$robots}', '', '')"; $wpdb->query($query); } } } } }
/** * 获取参数的所有父级分类 * @param int $cid 分类id * @return array 参数分类和父类的信息集合 * @author huajie <*****@*****.**> */ function get_parent_category($cid) { if (empty($cid)) { return false; } $cates = M('Category')->where(array('status' => 1))->field('id,title,pid')->order('sort')->select(); $child = get_category($cid); //获取参数分类的信息 $pid = $child['pid']; $temp = array(); $res[] = $child; while (true) { foreach ($cates as $key => $cate) { if ($cate['id'] == $pid) { $pid = $cate['pid']; array_unshift($res, $cate); //将父分类插入到数组第一个元素前 } } if ($pid == 0) { break; } } return $res; }
/** * Public View */ function widget($args, $instance) { extract($args); /* Our variables from the widget settings. */ $title = apply_filters('widget_title', $instance['title']); $topics = $instance['topics']; /* REQUIRED */ echo $before_widget; /* 'before' and 'after' are REQUIRED */ if ($title) { echo $before_title . $title . $after_title . ' '; } /* Display array separated by delimiter * TODO: make delimiter a configurable option? * */ if ($topics && isset($topics)) { foreach ($topics as &$topic) { $category_id = get_cat_ID($topic); if (0 < $category_id) { // modified the category link for the niche sites "site category" functionality // @TODO: this should change in the future as we fix the niche site theme $category = get_category($category_id); $category_link = get_bloginfo('url') . '/category/' . $category->slug; $topic = '<a href="' . $category_link . '" title="' . $topic . '">' . $topic . '</a>'; } else { // topic is not a link } } echo implode(' | ', $topics); } /* REQUIRED */ echo $after_widget; }
public function upload() { /* 返回标准数据 */ $return = array('status' => 1, 'info' => '上传成功', 'data' => ''); /* 获取当前分类附件配置信息 */ $default = C('ATTACHMENT_DEFAULT'); $category = get_category(I('get.category')); /* 分类正确性检测 */ if (empty($category)) { $return['status'] = 0; $return['info'] = '没有指定分类或分类不正确;'; } else { $config = $category['extend']['attachment']; $config = empty($config) ? $default : array_merge($default, $config); /* 检测并上传附件 */ if (in_array('2', str2arr($config['allow_type']))) { $setting = C('ATTACHMENT_UPLOAD'); /* 调用文件上传组件上传文件 */ $File = M('File'); $info = $File->upload($_FILES, $setting, $config['driver'], $config['driver_config']); /* 记录附件信息 */ if ($info) { $return['data'] = think_encrypt(json_encode($info['attachment'])); } else { $return['status'] = 0; $return['info'] = $File->getError(); } } else { $return['info'] = '该分类不允许上传文件附件!'; $return['status'] = 0; } } /* 返回JSON数据 */ $this->ajaxReturn($return); }
function start_el(&$output, $item, $depth = 0, $args = array(), $id = 0) { $indent = $depth ? str_repeat("\t", $depth) : ''; $li_attributes = ''; $class_names = $value = ''; $classes = empty($item->classes) ? array() : (array) $item->classes; // managing divider: add divider class to an element to get a divider // before it. $id_cate = $id; $class_names = join(' ', apply_filters('nav_menu_css_class', array_filter($classes), $item, $args)); $class_names = ' class="' . esc_attr($class_names) . '"'; $id = apply_filters('nav_menu_item_id', 'menu-item-' . $item->ID, $item, $args); $id = strlen($id) ? ' id="' . esc_attr($id) . '"' : ''; $attributes = !empty($item->attr_title) ? ' title="' . esc_attr($item->attr_title) . '"' : ''; $attributes .= !empty($item->target) ? ' target="' . esc_attr($item->target) . '"' : ''; $attributes .= !empty($item->xfn) ? ' rel="' . esc_attr($item->xfn) . '"' : ''; $attributes .= !empty($item->url) ? ' href="' . esc_attr($item->url) . '"' : ''; $attributes .= ' class="list-group-item"'; //$item_output = $args->before; $item_output .= '<a' . $attributes . '>'; $category = get_category($item->object_id); $count = $category->category_count; $item_output .= $args->has_children ? '<span class="badge bg-warning">' . wp_get_postcount($item->object_id) . '</span>' : '<span class="badge bg-info">' . $count . '</span>'; $item_output .= $args->has_children ? '<span class="text-bold">' . $args->link_before . apply_filters('the_title', $item->title, $item->ID) . $args->link_after . '</span>' : $args->link_before . apply_filters('the_title', $item->title, $item->ID) . $args->link_after; $item_output .= '</a>'; //$item_output .= $args->after; $output .= apply_filters('walker_nav_menu_start_el', $item_output, $item, $depth, $args); }
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; }
/** * This function filters all the CSS insertion values. */ function filter_css_value($value, $option_id) { // Custom Category Background if ($option_id == 'category_background') { $orn_cat_custom_bg = ot_get_option('orn_category_background'); if ($orn_cat_custom_bg) { $category_bckg_settings = ''; foreach ($orn_cat_custom_bg as $orn_cat_bg) { $cat_bg_sel = get_category($orn_cat_bg['orn_cat_bg_select']); $cat_bg_name = isset($cat_bg_sel->name) ? $cat_bg_sel->name : false; $cat_bg_slug = isset($cat_bg_sel->slug) ? $cat_bg_sel->slug : false; $backgrounds = $orn_cat_bg['orn_cat_bg_image']; $cat_bg_img = ''; $cat_bg_color = ''; $cat_bg_prop = ''; foreach ($backgrounds as $cat_background_key => $cat_background_value) { switch ($cat_background_key) { case 'background-image': if (isset($cat_background_value)) { $cat_bg_img = 'url("' . $cat_background_value . '")'; } break; case 'background-color': if (isset($cat_background_value)) { $cat_bg_color = $cat_background_value; } break; default: if ($cat_background_value) { $cat_bg_prop .= ' ' . $cat_background_value; } break; } } $category_bckg_settings .= '/* Custom Background for ' . $cat_bg_name . ' Category */' . "\n" . 'html > body.category-' . $cat_bg_slug . ' { ' . "\n" . ' background: ' . $cat_bg_color . ' ' . $cat_bg_img . $cat_bg_prop . ';' . "\n" . '}' . "\n" . ''; } return $category_bckg_settings; } } elseif ($option_id == 'orn_font_title') { // Google Fonts for title $orn_title_font = ot_get_option('orn_font_title'); $select_font = $orn_title_font == 'default' ? 'PT+Sans:400,700' : $orn_title_font; $title_font_name = '"' . str_replace("+", " ", strtok($select_font, ":")) . '";'; return $title_font_name; } elseif ($option_id == 'orn_font_body') { // Google Fonts for Body $orn_body_font = ot_get_option('orn_font_body'); $select_font = $orn_body_font == 'default' ? 'Open+Sans:400,700' : $orn_body_font; $body_font_name = '"' . str_replace("+", " ", strtok($select_font, ":")) . '";'; return $body_font_name; } elseif ($option_id == 'orn_font_navigation') { // Google Fonts for menu $orn_nav_font = ot_get_option('orn_font_navigation'); $select_font = $orn_nav_font == 'default' ? 'Oswald:400,700' : $orn_nav_font; $nav_font_name = '"' . str_replace("+", " ", strtok($select_font, ":")) . '";'; return $nav_font_name; } // Always return $value return $value; }
/** * Created by PhpStorm. * User: cleavesp * Date: 3/30/15 * Time: 10:20 AM */ function ms_ajax_search_articles() { global $api_access_keys; $target_env = $_POST['env']; $article_search_type = $_POST['searchtype']; $search_term = $_POST['searchterm']; $results_order_by = $_POST['orderby']; $args = array('post_type' => $article_search_type, 's' => $search_term, 'posts_per_page' => -1); $the_query = new WP_Query($args); $output = array(); if ($the_query->have_posts()) { while ($the_query->have_posts()) { $the_query->the_post(); //$html_item = ms_format_content_item_html(get_the_ID()); //$html_item = esc_html($html_item); $image_attributes = wp_get_attachment_image_src(get_post_thumbnail_id(get_the_ID())); $content_categories = wp_get_post_categories(get_the_ID()); $isCuratedLink = false; foreach ($content_categories as $c) { $cat = get_category($c); if ($cat->slug == 'curatedlink') { $isCuratedLink = true; break; } } array_push($output, array('title' => get_the_title(), 'body' => wp_trim_words(get_the_content(), 18), 'byline' => get_post_meta(get_the_ID(), 'byLine', true), 'sourcePubName' => get_post_meta(get_the_ID(), 'sourcePublicationName', true), 'articlePlacementId' => get_post_meta(get_the_ID(), 'articlePlacementId_en_' . $target_env, true), 'origin_url' => get_post_meta(get_the_ID(), 'originUrl', true), 'sourceId' => get_post_meta(get_the_ID(), 'sourceId', true), 'lastPublished' => get_post_meta(get_the_ID(), 'LastPublished' . $target_env, true), 'thumbnail' => $image_attributes[0], 'editlink' => get_admin_url(null, '/post.php?post=' . get_the_ID() . '&action=edit'), 'mansionid' => get_the_ID(), 'previewLink' => get_permalink(get_the_ID()), 'wordpress_post_id' => get_the_ID(), 'externalid' => get_post_meta(get_the_ID(), 'sourceId', true), 'curatedLinkId' => get_post_meta(get_the_ID(), 'curated_link_id_' . $target_env, true), 'quote' => get_post_meta(get_the_ID(), 'Quote', true), 'headline' => get_post_meta(get_the_ID(), 'Headline', true), 'sub_headline' => get_post_meta(get_the_ID(), 'Subtitle', true), 'action_url' => get_post_meta(get_the_ID(), 'Url', true), 'credit' => get_post_meta(get_the_ID(), 'credit', true), 'isCuratedLink' => $isCuratedLink)); } } $response = array('res' => $output, 'httpCode' => '200'); $json = json_encode($response); echo $json; die; }
function title_filter($title) { global $page, $paged, $post, $admin_options; $ctrl_id = basename(__FILE__, '.php'); $seo = $admin_options[$ctrl_id]; $slip = trim($seo['slip']) == '' ? '_' : trim($seo['slip']); $title = trim($title); if ($seo['switch_home'] != 1 && $seo['switch_cat'] != 1 && $seo['switch_tag'] != 1 && $seo['switch_post'] != 1) { return $title; } // 首页标题优化 if ((is_home() || is_front_page()) && $seo['switch_home'] == 1) { if ($seo['blog_title']) { $title = $this->clear_code($seo['blog_title']); } else { $title = get_bloginfo('name') . $slip . get_bloginfo('description'); } } elseif (is_category() && $seo['switch_cat'] == 1) { global $cat; $cat_id = is_object($cat) ? $cat->cat_ID : $cat; $cat_title = single_cat_title('', false); $cat_seo_title = trim($this->get_term_meta($cat_id, 'seo_title')); $title = $cat_seo_title ? $cat_seo_title : $title; if ($seo['term_title'] == 1) { $category = get_category($cat_id); while ($category->parent) { $category = get_category($category->parent); $title .= $slip . $category->cat_name; } } $title .= $slip . get_bloginfo('name'); } elseif (is_tag() && $seo['switch_tag'] == 1) { global $wp_query; $tag_id = $wp_query->queried_object->term_id; $tag_name = $wp_query->queried_object->name; $tag_seo_title = trim($this->get_term_meta($tag_id, 'seo_title')); $title = $tag_seo_title ? $tag_seo_title : $tag_name; $title .= $slip . get_bloginfo('name'); } elseif (is_singular() && $seo['switch_post'] == 1) { $title = $post->post_title ? $post->post_title : $post->post_date; if ($seo['post_title'] == 1) { $category = get_the_category(); $category = $category[0]; while ($category->cat_ID) { $title .= $seo_slip . $category->cat_name; $category = get_category($category->parent); } } $title .= $slip . get_bloginfo('name'); } elseif (is_feed()) { return $title; } else { $title .= $slip . get_bloginfo('name'); } if ($paged >= 2 || $page >= 2) { $title .= $seo_slip . sprintf(__('第%s页'), max($paged, $page)); } $title = $this->clear_code($title); return $title; }
function render() { global $comicpress_manager, $comicpress_manager_admin; foreach (array('comiccat' => 'comic_category', 'blogcat' => 'blog_category') as $param => $field) { $result = false; if (isset($comicpress_manager->properties[$param])) { $check = $comicpress_manager->properties[$param]; if (!is_array($check)) { $check = array($check); } $result = array(); foreach ($check as $cat_id) { $category = get_category($cat_id); if (!is_wp_error($category)) { $result[] = $category; } else { $result = false; break; } } } $this->{$field} = $result; } include $this->_partial_path("sidebar"); }
public static function prtCat($categories, $category_act, $category_childs_act, $single = FALSE) { $DW =& $GLOBALS['DW']; foreach ($categories as $pid => $childs) { $run = TRUE; if ($DW->wpml) { include_once DW_MODULES . 'wpml_module.php'; $wpml_id = DW_WPML::getID($pid, 'tax_category'); if ($wpml_id > 0 && $wpml_id != $pid) { $run = FALSE; } } if ($run) { $cat = get_category($pid); echo '<div style="position:relative;left:15px;">'; echo '<input type="checkbox" id="' . ($single ? 'single_' : '') . 'category_act_' . $cat->cat_ID . '" name="' . ($single ? 'single_' : '') . 'category_act[]" value="' . $cat->cat_ID . '" ' . (isset($category_act) && count($category_act) > 0 && in_array($cat->cat_ID, $category_act) ? 'checked="checked"' : '') . ' onchange="chkChild(\'' . ($single ? 'single_' : '') . 'category\', ' . $pid . ');' . ($single ? 'ci(\'single_category_act_' . $cat->cat_ID . '\')' : '') . '" /> <label for="' . ($single ? 'single_' : '') . 'category_act_' . $cat->cat_ID . '">' . $cat->name . '</label><br />'; echo '<div style="position:relative;left:15px;">'; echo '<input type="checkbox" id="' . ($single ? 'single_' : '') . 'category_childs_act_' . $cat->cat_ID . '" name="' . ($single ? 'single_' : '') . 'category_childs_act[]" value="' . $cat->cat_ID . '" ' . (isset($category_childs_act) && count($category_childs_act) > 0 && in_array($cat->cat_ID, $category_childs_act) ? 'checked="checked"' : '') . ' onchange="chkParent(\'' . ($single ? 'single_' : '') . 'category\', ' . $cat->cat_ID . ');' . ($single ? 'ci(\'single_category_act_' . $cat->cat_ID . '\')' : '') . '" /> <label for="' . ($single ? 'single_' : '') . 'category_childs_act_' . $cat->cat_ID . '"><em>' . __('All childs', DW_L10N_DOMAIN) . '</em></label><br />'; echo '</div>'; if (count($childs) > 0) { self::prtCat($childs, $category_act, $category_childs_act, $single); } echo '</div>'; } } }
function start_el(&$output, $category, $depth = 0, $args = array(), $id = 0) { extract($args); $cat_name = esc_attr($category->name); $cat_name = apply_filters('list_cats', $cat_name, $category); $link = '<a href="#" data-filter=".term-' . $category->term_id . '" '; if ($use_desc_for_title == 0 || empty($category->description)) { $link .= 'title="' . sprintf(__('View all items filed under %s', 'epicomedia'), $cat_name) . '" >'; } else { $link .= 'title="' . esc_attr(strip_tags(apply_filters('category_description', $category->description, $category))) . '" >'; } $link .= $cat_name . '<span class="filterline"></span><span class="post-count">' . esc_attr(sprintf("%02d", $category->count)) . '</span></a>'; if (isset($current_category) && $current_category) { $_current_category = get_category($current_category); } if ($args['style'] == 'list') { $class = 'cat-item cat-item-' . $category->term_id; if (isset($current_category) && $current_category && $category->term_id == $current_category) { $class .= ' current'; } elseif (isset($_current_category) && $_current_category && $category->term_id == $_current_category->parent) { $class .= ' current-parent'; } $output .= "<li class=\"{$class}\""; $output .= ">{$link}\n"; } else { $output .= "\t{$link}<br />\n"; } }
function epct_redirect() { global $wp_query, $wp_version; if (is_category()) { $childcat = $wp_query->query_vars['cat']; $parent = get_category_parent($childcat); $category = get_category($childcat); if ($parent != 0) { $wp_query->query_vars['cat_child'] = $childcat; // fix from marty@halfempty to deal with custom template. if (!file_exists(STYLESHEETPATH . '/category-' . $category->slug . '.php')) { if (version_compare($wp_version, '3.1', '>=')) { //fix for WP 3.1 $category = get_queried_object(); $category->term_id = $parent; $category->slug = get_category($parent)->slug; } else { $wp_query->query_vars['cat'] = $parent; } } } } // print_r($wp_query->get_queried_object()); // print_r($wp_query->query_vars); }
function quindo_get_alm_options_front($offset) { $alm_options = quindo_get_alm_options(); if ($offset) { $alm_options['offset'] = $offset; } if (is_category()) { $alm_options['category'] = get_category(get_query_var('cat'))->slug; } if (is_year() || is_month() || is_day()) { $alm_options['year'] = get_the_time('Y'); } if (is_month() || is_day()) { $alm_options['month'] = get_the_time('n'); } if (is_day()) { $alm_options['day'] = get_the_time('j'); } if (is_author()) { $alm_options['author'] = get_user_by('slug', get_query_var('author_name'))->ID; } if (is_search()) { $alm_options['search'] = get_query_var('s'); } $alm_options_imploded = ''; foreach ($alm_options as $option => $value) { $alm_options_imploded .= ' ' . $option . '="' . $value . '"'; } return $alm_options_imploded; }
private function _meta_data($view, $params) { $defaults = array('class' => ''); $params = wp_parse_args($params, $defaults); $content = ''; // Date $content .= '<a href="' . get_month_link(get_the_time('Y'), get_the_time('m')) . '" class="blog_date"><i class="icon-calendar"></i>' . get_the_date('F j, Y') . '</a>'; // Categories $post_categories = wp_get_post_categories(get_the_ID()); $categories = array(); foreach ($post_categories as $c) { $cat = get_category($c); $categories[] = '<a href="' . get_category_link($cat->term_id) . '">' . $cat->name . '</a>'; } if (count($categories) > 0) { $content .= '<div class="blog_category"><i class="icon-tag"></i>' . implode(', ', $categories) . '</div>'; } // Author $content .= '<span class="blog_author"><i class="icon-user"></i>' . get_the_author() . '</span>'; $post_tags = wp_get_post_tags(get_the_ID()); $tags = array(); foreach ($post_tags as $tag) { $tags[] = '<a href="' . get_tag_link($tag->term_id) . '">' . $tag->name . '</a>'; } if (count($tags) > 0) { $content .= '<div class="blog_category"><i class="icon-tag"></i>' . implode(', ', $tags) . '</div>'; } return '<div class="' . $params['class'] . '">' . $content . '</div>'; }
function getPost() { $data = new stdClass(); $categoryId = (int) get_query_var('cat'); if (is_tag()) { $data->post = get_post(ThemeOption::getOption('blog_search_post_id')); $tagQuery = get_query_var('tag'); $tagData = get_tags(array('slug' => $tagQuery)); $data->post->post_title = esc_html($tagData[0]->name); } elseif (is_category($categoryId)) { $category = get_category($categoryId); $data->post = get_post(ThemeOption::getOption('blog_category_post_id')); $data->post->post_title = ThemeHelper::esc_html($category->name); } elseif (is_day()) { $data->post = get_post(ThemeOption::getOption('blog_archive_post_id')); $data->post->post_title = get_the_date(); } elseif (is_archive()) { $data->post = get_post(ThemeOption::getOption('blog_archive_post_id')); $data->post->post_title = single_month_title(' ', false); } elseif (is_search()) { $data->post = get_post(ThemeOption::getOption('blog_search_post_id')); $data->post->post_title = sprintf(__('Search result for phrase <i>%s</i>', THEME_DOMAIN), esc_html(get_query_var('s'))); } elseif (is_404()) { $data->post = get_post(ThemeOption::getOption('page_404_page_id')); $data->post->post_title = $data->post->post_title; } else { return false; } return $data; }
/** * TODO: docs * @param type $cat_name * @return type */ public function category_count_do($cat_name) { $cat_id = get_cat_ID($cat_name); $category = get_category($cat_id); $count = $category->category_count; return "{$cat_name} ({$count})"; }
function widget($args, $instance) { extract($args); $title = empty($instance['title']) ? ' ' : apply_filters('widget_title', $instance['title']); $limit = is_numeric($instance['limit']) ? $instance['limit'] : 5; $orderby = $instance['orderby'] ? $instance['orderby'] : 'date'; $order = $instance['order'] ? $instance['order'] : 'desc'; $exclude = $instance['exclude'] != '' ? $instance['exclude'] : 0; $excludeposts = $instance['excludeposts'] != '' ? $instance['excludeposts'] : 0; $offset = is_numeric($instance['offset']) ? $instance['offset'] : 0; $category_id = $instance['categoryid']; $dateformat = $instance['dateformat'] ? $instance['dateformat'] : get_option('date_format'); $showdate = $instance['show_date'] == 'on' ? 'yes' : 'no'; $showexcerpt = $instance['show_excerpt'] == 'on' ? 'yes' : 'no'; $excerptsize = empty($instance['excerpt_size']) ? 55 : $instance['excerpt_size']; $showauthor = $instance['show_author'] == 'on' ? 'yes' : 'no'; $showcatlink = $instance['show_catlink'] == 'on' ? 'yes' : 'no'; $thumbnail = $instance['thumbnail'] == 'on' ? 'yes' : 'no'; $thumbnail_size = $instance['thumbnail_size'] ? $instance['thumbnail_size'] : 'thumbnail'; $morelink = empty($instance['morelink']) ? ' ' : $instance['morelink']; $atts = array('id' => $category_id, 'orderby' => $orderby, 'order' => $order, 'numberposts' => $limit, 'date' => $showdate, 'author' => $showauthor, 'dateformat' => $dateformat, 'template' => 'default', 'excerpt' => $showexcerpt, 'excerpt_size' => $excerptsize, 'exclude' => $exclude, 'excludeposts' => $excludeposts, 'offset' => $offset, 'catlink' => $showcatlink, 'thumbnail' => $thumbnail, 'thumbnail_size' => $thumbnail_size, 'morelink' => $morelink); echo $before_widget; if ($title == 'catlink') { //if the user has setup 'catlink' as the title, replace it with the category link: $lcp_category = get_category($category_id); $title = '<a href="' . get_category_link($lcp_category->cat_ID) . '">' . $lcp_category->name . '</a>'; } echo $before_title . $title . $after_title; $catlist_displayer = new CatListDisplayer($atts); echo $catlist_displayer->display(); echo $after_widget; }
function prepare_schema($post_id, $schema) { $post = get_post($post_id); $this->content = $schema->post_content; $this->content = str_replace("%LINK%", $post->guid, $this->content); $this->content = str_replace("%TITLE%", $post->post_title, $this->content); $this->content = str_replace("%CONTENT%", $post->post_content, $this->content); $this->content = str_replace("%DATE%", $post->post_date, $this->content); $this->keywords = array(); $tags = wp_get_post_tags($post_id); foreach ($tags as $tag) { array_push($this->keywords, $tags[$tag]->name); } $categories = wp_get_post_categories($post_id); foreach ($categories as $category) { $cat = get_category($category); array_push($this->keywords, $cat->name); } $content = str_replace("%KEYWORDS%", implode(",", $this->keywords), $this->content); $args = array('posts_per_page' => 9999999, 'orderby' => 'post_title', 'order' => 'ASC', 'post_type' => 'lrfield', 'post_status' => 'publish', 'suppress_filters' => true); $fields = get_posts($args); foreach ($fields as $field) { $this->content = str_replace("%" . strtoupper($field->post_title) . "%", $field->post_content, $this->content); } }
private function get_post() { if (isset($this->options['text_limit']) && !empty($this->options['text_limit'])) { $limit = $this->options['text_limit']; } else { $limit = 100; } $start_date = date('F jS, Y', strtotime($this->options['start_date'])); $getPost = new WP_Query(array('cat' => implode(',', $this->options['categories']), 'date_query' => array(array('after' => $start_date)), 'orderby' => 'date', 'order' => 'ASC', 'meta_query' => array('relation' => 'OR', array('key' => 'aus_telegram_sent', 'compare' => 'NOT EXISTS', 'value' => '')), 'posts_per_page' => 1)); if (isset($getPost->posts[0])) { $getPost = $getPost->posts[0]; $text = $getPost->post_content; $text = strip_shortcodes($text); $text = preg_replace('/[\\r\\n]+/', "", $text); $text = preg_replace('/\\s+/', ' ', $text); $text = trim($text); $text = strip_tags($text); $text = $this->limit($text, $limit); $cat_ids = wp_get_post_categories($getPost->ID); if (!empty($cat_ids)) { $category = get_category($cat_ids[0])->name; } else { $category = ''; } $post = array('id' => $getPost->ID, 'title' => $getPost->post_title, 'url' => $getPost->guid, 'date' => date('d.m.Y', strtotime($getPost->post_date)), 'category' => $category, 'text' => $text); wp_reset_query(); return $post; } else { return false; } }
function start_el(&$output, $item, $depth = 0, $args = array(), $id = 0) { global $sections; $classes = array('menu-item' => 'section--menu-item', 'current' => 'section--current-bg', 'uncurrent' => 'section--%s-bg-hover', 'focused' => 'navmenu--focused', 'text-shadow' => 'section--%s-shadow-hover'); $binding = array('parent' => 'data-bind="event: { mouseover: setFocusMenu, touchstart: setFocusMenu }, mouseoverBubble: false"'); // Get category section parent. $category = get_category($sections->get_category_section_id(intval($item->object_id))); // Add appropriate menu classes to a given menu item. if ($item->object === 'category' && !$item->menu_item_parent) { $item->classes[] = $classes['menu-item']; if ($sections::$current_section === $category->cat_ID) { // Add focused and current classes if the the section is current. $item->classes[] = sprintf($classes['current'], $category->slug); // Uncomment this line to have the section menu popout by default. // $item->classes[] = $classes['focused']; } else { // Elsewise add the hover BG class. $item->classes[] = sprintf($classes['uncurrent'], $category->slug); } } else { if ($item->menu_item_parent) { $item->classes[] = sprintf($classes['text-shadow'], $category->slug); } } // Reduce code by extending the parent function. parent::start_el($output, $item, $depth = 0, $args, $id); // Add data attribute and binding with regex. if (!$item->menu_item_parent) { $match = '/\\<li\\sid="menu-item-' . $item->ID . '"/'; $replace = '<li id="menu-item-' . $item->ID . '" ' . $binding['parent']; $output = preg_replace($match, $replace, $output, 1); } }
function _cat_row( $category, $level, $name_override = false ) { global $class; $category = get_category( $category ); $pad = str_repeat( '— ', $level ); $name = ( $name_override ? $name_override : $pad . ' ' . $category->name ); if ( current_user_can( 'manage_categories' ) ) { $edit = "<a class='row-title' href='categories.php?action=edit&cat_ID=$category->term_id' title='" . attribute_escape(sprintf(__('Edit "%s"'), $category->name)) . "'>$name</a>"; } else { $edit = $name; } $class = " class='alternate'" == $class ? '' : " class='alternate'"; $category->count = number_format_i18n( $category->count ); $posts_count = ( $category->count > 0 ) ? "<a href='edit.php?cat=$category->term_id'>$category->count</a>" : $category->count; $output = "<tr id='cat-$category->term_id'$class> <th scope='row' class='check-column'>"; if ( absint(get_option( 'default_category' ) ) != $category->term_id ) { $output .= "<input type='checkbox' name='delete[]' value='$category->term_id' /></th>"; } else { $output .= " "; } $output .= "<td>$edit</td> <td>$category->description</td> <td class='num'>$posts_count</td>\n\t</tr>\n"; return apply_filters('cat_row', $output); }
function do_html_header($title = '', $script = '', $style = '') { if (!empty($script)) { foreach ($script as $item) { ?> <script type="text/javascript" src="js/<?php echo $item; ?> "></script> <?php } } ?> <html> <head> <title> <?php echo $title; ?> </title> </head> <body> <?php if (isset($_SESSION['author'])) { $cate = get_category(); display_category($cate); } }
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 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; } }
/** * 获取文档列表 Document * @param num $p 当前 * @param array|num $categoryid 所属文档 * @param num $list_row 每页记录 * @param bool $extend 是否读取子文档 * @return array 文档列表 */ public static function get_list($p = 1, $categoryid, $list_row, $extend = true) { if (empty($categoryid)) { return '文档列表的分类属性必须为数字'; } //获取分类属性 $category = is_array($categoryid) ? $categoryid : get_category($categoryid); //获取分类属性 $list_row = empty($list_row) ? $category['list_row'] : $list_row; /* 获取当前分类列表 */ $Document = D('Document'); $list = $Document->page($p, $list_row)->lists($category['id']); if (false === $list) { return '获取文档列表数据失败'; } //判断是否读取子文档 if (true === $extend) { $newlist = array(); $modellist = self::get_sublist($category['model']); foreach ($list as $key => $value) { $newlist[$key] = array_merge($value, $modellist[$value['id']]); } } else { $newlist = $list; } return $newlist; }
/** * Create a list of checkboxes that can be used to select additional categories. */ function _generate_additional_categories_checkboxes($override_name = null) { global $comicpress_manager; $additional_categories = array(); $invalid_ids = array($comicpress_manager->properties['blogcat']); foreach ($this->category_tree as $node) { $invalid_ids[] = end(explode('/', $node)); } foreach (get_all_category_ids() as $cat_id) { if (!in_array($cat_id, $invalid_ids)) { $category = get_category($cat_id); $additional_categories[strtolower($category->cat_name)] = $category; } } ksort($additional_categories); $name = !empty($override_name) ? $override_name : "additional-categories"; $selected_additional_categories = explode(",", $comicpress_manager->get_cpm_option("cpm-default-additional-categories")); $this->category_checkboxes = array(); if (count($additional_categories) > 0) { foreach ($additional_categories as $category) { $checked = in_array($category->cat_ID, $selected_additional_categories) ? "checked=\"checked\"" : ""; $this->category_checkboxes[] = "<label><input id=\"additional-" . $category->cat_ID . "\" type=\"checkbox\" name=\"{$name}[]\" value=\"" . $category->cat_ID . "\" {$checked} /> " . $category->cat_name . "</label><br />"; } } return $this->category_checkboxes; }
function cats() { foreach (wp_get_post_categories(get_the_ID()) as $c) { $cat = get_category($c); return ' - <a href="' . get_category_link($cat) . '" title="' . $cat->name . '" class="category">' . $cat->name . '</a>'; } }
function category() { /** * set the page header for the category archive */ $this->View->add('layout_header_title', get_category(get_query_var('cat'))->name); }