本文整理汇总了PHP中get_the_category_by_ID函数的典型用法代码示例。如果您正苦于以下问题:PHP get_the_category_by_ID函数的具体用法?PHP get_the_category_by_ID怎么用?PHP get_the_category_by_ID使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_the_category_by_ID函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: wpgeoip_redirect
function wpgeoip_redirect()
{
if (get_option('wpgeoip_no_redirect', 0) == 1 and isset($_GET['noredirect'])) {
return false;
}
require_once 'geoip.inc';
//open geoip binary database
$gi = geoip_open(plugin_dir_path(__FILE__) . 'GeoIP.dat', GEOIP_STANDARD);
global $wpdb;
global $wp_query;
global $post;
$prefix = $wpdb->prefix;
$postID = $post->ID;
$catID = intval($wp_query->query_vars['cat']);
$isHome = is_home();
$the_page_name = '';
//get user country
$countryCode = geoip_country_code_by_addr($gi, WPGeoIP_getIP());
//sitewide rule
$rs_redirect = $wpdb->get_row("SELECT `targetURL` FROM `" . $prefix . "grules` WHERE `countryID` = '{$countryCode}' \n\t\t\t\t\t\t\tAND `postID` = 999999");
if (isset($rs_redirect) and count($rs_redirect)) {
$the_page_name = get_the_title($postID);
$wpdb->query("INSERT INTO wpgeoip_log VALUES (null, 'SITEWIDE Redirect', 'Redirecting Country <strong>" . $countryCode . "</strong> to " . $rs_redirect->targetURL . "')");
print '<meta http-equiv="refresh" content="0;url=' . $rs_redirect->targetURL . '"/>';
exit;
}
//redirect if any rule for this country
if ($postID != 0) {
$rs_redirect = $wpdb->get_row("SELECT `targetURL` FROM `" . $prefix . "grules` WHERE `countryID` = '{$countryCode}' \n\t\t\t\t\t\t\tAND `postID` = {$postID}");
$the_page_name = get_the_title($postID);
}
if ($catID != 0) {
$rs_redirect = $wpdb->get_row("SELECT `targetURL` FROM `" . $prefix . "grules` WHERE `countryID` = '{$countryCode}' \n\t\t\t\t\t\t\tAND `catID` = {$catID}");
$the_page_name = 'Category : ' . get_the_category_by_ID($catID);
}
if ($isHome) {
$rs_redirect = $wpdb->get_row("SELECT `targetURL` FROM `" . $prefix . "grules` WHERE `countryID` = '{$countryCode}' \n\t\t\t\t\t\t\tAND `home_rule` = 1");
$the_page_name = 'Homepage';
}
if (!$rs_redirect) {
//NOTHING TO DO
#$wpdb->query("INSERT INTO wpgeoip_log VALUES (null, 'Redirect', 'Nothing to do. No rules for Country <strong>".$countryCode."</strong>')");
}
if (isset($rs_redirect) and count($rs_redirect)) {
$wpdb->query("INSERT INTO wpgeoip_log VALUES (null, 'Redirect <em>" . $the_page_name . "</em>', 'Redirecting Country <strong>" . $countryCode . "</strong> to " . $rs_redirect->targetURL . "')");
print '<meta http-equiv="refresh" content="0;url=' . $rs_redirect->targetURL . '"/>';
exit;
} else {
//CHECK COUNTRIES WITHOUT REDIRECT RULES
$mass_redirect_enabled = get_option('wpgeoip_mass_redirect');
if ($mass_redirect_enabled != "0") {
$mass_url = get_option('wpgeoip_mass_url');
$wpdb->query("INSERT INTO wpgeoip_log VALUES (null, 'Mass Redirect', 'Redirecting Country <strong>" . $countryCode . "</strong> to " . $rs_redirect->targetURL . "')");
print '<meta http-equiv="refresh" content="0;url=' . $mass_url . '"/>';
exit;
} else {
//NOTHING TO DO AGAINM
}
}
}
示例2: get_nested_categories
function get_nested_categories($default = 0, $parent = 0) {
global $post_ID, $mode, $wpdb;
if ($post_ID) {
$checked_categories = $wpdb->get_col("
SELECT category_id
FROM $wpdb->categories, $wpdb->post2cat
WHERE $wpdb->post2cat.category_id = cat_ID AND $wpdb->post2cat.post_id = '$post_ID'
");
if(count($checked_categories) == 0)
{
// No selected categories, strange
$checked_categories[] = $default;
}
} else {
$checked_categories[] = $default;
}
$cats = return_categories_list($parent, TRUE);
$result = array();
foreach($cats as $cat)
{
$result[$cat]['children'] = get_nested_categories($default, $cat);
$result[$cat]['cat_ID'] = $cat;
$result[$cat]['checked'] = in_array($cat, $checked_categories);
$result[$cat]['cat_name'] = get_the_category_by_ID($cat);
}
return $result;
}
示例3: wpml_link_to_element
function wpml_link_to_element($element_id, $element_type = 'post', $link_text = '', $optional_parameters = array(), $anchor = '', $echoit = true)
{
if (!function_exists('icl_link_to_element')) {
switch ($element_type) {
case 'post':
case 'page':
$ret = '<a href="' . get_permalink($element_id) . '">';
if ($anchor) {
$ret .= $anchor;
} else {
$ret .= get_the_title($element_id);
}
$ret .= '<a>';
break;
case 'tag':
case 'post_tag':
$tag = get_term_by('id', $element_id, 'tag', ARRAY_A);
$ret = '<a href="' . get_tag_link($element_id) . '">' . $tag->name . '</a>';
case 'category':
$ret = '<a href="' . get_tag_link($element_id) . '">' . get_the_category_by_ID($element_id) . '</a>';
default:
$ret = '';
}
if ($echoit) {
echo $ret;
} else {
return $ret;
}
} else {
return icl_link_to_element($element_id, $element_type, $link_text, $optional_parameters, $anchor, $echoit);
}
}
示例4: field_value
function field_value( $data ) {
if ( $data == -1 )
return false;
if ( is_numeric( $data ) )
return get_the_category_by_ID( intval( $data ) );
return $data;
}
示例5: the_category_head
function the_category_head($before='', $after='') {
global $currentcat, $previouscat;
// Grab the first cat in the list.
$categories = get_the_category();
$currentcat = $categories[0]->category_id;
if ( $currentcat != $previouscat ) {
echo $before;
echo get_the_category_by_ID($currentcat);
echo $after;
$previouscat = $currentcat;
}
}
示例6: column_default
/**
* column_default function.
*
* @access public
* @param mixed $item
* @param mixed $column_name
*/
function column_default($item, $column_name)
{
global $wpdb;
switch ($column_name) {
case 'text':
echo $item->text;
break;
case 's':
if ($item->s) {
echo $item->s;
} else {
echo 'Any';
}
break;
case 'category':
if ($item->category) {
$cat = get_the_category_by_ID($item->category);
echo $cat;
} else {
echo 'Any';
}
break;
case 'enabled':
if ($item->enabled) {
echo '<b style="color:green;">Enabled</b>';
} else {
echo '<b style="color:red;">Disabled</b>';
}
break;
case 'wc_actions':
?>
<?php
$actions = array();
$action_id = $item->id;
$actions['edit'] = array('url' => admin_url('admin.php?page=autoText&id=' . $item->id . '&action=edit'), 'name' => __('Edit', 'fastedit'), 'action' => "edit");
if (!$item->enabled) {
$actions['view'] = array('url' => admin_url('admin.php?page=autoText&id=' . $item->id . '&action=enable'), 'name' => __('Enable', 'fastedit'), 'action' => "enable");
} else {
$actions['view'] = array('url' => admin_url('admin.php?page=autoText&id=' . $item->id . '&action=disable'), 'name' => __('Disable', 'fastedit'), 'action' => "disable");
}
$actions['delete'] = array('url' => admin_url('admin.php?page=autoText&id=' . $item->id . '&action=delete'), 'name' => __('Delete', 'fastedit'), 'action' => "delete");
$actions = apply_filters('fastedit_admin_text_table_actions', $actions, $product);
foreach ($actions as $action) {
printf('<a class="button tips %s" href="%s" >%s</a>', $action['action'], esc_url($action['url']), esc_attr($action['name']), esc_attr($action['name']));
}
?>
<?php
break;
}
}
示例7: check_for_category_single_template
function check_for_category_single_template($t)
{
foreach ((array) get_the_category() as $cat) {
if (file_exists(TEMPLATEPATH . "/single-{$cat->slug}.php")) {
return TEMPLATEPATH . "/single-{$cat->slug}.php";
}
if ($cat->parent) {
$cat = get_the_category_by_ID($cat->parent);
if (file_exists(TEMPLATEPATH . "/single-{$cat->slug}.php")) {
return TEMPLATEPATH . "/single-{$cat->slug}.php";
}
}
}
return $t;
}
示例8: codeless_register_sidebars_init
function codeless_register_sidebars_init()
{
global $cl_redata;
register_sidebar(array('id' => 'sidebar-1', 'name' => __('Sidebar Blog', 'codeless'), 'before_widget' => '<div id="%1$s" class="widget %2$s">', 'after_widget' => '</div>', 'before_title' => '<h5 class="widget-title">', 'after_title' => '</h5>'));
register_sidebar(array('id' => 'sidebar-2', 'name' => __('Sidebar Pages', 'codeless'), 'before_widget' => '<div id="%1$s" class="widget %2$s">', 'after_widget' => '</div>', 'before_title' => '<h5 class="widget-title">', 'after_title' => '</h5>'));
register_sidebar(array('id' => 'sidebar-3', 'name' => __('Sidebar Portfolio', 'codeless'), 'before_widget' => '<div id="%1$s" class="widget %2$s">', 'after_widget' => '</div>', 'before_title' => '<h5 class="widget-title">', 'after_title' => '</h5>'));
register_sidebar(array('id' => 'sidebar-4', 'name' => __('Top Header Left', 'codeless'), 'before_widget' => '<div id="%1$s" class="widget %2$s">', 'after_widget' => '</div>', 'before_title' => '', 'after_title' => ''));
register_sidebar(array('id' => 'sidebar-5', 'name' => __('Top Header Right', 'codeless'), 'before_widget' => '<div id="%1$s" class="widget %2$s">', 'after_widget' => '</div>', 'before_title' => '', 'after_title' => ''));
if (isset($cl_redata['footer_columns'])) {
$footer_columns = $cl_redata['footer_columns'];
for ($i = 1; $i <= $footer_columns; $i++) {
register_sidebar(array('name' => 'Footer - column' . $i, 'id' => 'footer-column-' . $i, 'before_widget' => '<div id="%1$s" class="widget %2$s">', 'after_widget' => '</div>', 'before_title' => '<h5 class="widget-title">', 'after_title' => '</h5>'));
}
}
register_sidebar(array('id' => 'sidebar-7', 'name' => __('Copyright Footer Sidebar', 'codeless'), 'before_widget' => '<div id="%1$s" class="widget %2$s">', 'after_widget' => '</div>', 'before_title' => '', 'after_title' => ''));
if (isset($cl_redata['pages_sidebar'])) {
$id_array = $cl_redata['pages_sidebar'];
if (isset($id_array[0])) {
foreach ($id_array as $page_id) {
if ($page_id != "") {
register_sidebar(array('id' => 'page-' . get_the_title($page_id), 'name' => __('Page', 'codeless') . ': ' . get_the_title($page_id) . '', 'before_widget' => '<div id="%1$s" class="widget %2$s">', 'after_widget' => '</div>', 'before_title' => '<h6 class="widget-title">', 'after_title' => '</h6>'));
}
}
}
}
if (isset($cl_redata['categories_sidebar'])) {
$id_array = $cl_redata['categories_sidebar'];
if (isset($id_array[0])) {
foreach ($id_array as $cat_id) {
if ($cat_id != "") {
register_sidebar(array('id' => 'category-' . get_the_category_by_ID($cat_id), 'name' => __('Category', 'codeless') . ': ' . get_the_category_by_ID($cat_id) . '', 'before_widget' => '<div id="%1$s" class="widget %2$s">', 'after_widget' => '</div>', 'before_title' => '<h6 class="widget-title">', 'after_title' => '</h6>'));
}
}
}
}
if (isset($cl_redata['extra_navigation']) && $cl_redata['extra_navigation']) {
register_sidebar(array('id' => 'sidebar-10', 'name' => __('Extra Side Navigation', 'codeless'), 'before_widget' => '<div id="%1$s" class="widget %2$s">', 'after_widget' => '</div>', 'before_title' => '<h5 class="widget-title">', 'after_title' => '</h5>'));
}
if (class_exists('Woocommerce')) {
register_sidebar(array('id' => 'sidebar-11', 'name' => __('Sidebar Woocommerce', 'codeless'), 'before_widget' => '<div id="%1$s" class="widget %2$s">', 'after_widget' => '</div>', 'before_title' => '<h5 class="widget-title">', 'after_title' => '</h5>'));
}
if (isset($cl_redata['header_style']) && ($cl_redata['header_style'] == 'header_6' || $cl_redata['header_style'] == 'header_7' || $cl_redata['header_style'] == 'header_12')) {
register_sidebar(array('id' => 'sidebar-12', 'name' => __('Header Widgetized Area', 'codeless'), 'before_widget' => '<div id="%1$s" class="widget %2$s">', 'after_widget' => '</div>', 'before_title' => '<h5 class="widget-title">', 'after_title' => '</h5>'));
}
if (isset($cl_redata['header_style']) && $cl_redata['header_style'] == 'header_12') {
register_sidebar(array('id' => 'sidebar-13', 'name' => __('After Navigation Area', 'codeless'), 'before_widget' => '<div id="%1$s" class="widget %2$s">', 'after_widget' => '</div>', 'before_title' => '<h5 class="widget-title">', 'after_title' => '</h5>'));
}
}
示例9: b2_newpost
/**
* b2.newPost. Adds a post, blogger-api like, +title +category +postdate.
*
* b2 API
*
* @param xmlrpcmsg XML-RPC Message
* 0 ?
* 1 ?
* 2 username (string): Login for a Blogger user who is member of the blog.
* 3 password (string): Password for said username.
* 4 content (string): The content of the post.
* 5 publish (boolean): If set to true, the post will be published immediately.
* 6 title (string): The title of the post.
* 7 category (string): The internal name of the category you want to post the post into.
* 8 date (string): This is the date that will be shown in the post, give "" for current date.
* @return xmlrpcresp XML-RPC Response
*/
function b2_newpost($m)
{
global $xmlrpcerruser;
// import user errcode value
global $DB;
global $Settings, $Messages;
// CHECK LOGIN:
/**
* @var User
*/
if (!($current_User =& xmlrpcs_login($m, 2, 3))) {
// Login failed, return (last) error:
return xmlrpcs_resperror();
}
$publish = $m->getParam(5);
$publish = $publish->scalarval();
$status = $publish ? 'published' : 'draft';
$main_cat = $m->getParam(7);
$main_cat = $main_cat->scalarval();
// CHECK PERMISSION: (we need perm on all categories, especially if they are in different blogs)
if (!$current_User->check_perm('cats_post!' . $status, 'edit', false, array($main_cat))) {
// Permission denied
return xmlrpcs_resperror(3);
// User error 3
}
logIO('Permission granted.');
// Check if category exists
if (get_the_category_by_ID($main_cat, false) === false) {
// Cat does not exist:
return xmlrpcs_resperror(11);
// User error 11
}
$cat_IDs = array($main_cat);
$postdate = $m->getParam(8);
$postdate = $postdate->scalarval();
if ($postdate != '') {
$post_date = $postdate;
} else {
$post_date = date('Y-m-d H:i:s', time() + $Settings->get('time_difference'));
}
$post_title = $m->getParam(6);
$post_title = $post_title->scalarval();
$content = $m->getParam(4);
$content = $content->scalarval();
// COMPLETE VALIDATION & INSERT:
return xmlrpcs_new_item($post_title, $content, $post_date, $main_cat, $cat_IDs, $status);
}
示例10: _single_cat_title
function _single_cat_title($prefix = '', $display = true)
{
$cat = intval(get_query_var('cat'));
if (!empty($cat) && !(strtoupper($cat) == 'ALL')) {
$my_cat_name = apply_filters('single_cat_title', get_the_category_by_ID($cat));
if (!empty($my_cat_name)) {
if ($display) {
echo '<h3>' . $prefix . strip_tags($my_cat_name) . '</h3>';
} else {
return strip_tags($my_cat_name);
}
if ($index_filename == 'index-wap.php') {
echo '<br/>';
}
}
}
}
示例11: get_rows_data
public function get_rows_data()
{
$search_value = isset($_POST['search_value']) ? esc_html(stripslashes($_POST['search_value'])) : '';
$category_id = isset($_POST['category_id']) && esc_html(stripslashes($_POST['category_id'])) != -1 ? esc_html(stripslashes($_POST['category_id'])) : '';
$category_name = $category_id ? get_the_category_by_ID($category_id) : '';
$asc_or_desc = isset($_POST['asc_or_desc']) ? esc_html(stripslashes($_POST['asc_or_desc'])) : 'ASC';
$order_by = isset($_POST['order_by']) ? esc_html(stripslashes($_POST['order_by'])) : 'date';
if (isset($_POST['page_number']) && $_POST['page_number']) {
$limit = ((int) $_POST['page_number'] - 1) * 20;
} else {
$limit = 0;
}
$page_limit = (int) ($limit / 20 + 1);
$args = array('posts_per_page' => 255, 'category_name' => $category_name, 'orderby' => $order_by, 'order' => $asc_or_desc, 'post_status' => 'publish');
$posts = get_posts($args);
$row = array();
$counter = 0;
for ($i = 0; $i < count($posts); $i++) {
$post = $posts[$i];
if (has_post_thumbnail($post->ID) && (!$search_value || stristr($post->post_title, $search_value) !== FALSE)) {
$counter++;
if ($counter > $limit && $counter <= $limit + 20) {
$row[$post->ID] = new stdClass();
$row[$post->ID]->id = $post->ID;
$image_url = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'full');
$row[$post->ID]->image_url = $image_url[0];
$thumb_url = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'thumbnail');
$row[$post->ID]->thumb_url = $thumb_url[0] ? $thumb_url[0] : $image_url[0];
$row[$post->ID]->title = $post->post_title;
$row[$post->ID]->date = $post->post_date;
$row[$post->ID]->modified = $post->post_modified;
$row[$post->ID]->type = $post->post_type;
$row[$post->ID]->author = get_the_author_meta('display_name', $post->post_author);
$row[$post->ID]->link = get_permalink($post->ID);
$row[$post->ID]->content = $this->add_more_link(strip_tags($post->post_content), $row[$post->ID]->link, 250);
}
}
}
return array($row, $counter, $page_limit);
}
示例12: the_category_head
function the_category_head($before = '', $after = '')
{
global $post, $currentcat, $previouscat, $dateformat, $newday;
$currentcat = $post->post_category;
if ($currentcat != $previouscat) {
echo $before;
echo get_the_category_by_ID($currentcat);
echo $after;
$previouscat = $currentcat;
}
}
示例13: foreach
?>
,
<?php
}
} else {
echo "Not Avail.";
}
?>
</p>
<p> <strong>Student/Alum of: </strong>
<?php
if (get_post_meta(get_the_ID(), 'Institute Name', true)) {
foreach (explode(",", get_post_meta(get_the_ID(), 'Institute Name', true)) as $inst) {
?>
<?php
echo get_the_category_by_ID($inst);
?>
,
<?php
}
} else {
echo "Not Avail.";
}
?>
</p>
<strong>One Line Pitch: </strong> <?php
if (get_post_meta(get_the_ID(), 'One line pitch', true)) {
echo get_post_meta(get_the_ID(), 'One line pitch', true);
} else {
echo "Not Avail.";
}
示例14: get_nested_categories
function get_nested_categories($default = 0, $parent = 0)
{
global $post_ID, $mode, $wpdb;
if ($post_ID) {
$checked_categories = $wpdb->get_col("\n\t\t SELECT category_id\n\t\t FROM {$wpdb->categories}, {$wpdb->post2cat}\n\t\t WHERE {$wpdb->post2cat}.category_id = cat_ID AND {$wpdb->post2cat}.post_id = '{$post_ID}'\n\t\t ");
if (count($checked_categories) == 0) {
// No selected categories, strange
$checked_categories[] = $default;
}
} else {
$checked_categories[] = $default;
}
$cats = return_categories_list($parent);
$result = array();
if (is_array($cats)) {
foreach ($cats as $cat) {
$result[$cat]['children'] = get_nested_categories($default, $cat);
$result[$cat]['cat_ID'] = $cat;
$result[$cat]['checked'] = in_array($cat, $checked_categories);
$result[$cat]['cat_name'] = get_the_category_by_ID($cat);
}
}
usort($result, 'sort_cats');
return $result;
}
示例15: the_permalink
<!-- **portfolio-detail - Starts** -->
<div class="portfolio-detail" onclick="window.location.href = '<?php
echo the_permalink();
?>
?id=post_details'">
<div class="views">
<h5 class="prname"><a href="<?php
echo the_permalink();
?>
"><?php
echo get_the_category_by_ID(get_post_meta(get_the_ID(), 'Alumni of Institute', true));
?>
</a></h5>
<span>City of Location: <?php
echo get_the_category_by_ID(get_post_meta(get_the_ID(), 'City Of location', true));
?>
</span>
</div>
<!-- <div class="portfolio-title">
<p><strong>Position at Institute: </strong><br>
<?php
// get_the_category_by_ID(get_post_meta(get_the_ID(), 'Position', true));
?>
</p>
</div>-->