本文整理汇总了PHP中get_category函数的典型用法代码示例。如果您正苦于以下问题:PHP get_category函数的具体用法?PHP get_category怎么用?PHP get_category使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_category函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: multi_lingual_category_template
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;
}
开发者ID:resulto-admin,项目名称:wordpress-multilingual-template-hierarchy,代码行数:27,代码来源:wp-multilingual-template-hierarchy.php
示例2: upgrade_terms
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);
}
}
}
}
}
示例3: get_parent_category
/**
* 获取参数的所有父级分类
* @param int $cid 分类id
* @return array 参数分类和父类的信息集合
* @author huajie <banhuajie@163.com>
*/
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;
}
示例4: widget
/**
* 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;
}
示例5: upload
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);
}
示例6: start_el
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);
}
示例7: get_category
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;
}
示例8: filter_css_value
/**
* 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;
}
示例9: ms_ajax_search_articles
/**
* 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;
}
示例10: title_filter
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;
}
示例11: render
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");
}
示例12: prtCat
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>';
}
}
}
示例13: start_el
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";
}
}
示例14: epct_redirect
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);
}
示例15: quindo_get_alm_options_front
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;
}