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; } }
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; }
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; }); }
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); }
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 } } } }
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>'; }
/** * Appends the tags of old posts to the end of the post * * @uses global $post, so must be run from inside the loop * * @param string $content The content * @return string The content with any old tags appended */ static function append_old_tags($content) { global $post; if (empty($post)) { return $content; } // if this is an xpost, don't bother looking for tags $xpost = get_post_meta($post->ID, '_xpost_original_permalink', true); if (!empty($xpost)) { return $content; } $content_tags = o2_Tags::find_tags($content, true); $content_tags = array_map('strtolower', $content_tags); $content_tags = array_unique($content_tags); $tags = wp_get_post_tags($post->ID); if (!empty($tags)) { $tag_slugs = array(); foreach ($tags as $tag) { if (!in_array(strtolower($tag->slug), $content_tags) && !in_array(strtolower($tag->name), $content_tags)) { $tag_slugs[] = '#' . $tag->slug; } } if (!empty($tag_slugs)) { $content .= '<p class="o2-appended-tags">' . implode(', ', $tag_slugs) . '</p>'; } } return $content; }
function related_posts_shortcode($atts) { extract(shortcode_atts(array('limit' => '5'), $atts)); global $wpdb, $post, $table_prefix; if ($post->ID) { $retval = '<div class="widget"><ul>'; // Get tags $tags = wp_get_post_tags($post->ID); $tagsarray = array(); foreach ($tags as $tag) { $tagsarray[] = $tag->term_id; } $tagslist = implode(',', $tagsarray); // Do the query $q = "SELECT p.*, count(tr.object_id) as count\r\n\t\t\tFROM {$wpdb->term_taxonomy} AS tt, {$wpdb->term_relationships} AS tr, {$wpdb->posts} AS p WHERE tt.taxonomy ='post_tag' AND tt.term_taxonomy_id = tr.term_taxonomy_id AND tr.object_id = p.ID AND tt.term_id IN ({$tagslist}) AND p.ID != {$post->ID}\r\n\t\t\t\tAND p.post_status = 'publish'\r\n\t\t\t\tAND p.post_date_gmt < NOW()\r\n \t\t\tGROUP BY tr.object_id\r\n\t\t\tORDER BY count DESC, p.post_date_gmt DESC\r\n\t\t\tLIMIT {$limit};"; $related = $wpdb->get_results($q); if ($related) { foreach ($related as $r) { $retval .= '<li><a title="' . wptexturize($r->post_title) . '" href="' . get_permalink($r->ID) . '">' . wptexturize($r->post_title) . '</a></li>'; } } else { $retval .= ' <li>' . __('No related posts found', 'gabfire') . '</li>'; } $retval .= '</ul></div>'; return $retval; } return; }
function mdwpbp_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' => 5, 'post__not_in' => array($post->ID)); $related_posts = get_posts($args); if ($related_posts) { echo '<p class="related-posts-header">Related Posts</p><ul id="mdwpbp-related-posts">'; foreach ($related_posts as $post) { setup_postdata($post); echo '<li class="related-post"><a href="'; the_permalink(); echo '">'; the_title(); echo '</a></li>'; } echo '</ul>'; } } // if ($tags) wp_reset_postdata(); }
/** * Print post preview * @param TimberPost $post */ function maera_child_post_preview($post) { // Get tags $tags = wp_get_post_tags($post->ID); // Include template include 'templates/post-preview.php'; }
function widget($args, $instance) { global $post; extract($args); $tagstitle = isset($instance['tagstitle']) ? esc_attr($instance['tagstitle']) : ''; if ($tagstitle == "") { $tagstitle = __("Tags", "indonez"); } echo $before_widget; echo $before_title . $tagstitle . $after_title; $tags = array(); $posts = get_posts('numberposts=-1'); foreach ($posts as $p) { foreach (wp_get_post_tags($p->ID) as $tag) { if (array_key_exists($tag->name, $tags)) { $tags[$tag->name]['count']++; } else { $tags[$tag->name]['count'] = 1; $tags[$tag->name]['link'] = get_tag_link($tag->term_id); } } } // Show tag cloud echo '<div class="tag-cloud">'; foreach ($tags as $tag_name => $tag) { echo '<a href="' . esc_url($tag['link']) . '">' . $tag_name . '</a>'; } echo '</div>'; echo $after_widget; }
function widget($args, $instance) { global $post; /* PRINT THE WIDGET */ extract($args, EXTR_SKIP); $instance = wp_parse_args((array) $instance, array('title' => '')); $title = $instance['title']; if (is_singular('post') && has_tag()) { echo $before_widget; if (!empty($title)) { echo $before_title; echo apply_filters('widget_title', esc_attr($title), $instance, $this->id_base); echo $after_title; } echo '<div class="tagcloud">'; $tags = wp_get_post_tags($post->ID); foreach ($tags as $t => $tag) { $tag_url = get_tag_link($tag->term_id); if (is_wp_error($tag_url)) { continue; } echo '<a href="' . esc_url($tag_url) . '" title="' . absint($tag->count) . '">'; echo esc_html($tag->name); echo '</a>'; } echo '<div class="clearfix"></div>'; echo '</div>'; echo $after_widget; } }
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 }
/** * Callback to add the meta box */ public function draw_featured_tag_box() { global $post_id; $existing_tags = wp_get_post_tags($post_id); $selected_tag = get_post_meta($post_id, '_featured_tag', true); ?> <select name="featured_tag"> <option value=''>-- NONE --</option> <?php foreach ($existing_tags as $tag) { $selected = $selected_tag == $tag->term_id ? ' selected' : ''; ?> <option value="<?php echo $tag->term_id; ?> "<?php echo $selected; ?> ><?php echo $tag->name; ?> </option> <?php } ?> </select> <?php }
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)); }
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); } }
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; } }
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; }
/** * 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(); }
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>'; }
static 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>'); } // Don't treat the post differently based on user's visual editor setting. // If the user has disabled the visual editor, the post_content goes through an "extra" esc_textarea(). add_filter('user_can_richedit', '__return_true'); $post = get_post($post_id, OBJECT, 'edit'); function get_tag_name($tag) { return $tag->name; } $tags = array_map('get_tag_name', wp_get_post_tags($post_id)); $post_format = p2_get_post_format($post_id); // handle page as post_type if ('page' == $post->post_type) { $post_format = ''; $tags = ''; } add_filter('user_can_richedit', '__return_false'); $post->post_content = apply_filters('the_editor_content', $post->post_content); echo json_encode(array('title' => $post->post_title, 'content' => $post->post_content, 'post_format' => $post_format, 'post_type' => $post->post_type, 'tags' => $tags)); }
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; }
function related_posts($count, $type, $post_id) { $out = $categories = $param = ''; if ($type == 'category') { $categories = get_the_category($post_id); $param = 'category__in'; } else { $categories = wp_get_post_tags($post_id); $param = 'tag__in'; } if ($categories) { $category_ids = array(); foreach ($categories as $individual_category) { $category_ids[] = $individual_category->term_id; } $args = array('post_type' => 'post', $param => $category_ids, 'post__not_in' => array($post_id), 'posts_per_page' => $count, 'ignore_sticky_posts ' => 1); $related = new WP_Query($args); if ($related->have_posts() && $related->found_posts >= 1) { $out .= '<div class="related-posts mts clearfix">'; $out .= '<div class="element-title"><h3>' . __('Related Articles ', 'corporative') . '</h3></div>'; $out .= '<ul class="row_inner">'; $count = 1; while ($related->have_posts()) { $related->the_post(); $gallery = $audioURL = $videoURL = $format = ''; if (get_field('post_gallery')) { $gallery = get_field('post_gallery'); } if (get_field('post_video')) { $videoURL = get_field('post_video'); } if (get_field('post_audio')) { $audioURL = get_field('post_audio'); } if (has_post_format('video')) { $format = 'Video'; } elseif (has_post_format('audio')) { $format = 'Audio'; } elseif (has_post_format('gallery')) { $format = 'Gallery'; } else { $format = 'Standard'; } $out .= '<li class="grid_3 grid_item no_title_thumb">'; $out .= mediaholder_caption('', $format, 243, 160, 'carousel', $videoURL, $audioURL, $gallery); $out .= '<h2 class="post_title"><a href="' . get_permalink() . '" title="">' . get_the_title() . '</a></h2>'; $out .= '</li>'; if ($count % 4 == 0) { $out .= '<div class="clear"></div>'; } $count++; } $out .= '</ul>'; $out .= '</div>'; } } wp_reset_postdata(); return $out; }
public function get_tags($object, $field_name, $request) { $ret = []; foreach (wp_get_post_tags($object['id']) as $tag) { $ret[$tag->term_id] = $tag->name; } return $ret; }
/** * get_tags * * @param $page * @return array */ protected function get_tags() { if (empty($this->tags)) { $this->tags = wp_get_post_tags($this->get_post()->ID); $this->tags = count($this->tags) ? $this->tags[0]->term_id : array(); } return $this->tags; }
public function e_tags(WP_REST_Request $request) { $id = $request->get_param("id"); if (empty($id)) { return get_tags(); } return wp_get_post_tags($id); }
/** * 相关页面 */ function wpdx_related_pages() { $orig_post = $post; global $post; $tags = wp_get_post_tags($post->ID); if ($tags) { $tag_ids = array(); foreach ($tags as $individual_tag) { $tag_ids[] = $individual_tag->term_id; } $args = array('post_type' => 'page', 'tag__in' => $tag_ids, 'post__not_in' => array($post->ID), 'posts_per_page' => 5); $my_query = new WP_Query($args); if ($my_query->have_posts()) { echo '<div id="relatedpages"><h3>相关页面</h3><ul>'; while ($my_query->have_posts()) { $my_query->the_post(); ?> <li> <div class="relatedthumb"><a href="<?php the_permalink(); ?> " rel="bookmark" title="<?php the_title(); ?> "> <?php the_post_thumbnail('thumb'); ?> </a></div> <div class="relatedcontent"> <h3><a href="<?php the_permalink(); ?> " rel="bookmark" title="<?php the_title(); ?> "> <?php the_title(); ?> </a></h3> <?php the_time('M j, Y'); ?> </div> </li> <?php } echo '</ul></div>'; } else { echo "没有相关页面"; } } $post = $orig_post; wp_reset_query(); }
public static function getTags($postId) { $tagsString = ''; $t = wp_get_post_tags($postId); foreach ($t as $tag) { $tagsString .= $tag->name . ', '; } return trim($tagsString, ', '); }
/** * This function is called once per Post that is sent out. If the Post is sent out several times * then it will also be called several times. This happens if you have 20 subscribers but only send * 10 Mails in a batch. * @param int $post_id the id of the Post * @return array An array of replacements */ function post_notificataion_uf_perPost($post_id) { //This is the easiest way to create array with a low possibility of errors $rv = array(); $cats = wp_get_post_categories($post_id); $tags = wp_get_post_tags($post_id); $rv['@@categories'] = wp_get_post_categories($post_id); return $rv; }
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'); }