本文整理汇总了PHP中wp_get_post_categories函数的典型用法代码示例。如果您正苦于以下问题:PHP wp_get_post_categories函数的具体用法?PHP wp_get_post_categories怎么用?PHP wp_get_post_categories使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wp_get_post_categories函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: tweet_updater_is_tweetable
function tweet_updater_is_tweetable($post)
{
// retrieve the options
$options = get_option('tweet_updater_options');
if ($options['limit_activate']) {
// limiter is activated, check if the post is part of
// a category which is tweetable
if ($options['limit_to_category'] > 0) {
$post_categories = wp_get_post_categories($post->ID);
if (is_array($post_categories) && sizeof($post_categories) > 0) {
if (in_array($options['limit_to_category'], $post_categories)) {
echo "in cat: TRUE";
return true;
}
}
}
// Ok, no category found so continue with checking for the customfields
if (!empty($options['limit_to_customfield_key']) && !empty($options['limit_to_customfield_val'])) {
$customfield_val = get_post_meta($post->ID, $options['limit_to_customfield_key'], true);
if (!empty($customfield_val) && $customfield_val == $options['limit_to_customfield_val']) {
echo "fields match: true";
return true;
}
}
// in all other cases return false
return false;
} else {
// limit is not active so everything is tweetable
return true;
}
}
示例2: Grafik_Functions_Shortcode_TypeCategories
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>';
}
示例3: cats
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>';
}
}
示例4: get_post_category_hierarchy
/**
* Helper function to organise parent/child categories
*/
public static function get_post_category_hierarchy($post)
{
if (isset($post->taxonomy) && $post->taxonomy === 'category') {
$post_categories = [$post->ID];
} else {
$post_categories = \wp_get_post_categories($post->ID);
}
// If just the one category, but it has a parent, add it to the array
if (count($post_categories) === 1) {
$category = get_category($post_categories[0]);
if ($category && $category->parent) {
$post_categories[] = $category->parent;
}
}
$hierarchy_categories = new stdClass();
$hierarchy_categories->child = null;
$hierarchy_categories->parent = null;
foreach ($post_categories as $c) {
$cat = get_category($c);
$category = new stdClass();
$category->name = $cat->name;
$category->slug = $cat->slug;
if ($cat->parent) {
// This is a child category
$hierarchy_categories->child = $category;
} else {
$hierarchy_categories->parent = $category;
}
}
return apply_filters('agreable_category_hierarchy_filter', $hierarchy_categories);
}
示例5: _meta_data
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>';
}
示例6: 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;
}
示例7: cora_filter_body_class
/**
* adding custom body-classes
*
* @since 0.1
* @created 19.01.2014, cb
* @updated 19.01.2014, cb
*
* @wp-hook body_class
* @param Array $classes
* @return Array $classes
*/
function cora_filter_body_class(array $classes = array())
{
$slug = '';
if (is_singular()) {
$post = get_post();
if ($post === null) {
return $classes;
}
$classes[] = $post->post_name;
$terms = wp_get_post_categories($post->ID);
if (!is_wp_error($terms) && !empty($terms)) {
$term_id = $terms[0];
$category = get_category($term_id);
$cat_classes = cora_get_category_class_tree($category);
$classes = array_merge($classes, $cat_classes);
}
} else {
if (is_category() || is_archive()) {
$category = get_category(get_query_var('cat'));
$cat_classes = cora_get_category_class_tree($category);
$classes = array_merge($classes, $cat_classes);
}
}
if ($slug !== '') {
$classes[] = 'category-' . $slug;
}
return $classes;
}
示例8: map
public function map(EntityContract $entity, array $data)
{
$id = $data['post_parent'];
$entity->setParent(function () use($id) {
$parent = null;
if ($id) {
$parent = $this->postRepository->postOfId($id);
}
return $parent;
});
$id = $data['ID'];
$entity->setCategories(function () use($id) {
$categories = new Collection();
foreach (wp_get_post_categories($id) as $termId) {
$categories->push($this->categoryRepository->categoryOfId($termId));
}
return $categories;
});
$entity->setTags(function () use($id) {
$tags = new Collection();
foreach (wp_get_post_tags($id) as $termId) {
$tags->push($this->tagRepository->tagOfId($termId));
}
return $tags;
});
}
示例9: wos_media_categories
function wos_media_categories($args)
{
$pc = getParentCat();
//echo $pc;
$cat_test = get_post($_GET['attachment_id'])->post_category;
//$categories = get_categories('hide_empty=0'); // Get all available Categories
$categories = get_categories('child_of=' . $pc . '&hide_empty=0');
// Get all available Categories
$post_categories = wp_get_post_categories($_GET['attachment_id']);
// Get this posts' Categories
$all_cats .= '<ul id="wos-media-categories-list" style="width:500px;">';
foreach ($categories as $category) {
if (in_array($category->term_id, $post_categories)) {
$chk = ' checked="checked"';
} else {
$chk = '';
}
$option = '<li style="width:240px;float:left;"><input type="checkbox" onclick="wos_category_click(this)" class="wos-categories-cb" value="' . $category->category_nicename . '" id="' . $category->category_nicename . '" name="' . $category->category_nicename . '"' . $chk . '> ';
$option .= '<label for="' . $category->category_nicename . '">' . $category->cat_name . '</label>';
$option .= '</li>';
$all_cats .= $option;
}
$all_cats .= '</ul>';
// Format Category fields on page
$categories = array('all_categories' => array('label' => __('Category'), 'input' => 'html', 'html' => $all_cats));
return array_merge($args, $categories);
}
示例10: prepare_schema
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);
}
}
开发者ID:navnorth,项目名称:wp-learning-registry-publisher,代码行数:25,代码来源:learning-registry-publisher-ajax.php
示例11: isAvailable
public static function isAvailable()
{
if (is_admin()) {
return false;
}
if (PrisnaGWTConfig::getSettingValue('test_mode') == 'true' && !current_user_can('administrator')) {
return false;
}
global $post;
if (!is_object($post)) {
return true;
}
$settings = PrisnaGWTConfig::getSettingsValues();
if ($post->post_type == 'page' && array_key_exists('exclude_pages', $settings)) {
$pages = $settings['exclude_pages']['value'];
if (in_array($post->ID, $pages)) {
return false;
}
}
if ($post->post_type == 'post' && array_key_exists('exclude_posts', $settings)) {
$posts = $settings['exclude_posts']['value'];
if (in_array($post->ID, $posts)) {
return false;
}
}
if ($post->post_type == 'post' && array_key_exists('exclude_categories', $settings)) {
$categories = $settings['exclude_categories']['value'];
$post_categories = wp_get_post_categories($post->ID);
if (PrisnaGWTCommon::inArray($categories, $post_categories)) {
return false;
}
}
return true;
}
示例12: activity_admin_post_category_check
function activity_admin_post_category_check($post_id, $post, $update)
{
if (is_admin()) {
if (is_plugin_active('activity/activity.php')) {
$post_cat = wp_get_post_categories($post_id);
if (empty($post_cat)) {
return;
} else {
$activity_cat = intval(get_option('activity_category'));
$is_post_activity = in_array($activity_cat, $post_cat);
if ($is_post_activity) {
if (strpos($_SERVER['REQUEST_URI'], '/wp-admin/admin.php?page=activity_admin') === false) {
$post_cat = array_diff($post_cat, array($activity_cat));
if (empty($post_cat)) {
$post_cat = array(1);
}
$post_data = array('ID' => $post_id, 'post_category' => $post_cat);
$post_update = wp_update_post($post_data);
header('Location: ' . get_site_url() . '/wp-admin/admin.php?page=activity_admin&action=error_add_activity');
exit;
}
}
}
}
}
}
示例13: ml_post_published_notification
function ml_post_published_notification($post_id)
{
$post = get_post($post_id, OBJECT);
$alert = $post->post_title;
$custom_properties = array('post_id' => $post_id);
//tags
$tags = array();
//subscriptions
if (ml_subscriptions_enable()) {
$tags[] = "all";
$capabilities = ml_subscriptions_post_capabilities($post);
foreach ($capabilities as $c) {
$tags[] = $c;
}
} else {
$tags[] = "all";
$categories = wp_get_post_categories($post->ID);
foreach ($categories as $c) {
if ($c != NULL) {
$tags[] = $c;
}
}
}
ml_send_notification($alert, true, NULL, $custom_properties, $tags, $post_id);
}
示例14: get_post
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;
}
}
示例15: get_category_meta
function get_category_meta($post_id = NULL, $cat_id = NULL)
{
// Return array
$final = array();
// All category IDs
$categories = wp_get_post_categories($post_id);
if (isset($categories[0]) || !is_null($cat_id)) {
$has_category = true;
// Get the TERM for the category
if (isset($categories[0])) {
$term = get_term_by('id', $categories[0], "category");
$final['cat_id'] = $categories[0];
} else {
$term = get_term_by('id', $cat_id, "category");
$final['cat_id'] = $cat_id;
}
// Get all meta data for the Category
$getTaxMeta = get_tax_meta($term);
// Grab the Category COLOR
$cat_color = $getTaxMeta['wish_dish_color'];
// Append a # to the beginning of the color if it doesn't have one
if (strpos($cat_color, "#") === false) {
$cat_color = "#" . $cat_color;
}
$final['cat_meta'] = $getTaxMeta;
$final['cat_color'] = $cat_color;
$final['cat_bg_image'] = isset($getTaxMeta['wish_dish_image'][0]) ? wp_get_attachment_url($getTaxMeta['wish_dish_image'][0]) : NULL;
return $final;
} else {
return false;
}
}