本文整理汇总了PHP中wp_get_post_tags函数的典型用法代码示例。如果您正苦于以下问题:PHP wp_get_post_tags函数的具体用法?PHP wp_get_post_tags怎么用?PHP wp_get_post_tags使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wp_get_post_tags函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: widget
function widget($args, $instance)
{
/* PRINT THE WIDGET */
extract($args, EXTR_SKIP);
$title = !empty($instance['title']) ? $instance['title'] : '';
if (is_singular('post') && has_tag()) {
global $post;
echo $before_widget;
if (!empty($title)) {
echo $before_title;
echo $title;
echo $after_title;
}
echo '<div class="tagcloud">';
$tags = wp_get_post_tags($post->ID);
foreach ($tags as $t => $tag) {
echo '<a href="' . get_tag_link($tag->term_id) . '" title="' . $tag->count . ' topic">';
echo $tag->name;
echo '</a>';
}
echo '<div class="clear"></div>';
echo '</div>';
echo $after_widget;
}
}
示例2: check_for_tag_update
function check_for_tag_update($post_data, $post_array)
{
if (!empty($post_array['ID'])) {
$post_id = $post_array['ID'];
$post = new TimberPost($post_id);
if ($this->check($post)) {
return $post_data;
}
$tags = wp_get_post_tags($post->id);
$old_tag_id = $new_tag_id = false;
if (isset($tags[0]->term_id)) {
$old_tag_id = $tags[0]->term_id;
}
if (isset($post_array['tax_input']['post_tag'][0])) {
$new_tag_id = $post_array['tax_input']['post_tag'][0];
}
if ($old_tag_id === $new_tag_id) {
return $post_data;
}
if ($old_tag_id === false && $new_tag_id) {
$this->add_post_to_edition($post, $new_tag_id);
return $post_data;
}
if ($old_tag_id && $new_tag_id === false) {
$this->remove_post_from_edition($post, $old_tag_id);
return $post_data;
}
if ($old_tag_id !== $new_tag_id) {
$this->remove_post_from_edition($post, $old_tag_id);
$this->add_post_to_edition($post, $new_tag_id);
return $post_data;
}
}
return $post_data;
}
示例3: 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;
});
}
示例4: related_post
public static function related_post()
{
//for use in the loop, list 5 post titles related to first tag on current post
global $post;
$tags = wp_get_post_tags($post->ID);
if ($tags) {
echo 'Related Posts';
$first_tag = $tags[0]->term_id;
$args = array('tag__in' => array($first_tag), 'post__not_in' => array($post->ID), 'showposts' => 5, 'caller_get_posts' => 1);
$my_query = new WP_Query($args);
if ($my_query->have_posts()) {
while ($my_query->have_posts()) {
$my_query->the_post();
?>
<p><a href="<?php
the_permalink();
?>
" rel="bookmark" title="Permanent Link to <?php
the_title_attribute();
?>
"><?php
the_title();
?>
</a></p>
<?php
}
}
}
}
示例5: wp_fetch_related_posts
function wp_fetch_related_posts($limitclause="") {
global $wpdb, $post;
$wp_rp = get_option("wp_rp");
if(!$post->ID){return;}
$now = current_time('mysql', 1);
$tags = wp_get_post_tags($post->ID);
$tagcount = count($tags);
$taglist = false;
if ($tagcount > 0) {
$taglist = "'" . $tags[0]->term_id. "'";
for ($i = 1; $i < $tagcount; $i++) {
$taglist = $taglist . ", '" . $tags[$i]->term_id . "'";
}
}
$related_posts = false;
if ($taglist) {
$q = "SELECT p.ID, p.post_title, p.post_content,p.post_excerpt, p.post_date, p.comment_count, count(t_r.object_id) as cnt FROM $wpdb->term_taxonomy t_t, $wpdb->term_relationships t_r, $wpdb->posts p WHERE t_t.taxonomy ='post_tag' AND t_t.term_taxonomy_id = t_r.term_taxonomy_id AND t_r.object_id = p.ID AND (t_t.term_id IN ($taglist)) AND p.ID != $post->ID AND p.post_status = 'publish' AND p.post_date_gmt < '$now' GROUP BY t_r.object_id ORDER BY cnt DESC, p.post_date_gmt DESC $limitclause;";
$related_posts = $wpdb->get_results($q);
}
return $related_posts;
}
示例6: _getPostTop
private function _getPostTop($category)
{
if (empty($category)) {
$this->_trough404('_getPostTop: No category set');
}
require $this->wp;
$cid = get_cat_ID($category);
if ($cid) {
$wp_posts = get_posts(array('category' => get_cat_ID($category)));
foreach ($wp_posts as $wp_post) {
$id = $wp_post->ID;
$tags = wp_get_post_tags($wp_post->ID);
foreach ($tags as $tag) {
if ($tag->name == 'top') {
return $id;
}
}
}
if (!empty($id)) {
return $id;
}
// Backup, random one
}
$this->_trough404('_getPostTop: No category found');
}
示例7: post_meta
function post_meta()
{
?>
<ul class="post_meta">
<li class="date"><?php
echo get_the_date();
?>
</li>
<li class="category"><?php
the_category(', ');
?>
</li>
<?php
$post_tags = wp_get_post_tags($post->ID);
if (!empty($post_tags)) {
?>
<li class="tags"><?php
the_tags('', ', ', '');
?>
</li>
<?php
}
?>
</ul><!-- .post-meta -->
<?php
}
示例8: widget
function widget($args, $instance)
{
/* PRINT THE WIDGET */
extract($args, EXTR_SKIP);
$instance = wp_parse_args((array) $instance, array('title' => null));
$title = esc_attr($instance['title']);
if (is_singular('post') && has_tag()) {
global $post;
echo $before_widget;
if (!empty($title)) {
echo $before_title;
echo apply_filters('widget_title', $title, $instance, $this->id_base);
echo $after_title;
}
echo '<div class="tagcloud">';
$tags = wp_get_post_tags($post->ID);
foreach ($tags as $t => $tag) {
echo '<a href="' . get_tag_link($tag->term_id) . '" title="' . $tag->count . ' topic">';
echo $tag->name;
echo '</a>';
}
echo '<div class="clear"></div>';
echo '</div>';
echo $after_widget;
}
}
示例9: joints_related_posts
function joints_related_posts()
{
global $post;
$tags = wp_get_post_tags($post->ID);
if ($tags) {
foreach ($tags as $tag) {
$tag_arr .= $tag->slug . ',';
}
$args = array('tag' => $tag_arr, 'numberposts' => 3, 'post__not_in' => array($post->ID));
$related_posts = get_posts($args);
if ($related_posts) {
echo '<section class="fs-cell fs-all-full section section-compact"><h4 class="title"><span>Related Posts</span></h4></section>';
//echo '<ul id="joints-related-posts">';
foreach ($related_posts as $post) {
setup_postdata($post);
?>
<?php
get_template_part('entry');
?>
<?php
}
}
}
wp_reset_postdata();
//echo '</ul>';
}
示例10: blocks_get_gallery
function blocks_get_gallery($post_id)
{
$ret = array('tags' => array(), 'images' => array());
$gallery = get_post_gallery($post_id, false);
$gallery_ids = $gallery ? explode(',', $gallery['ids']) : array();
foreach ($gallery_ids as $id) {
$thumb = wp_get_attachment_image_src($id, 'medium');
$image = wp_get_attachment_image_src($id, 'large');
if ($thumb && $image) {
$image_data = array('tags' => array(), 'tags_string' => '');
$image_data['thumbnail'] = $thumb;
$image_data['image'] = $image;
$image_data['tags'] = wp_get_post_tags($id);
foreach ($image_data['tags'] as $tag) {
$ret['tags'][$tag->slug] = $tag->name;
$image_data['tags_string'] .= ' ' . $tag->slug;
}
$data = wp_prepare_attachment_for_js($id);
$image_data['title'] = $data['title'];
$image_data['caption'] = $data['caption'];
$image_data['alt'] = $data['alt'];
$image_data['description'] = $data['description'];
$image_data['link'] = get_post_meta($id, "_blocks_link", true);
$ret['images'][] = $image_data;
}
}
asort($ret['tags']);
return $ret;
}
示例11: 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
示例12: my_rss_related
/**
* Get related posts.
*/
function my_rss_related()
{
global $post;
// Setup post data
$pid = $post->ID;
$tags = wp_get_post_tags($pid);
$tag_ids = array();
// Loop through post tags
foreach ($tags as $individual_tag) {
$tag_ids[] = $individual_tag->term_id;
}
// Execute WP_Query
$related_by_tag = new WP_Query(array('tag__in' => $tag_ids, 'post__not_in' => array($pid), 'posts_per_page' => 10));
// Loop through posts and build HTML
if ($related_by_tag->have_posts()) {
echo 'Related:<br />';
while ($related_by_tag->have_posts()) {
$related_by_tag->the_post();
echo '<a href="' . get_permalink() . '">' . get_the_title() . '</a><br />';
}
} else {
echo '';
}
wp_reset_postdata();
}
示例13: _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>';
}
示例14: rp_get_related_posts
function rp_get_related_posts($post, $limit)
{
global $wpdb;
// wordpress database access
// limit has to be a number
$limit = (int) $limit;
// get tags of the post
$tags = wp_get_post_tags($post->ID);
if (is_wp_error($tags)) {
return false;
}
// error
if (count($tags) <= 0) {
// we cannot get related posts without tags
return array();
}
// no related posts
// get term ids
$termids = array();
foreach ($tags as $tag) {
$termids[$tag->term_id] = $tag->term_id;
}
if (count($termids) <= 0) {
// we cannot get related posts without the termids
return array();
}
// no related posts
// the query to get the related posts
$query = "SELECT DISTINCT {$wpdb->posts}.*, COUNT( tr.object_id) AS cnt " . "FROM {$wpdb->term_taxonomy} tt, {$wpdb->term_relationships} tr, {$wpdb->posts} " . "WHERE 1 " . "AND tt.taxonomy = 'post_tag' " . "AND tt.term_taxonomy_id = tr.term_taxonomy_id " . "AND tr.object_id = {$wpdb->posts}.ID " . "AND tt.term_id IN( " . implode(',', $termids) . " ) " . "AND {$wpdb->posts}.ID != {$post->ID} " . "AND {$wpdb->posts}.post_status = 'publish' " . "GROUP BY tr.object_id " . "ORDER BY cnt DESC, {$wpdb->posts}.post_date_gmt DESC " . "LIMIT {$limit} ";
// get only the top x
// run the query and return the result
return $wpdb->get_results($query);
}
示例15: get_post
function get_post()
{
check_ajax_referer('ajaxnonce', '_inline_edit');
if (!is_user_logged_in()) {
die('<p>' . __('Error: not logged in.', 'p2') . '</p>');
}
$post_id = $_GET['post_ID'];
$post_id = substr($post_id, strpos($post_id, '-') + 1);
if (!current_user_can('edit_post', $post_id)) {
die('<p>' . __('Error: not allowed to edit post.', 'p2') . '</p>');
}
$post = get_post($post_id);
function get_tag_name($tag)
{
return $tag->name;
}
$tags = array_map('get_tag_name', wp_get_post_tags($post_id));
$categories = get_the_category($post_id);
$category_slug = isset($categories[0]) ? $categories[0]->slug : '';
// handle page as post_type
if ('page' == $post->post_type) {
$category_slug = 'page';
$tags = '';
}
echo json_encode(array('title' => $post->post_title, 'content' => $post->post_content, 'type' => $category_slug, 'tags' => $tags));
}