本文整理汇总了PHP中get_the_tags函数的典型用法代码示例。如果您正苦于以下问题:PHP get_the_tags函数的具体用法?PHP get_the_tags怎么用?PHP get_the_tags使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_the_tags函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: handleChange
/**
* Triggers on a change event and adds the relevant URL's to the ban list
*
* Function inspired by Varnish HTTP Purge
* https://github.com/Ipstenu/varnish-http-purge/blob/master/plugin/varnish-http-purge.php#L277
*
* @param [type] $postId [description]
* @return [type] [description]
*/
protected function handleChange($postId)
{
// If this is a valid post we want to purge the post, the home page and any associated tags & cats
// If not, purge everything on the site.
$validPostStatus = array("publish", "trash");
$thisPostStatus = get_post_status($postId);
// If this is a revision, stop.
if (get_permalink($postId) !== true && !in_array($thisPostStatus, $validPostStatus)) {
return;
} else {
// array to collect all our URLs
$listofurls = array();
// Category purge based on Donnacha's work in WP Super Cache
$categories = get_the_category($postId);
if ($categories) {
foreach ($categories as $cat) {
$this->invalidateUrl(get_category_link($cat->term_id));
}
}
// Tag purge based on Donnacha's work in WP Super Cache
$tags = get_the_tags($postId);
if ($tags) {
foreach ($tags as $tag) {
$this->invalidateUrl(get_tag_link($tag->term_id));
}
}
// Author URL
$this->invalidateUrl(get_author_posts_url(get_post_field('post_author', $postId)));
$this->invalidateUrl(get_author_feed_link(get_post_field('post_author', $postId)));
// Archives and their feeds
$archiveurls = array();
if (get_post_type_archive_link(get_post_type($postId)) == true) {
$this->invalidateUrl(get_post_type_archive_link(get_post_type($postId)));
$this->invalidateUrl(get_post_type_archive_feed_link(get_post_type($postId)));
}
// Post URL
$this->invalidateUrl(get_permalink($postId));
// Feeds
$this->invalidateUrl(get_bloginfo_rss('rdf_url'));
$this->invalidateUrl(get_bloginfo_rss('rss_url'));
$this->invalidateUrl(get_bloginfo_rss('rss2_url'));
$this->invalidateUrl(get_bloginfo_rss('atom_url'));
$this->invalidateUrl(get_bloginfo_rss('comments_rss2_url'));
$this->invalidateUrl(get_post_comments_feed_link($postId));
// Home Page and (if used) posts page
$this->invalidateUrl(home_url('/'));
if (get_option('show_on_front') == 'page') {
$this->invalidateUrl(get_permalink(get_option('page_for_posts')));
}
}
// Filter to add or remove urls to the array of purged urls
// @param array $purgeUrls the urls (paths) to be purged
// @param int $postId the id of the new/edited post
// $this->invalidateUrls = apply_filters( 'vhp_purge_urls', $this->invalidateUrls, $postId );
}
示例2: get_data_original
public function get_data_original($num = '', $post_id = null)
{
global $wpdb, $post;
if (!isset($post_id)) {
$post_id = $post->ID;
}
if (empty($post_id)) {
return false;
}
$current_tags = get_the_tags($post_id);
if (!$current_tags) {
return false;
}
$tags = array();
foreach ((array) $current_tags as $tag) {
$tags[] = absint($tag->term_id);
}
$tag_list = implode(',', $tags);
if ($num == '') {
$option = get_option('sirp_options');
$num = $option['display_num'];
}
$q = "SELECT ID FROM {$wpdb->posts} AS p\n\t\t\tINNER JOIN {$wpdb->term_relationships} AS tr ON (p.ID = tr.object_id)\n\t\t\tINNER JOIN {$wpdb->term_taxonomy} AS tt ON (tr.term_taxonomy_id = tt.term_taxonomy_id)\n\t\t\tWHERE (tt.taxonomy = 'post_tag' AND tt.term_id IN ({$tag_list}))\n\t\t\tAND p.post_status = 'publish'\n\t\t\tAND p.post_type = 'post'\n\t\t\tAND p.ID != {$post_id}\n\t\t\tGROUP BY tr.object_id\n\t\t\tORDER BY post_date DESC" . $wpdb->prepare(" LIMIT %d", $num);
return $wpdb->get_results($q, ARRAY_A);
}
示例3: dtheme_keywords
function dtheme_keywords()
{
global $s, $post;
$keywords = '';
if (is_single()) {
if (get_the_tags($post->ID)) {
foreach (get_the_tags($post->ID) as $tag) {
$keywords .= $tag->name . ', ';
}
}
foreach (get_the_category($post->ID) as $category) {
$keywords .= $category->cat_name . ', ';
}
$keywords = substr_replace($keywords, '', -2);
} elseif (is_home()) {
$keywords = dopt('d_keywords');
} elseif (is_tag()) {
$keywords = single_tag_title('', false);
} elseif (is_category()) {
$keywords = single_cat_title('', false);
} elseif (is_search()) {
$keywords = esc_html($s, 1);
} else {
$keywords = trim(wp_title('', false));
}
if ($keywords) {
echo "<meta name=\"keywords\" content=\"{$keywords}\" />\n";
}
}
示例4: wp_aatags_run
function wp_aatags_run($post_ID)
{
$tags = get_option('wp_aatags_opts');
$number = get_option('wp_aatags_aadnumber');
global $wpdb;
if (get_post($post_ID)->post_type == 'post' && !wp_is_post_revision($post_ID) && !get_the_tags($post_ID)) {
$post_title = get_post($post_ID)->post_title;
$post_content = get_post($post_ID)->post_content;
switch ($tags) {
case 3:
$requix = strtolower($post_title . ' ' . wp_trim_words($post_content, 333, ''));
break;
case 2:
$requix = strtolower($post_title . ' ' . wp_trim_words($post_content, 999, ''));
break;
default:
$requix = strtolower($post_title);
break;
}
$body = wp_aatags_keycontents(wp_aatags_html2text($requix), $number);
if ($body != 'rEr') {
$keywords = wp_aatags_kwsiconv($body);
wp_add_post_tags($post_ID, $keywords);
} else {
wp_aatags_alts($post_ID, $post_title, $post_content);
}
}
}
示例5: render_related_string
function render_related_string()
{
$settings = C_NextGen_Settings::get_instance();
$type = $settings->appendType;
$maxImages = $settings->maxImages;
$sluglist = array();
switch ($type) {
case 'tags':
if (function_exists('get_the_tags')) {
$taglist = get_the_tags();
if (is_array($taglist)) {
foreach ($taglist as $tag) {
$sluglist[] = $tag->slug;
}
}
}
break;
case 'category':
$catlist = get_the_category();
if (is_array($catlist)) {
foreach ($catlist as $cat) {
$sluglist[] = $cat->category_nicename;
}
}
break;
}
$taglist = implode(',', $sluglist);
if ($taglist === 'uncategorized' || empty($taglist)) {
return;
}
$renderer = C_Component_Registry::get_instance()->get_utility('I_Displayed_Gallery_Renderer');
$view = C_Component_Registry::get_instance()->get_utility('I_Component_Factory')->create('mvc_view', '');
$retval = $renderer->display_images(array('source' => 'tags', 'container_ids' => $taglist, 'display_type' => NEXTGEN_GALLERY_BASIC_THUMBNAILS, 'images_per_page' => $maxImages, 'maximum_entity_count' => $maxImages, 'template' => $view->get_template_abspath('photocrati-nextgen_gallery_display#related'), 'show_all_in_lightbox' => FALSE, 'show_slideshow_link' => FALSE, 'disable_pagination' => TRUE));
return apply_filters('ngg_show_related_gallery_content', $retval, $taglist);
}
开发者ID:lcw07r,项目名称:productcampamsterdam.org,代码行数:35,代码来源:adapter.displayed_gallery_related_element.php
示例6: wpthemes_post_class
function wpthemes_post_class($class = '', $post_id = null)
{
$post = get_post($post_id);
$classes = array();
$classes[] = $post->post_type;
if (is_sticky($post->ID) && is_home()) {
$classes[] = 'sticky';
}
$classes[] = 'hentry';
foreach ((array) get_the_category($post->ID) as $cat) {
if (empty($cat->slug)) {
continue;
}
$classes[] = 'category-' . $cat->slug;
}
foreach ((array) get_the_tags($post->ID) as $tag) {
if (empty($tag->slug)) {
continue;
}
$classes[] = 'tag-' . $tag->slug;
}
if (!empty($class)) {
if (!is_array($class)) {
$class = preg_split('#\\s+#', $class);
}
$classes = array_merge($classes, $class);
}
return apply_filters('post_class', $classes, $class, $post_id);
}
示例7: get_related_posts
function get_related_posts()
{
// an array of tags from the current post
$related_tags = get_the_tags();
/*
$tag will be used in this example, this is just the first tag
from the array. To optimize the plugin we would want to loop through
all of the tags in the $related_tags array and do something more
interesting with them.
*/
$tag = $related_tags[0];
// The ID of the current post
$current_post = get_the_id();
// The arguments for the nested loop
$args = array('posts_per_page' => 3, 'post__not_in' => array($current_post), 'tag' => $tag->name);
$related_query = new WP_Query($args);
if ($related_query->have_posts()) {
$html = '<h2>Some Related Posts</h2>';
$html .= '<ul>';
while ($related_query->have_posts()) {
$related_query->the_post();
$html .= '<li>';
$html .= get_the_title();
$html .= '</li>';
}
$html .= '</ul>';
}
return $html;
}
示例8: ushipnetwork_entry_footer
/**
* Prints HTML with meta information for the categories, tags and comments.
*/
function ushipnetwork_entry_footer()
{
// Hide category and tag text for pages.
if ('post' === get_post_type()) {
$byline = sprintf(esc_html_x('by %s', 'post author', 'ushipnetwork'), '<span class="author vcard"><a class="url fn n" href="' . esc_url(get_author_posts_url(get_the_author_meta('ID'))) . '">' . esc_html(get_the_author()) . '</a></span>');
echo '<div class="byline">' . '<div class="authorship">' . $byline . '</div>' . '<div class="share">';
include "share.php";
echo '</div>' . '</div>';
$posttags = get_the_tags();
$count = 0;
$separator = ', ';
$output = '';
if (!empty($posttags)) {
echo '<span class="tag-list">tags: ';
foreach ($posttags as $posttag) {
$count++;
if ($count <= 2) {
$output .= '<a href="' . esc_url(get_tag_link($posttag->term_id)) . '" alt="' . esc_attr(sprintf(__('View all posts in %s', 'textdomain'), $posttag->name)) . '">' . esc_html($posttag->name) . '</a>' . $separator;
}
}
echo trim($output, $separator);
}
echo '</span>';
}
edit_post_link(sprintf(esc_html__('Edit %s', 'ushipnetwork'), the_title('<span class="screen-reader-text">"', '"</span>', false)), '<span class="edit-link">', '</span>');
}
示例9: flatbook_post_metas
function flatbook_post_metas()
{
$user = get_the_author();
$date = get_the_date('F j');
$cats = get_the_category();
$tags = get_the_tags();
$comm = get_comments_number();
$type = get_post_format();
if (false === $type) {
$type = __('standard', 'flatbook');
}
echo '<div class="entry-metas">';
if ($type) {
echo '<span class="format"><i class="fa fa-inbox"></i>' . $type . '</span>';
}
if ($date) {
echo '<span class="posted-on"><i class="fa fa-dashboard"></i>' . $date . '</span>';
}
if ($user) {
echo '<span class="byline"><i class="fa fa-user"></i>' . $user . '</span>';
}
if ($cats) {
echo '<span class="cats"><i class="fa fa-folder-open"></i>' . $cats[0]->cat_name . '</span>';
}
if ($tags) {
echo '<span class="tags"><i class="fa fa-tags"></i>' . $tags[0]->name . '</span>';
}
if ($comm) {
echo '<span class="comments"><i class="fa fa-comments"></i>' . $comm . __(' Comment', 'flatbook') . '</span>';
}
echo '</div>';
}
示例10: Bing_related_posts_ID
/**
*获取相关文章
*http://www.bgbk.org
*/
function Bing_related_posts_ID($post = null)
{
$post = get_post($post);
$number = 3;
$posts = array();
$tags = get_the_tags($post);
$exclude_ID = array($post->ID);
if (!empty($tags)) {
$tags_ID = array();
foreach ($tags as $tag) {
$tags_ID[] = $tag->term_id;
}
$posts = get_posts(array('tag__in' => $tags_ID, 'exclude' => $exclude_ID, 'orderby' => 'rand', 'fields' => 'ids', 'numberposts' => $number));
}
$cats = get_the_category($post);
if (count($posts) < $number && !empty($cats)) {
$cats_ID = array();
foreach ($cats as $cat) {
$cats_ID[] = $cat->term_id;
}
$_posts = get_posts(array('category__in' => $cats_ID, 'exclude' => array_merge($exclude_ID, $posts), 'orderby' => 'rand', 'fields' => 'ids', 'numberposts' => $number - count($posts)));
$posts = array_merge($posts, $_posts);
}
if (count($posts) < $number) {
$_posts = get_posts(array('exclude' => array_merge($exclude_ID, $posts), 'orderby' => 'rand', 'fields' => 'ids', 'numberposts' => $number - count($posts)));
$posts = array_merge($posts, $_posts);
}
return $posts;
}
示例11: auto_add_tag
public function auto_add_tag($title, $post_id)
{
global $post;
$result = '';
$add_tags = '';
$i = 0;
if (in_the_loop()) {
$p = get_post($post_id);
$cur_title = $p->post_title;
$post_tags = get_the_tags($post_id);
if ($post_tags) {
foreach ($post_tags as $tag) {
//get the first post tag
if ($i == 0) {
$add_tags .= '[' . $tag->name . '] ';
}
$i++;
}
}
$result = $add_tags . $cur_title;
} else {
$result = $title;
}
return $result;
}
示例12: get_bodyid
function get_bodyid()
{
if (is_home()) {
$bodyid = 'home';
} elseif (is_archive() and !is_author() and !is_tax() and !is_tag()) {
$categories = get_the_category();
foreach ($categories as $category) {
$cat_id = $category->term_id;
$cat_parent_id = $category->category_parent;
}
if ($cat_parent_id) {
$cat_name = strtolower(get_the_category_by_id($cat_parent_id));
} else {
$cat_name = strtolower(get_the_category_by_id($cat_id));
}
$bodyid = $cat_name;
} elseif (is_archive() and is_author()) {
$bodyid = 'profile';
} elseif (is_archive() and is_tax('nh_cities')) {
$term = get_term_by('slug', get_query_var('term'), get_query_var('taxonomy'));
$term_name = $term->name;
$bodyid = 'cities-' . $term_name;
} elseif (is_archive() and is_tag()) {
$tags = get_the_tags();
foreach ($tags as $tag) {
$tag_name = $tag->name;
}
$bodyid = $tag_name;
} elseif (is_page()) {
if (is_page('topics')) {
$bodyid = 'topics';
} elseif (is_page('cities')) {
$bodyid = 'cities';
} elseif (is_page('login')) {
$bodyid = 'settings';
} else {
$bodyid = 'general';
}
} elseif (is_single()) {
$categories = get_the_category();
foreach ($categories as $category) {
$cat_id = $category->term_id;
$cat_parent_id = $category->category_parent;
}
if ($cat_parent_id) {
$cat_name = strtolower(get_the_category_by_id($cat_parent_id));
$bodyid = $cat_name;
} else {
$cat_name = strtolower(get_the_category_by_id($cat_id));
$bodyid = $cat_name;
}
// if (isset($cat_name)) {
// $bodyid = $cat_name;
// }
} elseif (is_search()) {
$bodyid = 'search';
}
return $bodyid;
}
示例13: widget
function widget($args, $instance) {
global $post;
// don't show widget if we are not on a post page
if ($post == null || $post->post_type != 'post') {
echo '<!-- ' . __('Tweet Blender: Not shown as this is not a post', 'tweetblender') . ' -->';
return;
}
// check custom tb_tags field
$sources = array();
$custom_fields = get_post_custom($post->ID);
$post_tags = get_the_tags($post->ID);
if (isset($custom_fields['tb_tags'])) {
foreach($custom_fields['tb_tags'] as $key => $tags) {
$sources = array_merge($sources,explode(',',$tags));
}
}
// check general post tags
elseif (isset($post_tags) && is_array($post_tags) && sizeof($post_tags) > 0) {
foreach($post_tags as $tag) {
$sources[] = trim($tag->name);
}
}
// don't show widget if there are no tags
else {
echo '<!-- ' . __('Tweet Blender: Not shown as there are no tags for this post', 'tweetblender') . ' -->';
return;
}
if (sizeof($args) > 0) {
extract($args, EXTR_SKIP);
}
$tb_o = get_option('tweet-blender');
echo $before_widget;
$title = empty($instance['title']) ? ' ' : apply_filters('widget_title', $instance['title']);
if ( !empty( $title ) ) { echo $before_title . $title . $after_title; };
$instance['widget_sources'] = join('\n\r',$sources);
// add configuraiton options
echo '<form id="' . $this->id . '-f" class="tb-widget-configuration">';
echo '<input type="hidden" name="sources" value="' . addslashes(join(',',$sources)) . '">';
echo '<input type="hidden" name="refreshRate" value="' . $instance['widget_refresh_rate'] . '">';
echo '<input type="hidden" name="tweetsNum" value="' . $instance['widget_tweets_num'] . '">';
echo '</form>';
// print out header and list of tweets
echo '<div id="'. $this->id . '-mc">';
echo tb_create_markup($mode = 'widget',$instance,$this->id,$tb_o);
// print out footer
echo '<div class="tb_footer"></div>';
echo '</div>';
echo $after_widget;
}
示例14: meta_keywords
/**
* Tags as meta keywords
**/
function meta_keywords()
{
$posttags = get_the_tags();
foreach ((array) $posttags as $tag) {
$meta_keywords .= $tag->name . ',';
}
return substr($meta_keywords, 0, -1);
}
示例15: get_tags_list
function get_tags_list()
{
$tags = get_the_tags();
if (empty($tags)) {
return;
}
get_view('post-tags', '', compact('tags'));
}