本文整理汇总了PHP中get_term_link函数的典型用法代码示例。如果您正苦于以下问题:PHP get_term_link函数的具体用法?PHP get_term_link怎么用?PHP get_term_link使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_term_link函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get_url
/**
* get_url - Returns a url based on a string that holds either post type and id or taxonomy and id
*/
static function get_url($link, $post_id = false)
{
$link = explode(',', $link);
if ($link[0] == 'lightbox') {
$link = wp_get_attachment_image_src($post_id, apply_filters('avf_avia_builder_helper_lightbox_size', 'large'));
return $link[0];
}
if (empty($link[1])) {
return $link[0];
}
if ($link[0] == 'manually') {
return $link[1];
}
if (post_type_exists($link[0])) {
return get_permalink($link[1]);
}
if (taxonomy_exists($link[0])) {
$return = get_term_link(get_term($link[1], $link[0]));
if (is_object($return)) {
$return = "";
}
//if an object is returned it is a WP_Error object and something was not found
return $return;
}
}
示例2: get_rocket_post_terms_urls
/**
* Get all terms archives urls associated to a specific post
*
* @since 1.0
*
* @param int $post_ID The post ID
* @return array $urls List of taxonomies URLs
*/
function get_rocket_post_terms_urls($post_ID)
{
$urls = array();
$taxonomies = get_object_taxonomies(get_post_type($post_ID), 'objects');
foreach ($taxonomies as $taxonomy) {
if (!$taxonomy->public) {
continue;
}
// Get the terms related to post
$terms = get_the_terms($post_ID, $taxonomy->name);
if (!empty($terms)) {
foreach ($terms as $term) {
$term_url = get_term_link($term->slug, $taxonomy->name);
if (!is_wp_error($term_url)) {
$urls[] = $term_url;
}
}
}
}
/**
* Filter the list of taxonomies URLs
*
* @since 1.1.0
*
* @param array $urls List of taxonomies URLs
*/
$urls = apply_filters('rocket_post_terms_urls', $urls);
return $urls;
}
示例3: enlightenment_project_types_filter
function enlightenment_project_types_filter($args = null)
{
$args = array('container' => 'ul', 'container_class' => 'project-types-filter', 'term_tag' => 'li', 'term_class' => 'project-type', 'current_term_class' => 'current-project-type', 'sep' => '', 'echo' => true);
$args = apply_filters('enlightenment_project_types_filter_args', $args);
$terms = get_terms('jetpack-portfolio-type');
$output = '';
if (!empty($terms)) {
$output .= enlightenment_open_tag($args['container'], $args['container_class']);
if (is_tax('jetpack-portfolio-type')) {
$output .= enlightenment_open_tag($args['term_tag'], $args['term_class']);
$output .= sprintf('<a href="%1$s" rel="%2$s">%3$s</a>', get_post_type_archive_link('jetpack-portfolio'), 'jetpack-portfolio-type', __('All', 'enlightenment'));
$output .= enlightenment_close_tag($args['term_tag']);
}
foreach ($terms as $term) {
$class = $args['term_class'];
$link = get_term_link($term, $term->taxonomy);
$current_url = sprintf('%1$s%2$s%3$s', is_ssl() ? 'https://' : 'http://', $_SERVER['HTTP_HOST'], $_SERVER['REQUEST_URI']);
if ($link == $current_url) {
$class .= ' ' . $args['current_term_class'];
}
$output .= enlightenment_open_tag($args['term_tag'], $class);
$output .= sprintf('<a href="%1$s" rel="%2$s">%3$s</a>', $link, $term->taxonomy, $term->name);
$output .= enlightenment_close_tag($args['term_tag']);
}
$output .= enlightenment_close_tag($args['container']);
}
$output = apply_filters('enlightenment_project_types_filter', $output);
if (!$args['echo']) {
return $output;
}
echo $output;
}
示例4: portfolioTypes
function portfolioTypes()
{
$portfolioTypes = get_terms('portfolio-type', 'orderby=id&order=ASC');
if (count($portfolioTypes) > 0) {
//current term
$currentTermId = is_tax('portfolio-type') ? get_queried_object()->term_id : "";
?>
<ol class="breadcrumb">
<?php
foreach ($portfolioTypes as $types) {
$activeClass = $currentTermId == $types->term_id ? " active " : "";
?>
<li class="gallery-type term-<?php
echo esc_attr($types->slug);
echo esc_attr($activeClass);
?>
term-id-<?php
echo esc_attr($types->term_id);
?>
">
<a href="<?php
echo esc_url(get_term_link($types));
?>
"><?php
echo esc_html($types->name);
?>
</a>
</li>
<?php
}
?>
</ol><?php
}
}
示例5: prepare_data
protected function prepare_data($data)
{
$term_id = intval($data[0]);
$taxonomy = $data[1];
$url = get_term_link($term_id, $taxonomy);
return array('url' => $url);
}
示例6: start_el
/**
* @see Walker::start_el()
* @since 2.1.0
*
* @param string $output Passed by reference. Used to append additional content.
* @param object $category Category data object.
* @param int $depth Depth of category in reference to parents.
* @param integer $current_object_id
*/
function start_el(&$output, $cat, $depth = 0, $args = array(), $current_object_id = 0)
{
$term_meta = get_option("taxonomy_{$cat->term_id}");
$output .= '<li class="list-group-item cat-item cat-item-' . $cat->term_id;
if ($args['current_category'] == $cat->term_id) {
$output .= ' current-cat';
}
if ($args['has_children'] && $args['hierarchical']) {
$output .= ' cat-parent';
}
if ($args['current_category_ancestors'] && $args['current_category'] && in_array($cat->term_id, $args['current_category_ancestors'])) {
$output .= ' current-cat-parent';
}
$output .= '"><a href="' . get_term_link((int) $cat->term_id, 'product_cat') . '">';
if (isset($term_meta['icon']) && $term_meta['icon'] != '') {
$output .= '<i class="fa ' . $term_meta['icon'] . '"></i>';
} else {
//$output .= '<i class="fa fa-star"></i>';
}
$output .= '<span class="heading">';
$output .= '<span class="menu-title">' . __($cat->name, 'woocommerce') . '</span>';
if ($cat->category_description != '') {
$output .= '<span class="menu-desc">' . wpo_string_limit_words($cat->category_description, 5) . '</span>';
}
$output .= '</span>';
$output .= '</a>';
if ($args['show_count']) {
$output .= ' <span class="badge count">(' . $cat->count . ')</span>';
}
}
示例7: add_new_category
function add_new_category()
{
if (is_user_logged_in()) {
if (isset($_POST['cat_name']) && !empty($_POST['cat_name']) && isset($_POST['parent_id']) && !empty($_POST['parent_id'])) {
$cat_name = esc_html($_POST['cat_name']);
$parent_id = esc_html($_POST['parent_id']);
$new_cat_args = array($cat_name, 'bookmark-category');
if ($parent_id == -1) {
// Add Term to Bookmark Category
$new_category = wp_insert_term($cat_name, 'bookmark-category');
} else {
// Add Term to Bookmark Category
$new_category = wp_insert_term($cat_name, 'bookmark-category', array('parent' => $parent_id));
}
if (!is_wp_error($new_category)) {
$term = get_term_by('id', $new_category['term_id'], 'bookmark-category');
// Add Term to User
wp_set_object_terms($current_user->ID, array($term->slug), 'bookmark-category', true);
$returner = array('success' => true, 'cat_id' => $new_category['term_id'], 'cat_slug' => $term->slug, 'cat_link' => get_term_link($term, 'bookmark-category'));
} else {
$returner = array('success' => false, 'reason' => 'WP Error on term creation.');
}
} else {
$returner = array('success' => false, 'reason' => 'Post values not set.');
}
} else {
$returner = array('success' => false, 'reason' => 'User not logged in.');
}
echo json_encode($returner);
exit;
}
示例8: redirection
/**
* will redirect old links to new link structures.
*/
public static function redirection()
{
global $wpdb, $wp_query;
if (is_object($wp_query) && $wp_query->get('em_redirect')) {
//is this a querystring url?
if ($wp_query->get('event_slug')) {
$event = $wpdb->get_row('SELECT event_id, post_id FROM ' . EM_EVENTS_TABLE . " WHERE event_slug='" . $wp_query->get('event_slug') . "' AND (blog_id=" . get_current_blog_id() . " OR blog_id IS NULL OR blog_id=0)", ARRAY_A);
if (!empty($event)) {
$EM_Event = em_get_event($event['event_id']);
$url = get_permalink($EM_Event->post_id);
}
} elseif ($wp_query->get('location_slug')) {
$location = $wpdb->get_row('SELECT location_id, post_id FROM ' . EM_LOCATIONS_TABLE . " WHERE location_slug='" . $wp_query->get('location_slug') . "' AND (blog_id=" . get_current_blog_id() . " OR blog_id IS NULL OR blog_id=0)", ARRAY_A);
if (!empty($location)) {
$EM_Location = em_get_location($location['location_id']);
$url = get_permalink($EM_Location->post_id);
}
} elseif ($wp_query->get('category_slug')) {
$url = get_term_link($wp_query->get('category_slug'), EM_TAXONOMY_CATEGORY);
}
if (!empty($url)) {
wp_redirect($url, 301);
exit;
}
}
}
示例9: ubik_places_ancestors
function ubik_places_ancestors($taxonomy = 'places', $depth = 2, $sep = ', ')
{
// Initialize
$output = '';
$places = array();
// Get term ID; we only need one
global $post;
$terms = get_the_terms($post->ID, $taxonomy);
$term = $terms[0];
// Only proceed if this term shows inheritance
if (!empty($term->parent)) {
// The grunt work
$ancestors = ubik_terms_ancestors($term->term_id, $taxonomy);
// Ready to roll
if (!empty($ancestors) && count($ancestors) > 1) {
// Remove basal term, limit depth, and reverse (as is the custom for displaying places)
$ancestors = array_reverse(array_slice(array_slice($ancestors, 0, -1), 0, $depth));
// Loop through all ancestors and create links
if (!empty($ancestors)) {
foreach ($ancestors as $ancestor) {
$place = get_term_by('id', $ancestor, $taxonomy);
$places[] = '<a href="' . get_term_link($place->term_id, $taxonomy) . '" rel="tag">' . $place->name . '</a>';
}
// Assemble output
if (!empty($places)) {
$output = implode($sep, $places);
}
}
}
}
return $output;
}
示例10: ap_question_categories_html
/**
* Output question categories
* @param array $args
* @return string
*/
function ap_question_categories_html($args = array())
{
$defaults = array('question_id' => get_the_ID(), 'list' => false, 'tag' => 'span', 'class' => 'question-categories', 'label' => __('Categories', 'categories-for-anspress'), 'echo' => false);
if (!is_array($args)) {
$defaults['question_id'] = $args;
$args = $defaults;
} else {
$args = wp_parse_args($args, $defaults);
}
$cats = get_the_terms($args['question_id'], 'question_category');
if ($cats) {
$o = '';
if ($args['list']) {
$o = '<ul class="' . $args['class'] . '">';
foreach ($cats as $c) {
$o .= '<li><a href="' . esc_url(get_term_link($c)) . '" title="' . $c->description . '">' . $c->name . '</a></li>';
}
$o .= '</ul>';
} else {
$o = $args['label'];
$o .= '<' . $args['tag'] . ' class="' . $args['class'] . '">';
foreach ($cats as $c) {
$o .= '<a href="' . esc_url(get_term_link($c)) . '" title="' . $c->description . '">' . $c->name . '</a>';
}
$o .= '</' . $args['tag'] . '>';
}
if ($args['echo']) {
echo $o;
}
return $o;
}
}
示例11: tags
public function tags()
{
if (!did_action('pre_get_posts')) {
return array();
}
$queried_object = get_queried_object();
$tags = array();
$default_tags = array('og:type' => 'website', 'og:locale' => get_locale(), 'og:site_name' => get_bloginfo('name'), 'og:image' => $this->get_image_url());
if (is_front_page()) {
$tags = array('og:url' => home_url('/'), 'og:title' => get_bloginfo('name'), 'og:description' => get_bloginfo('description'));
} else {
if (is_singular()) {
$tags = array('og:type' => 'article', 'og:url' => get_permalink($queried_object), 'og:title' => get_the_title($queried_object), 'og:description' => $this->generate_preview($queried_object->post_content), 'article:published_time' => date('c', strtotime($queried_object->post_date_gmt)), 'article:modified_time' => date('c', strtotime($queried_object->post_modified_gmt)), 'article:author' => get_author_posts_url($queried_object->post_author));
} else {
if (is_tax() || is_category() || is_tag()) {
$tags = array('og:url' => get_term_link($queried_object), 'og:title' => $queried_object->name, 'og:description' => $this->generate_preview($queried_object->description));
} else {
if (is_author()) {
$tags = array('og:type' => 'profile', 'og:url' => get_author_posts_url($queried_object->ID), 'og:title' => $queried_object->display_name, 'og:description' => $this->generate_preview($queried_object->user_description), 'profile:first_name' => get_the_author_meta('first_name', $queried_object->ID), 'profile:last_name' => get_the_author_meta('last_name', $queried_object->ID));
}
}
}
}
$tags = array_merge($default_tags, $tags);
return apply_filters('appthemes_open_graph_meta_tags', $tags);
}
示例12: pronamic_framework_shortcode_terms_index
/**
* Shortcode terms index
*/
function pronamic_framework_shortcode_terms_index($atts)
{
extract(shortcode_atts(array('taxonomy' => null, 'parent' => 0), $atts));
$result = '';
if ($taxonomy) {
$terms = get_terms($taxonomy);
$alphabet = array();
foreach ($terms as $term) {
$letter = strtoupper(substr($term->name, 0, 1));
if (!isset($alphabet[$letter])) {
$alphabet[$letter] = array();
}
$alphabet[$letter][] = $term;
}
if (!empty($alphabet)) {
$result .= '<ul class="pronamic-terms-index-list">';
foreach ($alphabet as $letter => $terms) {
$result .= '<li>';
$result .= $letter;
if (!empty($terms)) {
$result .= '<ul>';
foreach ($terms as $term) {
$result .= '<li>';
$result .= sprintf('<a href="%s">%s</a>', get_term_link($term), $term->name);
$result .= '</li>';
}
$result .= '</ul>';
}
$result .= '</li>';
}
$result .= '</ul>';
}
}
return $result;
}
示例13: permalink
public function permalink()
{
$permalink = get_term_link($this->term_id, $this->taxonomy);
if (!is_wp_error($permalink)) {
return $this->permalink = $permalink;
}
}
示例14: browse_displays
function browse_displays()
{
$custom_taxonomy = 'gallery-wing';
$custom_terms = get_terms($custom_taxonomy);
$str_return = '<ul>';
foreach ($custom_terms as $custom_term) {
wp_reset_query();
$args = array('post_type' => 'display', 'tax_query' => array(array('taxonomy' => $custom_taxonomy, 'field' => 'slug', 'terms' => $custom_term->slug, 'include_children' => false)));
$loop = new WP_Query($args);
$term_name = $custom_term->name;
$term_slug = $custom_term->slug;
$term_link = get_term_link($term_slug, $custom_taxonomy);
$str_return .= '<li><a href="' . $term_link . '">' . $term_name . '</a>';
if ($loop->have_posts()) {
$str_return .= '<ol>';
while ($loop->have_posts()) {
$loop->the_post();
$str_return .= '<li><a href="' . get_permalink() . '">' . get_the_title() . '</a></li> ';
}
$str_return .= '</ol>';
}
$str_return .= '</li>';
}
$str_return .= '</ul>';
return $str_return;
}
示例15: populate_form_array
/**
* Generate the form configuration array for this tab
*
* @since 0.1
* @access private
*/
private function populate_form_array()
{
// define the sections
$this->sections = array('locations' => array('title' => _x('Page Slugs', 'page locations section title', 'wpsc'), 'fields' => array('store_slug', 'store_as_front_page', 'category_base_slug', 'product_base_slug', 'cart_page_slug', 'checkout_page_slug', 'customer_account_page_slug', 'login_page_slug', 'password_reminder_page_slug', 'register_page_slug', 'prefix_product_slug', 'hierarchical_product_category_url')), 'titles' => array('title' => _x('Page Titles', 'page titles section title', 'wpsc'), 'fields' => array('store_title', 'cart_page_title', 'checkout_page_title', 'customer_account_page_title', 'login_page_title', 'password_reminder_page_title', 'register_page_title')));
// Shortcut variables for buttons and messages
$view_button = '<a class="button button-secondary button-view-page" href="%1$s">%2$s</a>';
$view_message = _x('View', 'view page', 'wpsc');
$view_category_message = _x('Sample Category', 'view page', 'wpsc');
$view_product_message = _x('Sample Product', 'view page', 'wpsc');
// generate sample URLs for single product and product category
$base_shop_url = '<small>' . esc_url(wpsc_get_store_url('/')) . '</small>';
$sample_category = get_terms('wpsc_product_category', array('number' => 1));
$sample_product = get_posts(array('post_type' => 'wpsc-product', 'numberposts' => 1));
// generate form fields
$this->form_array = array('store_slug' => array('type' => 'textfield', 'prepend' => '<small>' . esc_url(home_url('/')) . '</small>', 'title' => _x('Main store', 'page slug setting', 'wpsc'), 'append' => sprintf($view_button, wpsc_get_store_url(), $view_message), 'validation' => 'required', 'class' => 'regular-text'), 'store_as_front_page' => array('type' => 'radios', 'title' => _x('Display main store on front page', 'page settings', 'wpsc'), 'options' => array(1 => _x('Yes', 'settings', 'wpsc'), 0 => _x('No', 'settings', 'wpsc'))), 'store_title' => array('type' => 'textfield', 'title' => _x('Main store title', 'page slug title', 'wpsc'), 'validation' => 'required'), 'category_base_slug' => array('type' => 'textfield', 'prepend' => $base_shop_url, 'append' => empty($sample_category) ? '' : sprintf($view_button, get_term_link($sample_category[0]), $view_category_message), 'title' => _x('Product category base slug', 'permalinks setting', 'wpsc'), 'validation' => 'required', 'class' => 'regular-text'), 'product_base_slug' => array('type' => 'textfield', 'prepend' => $base_shop_url, 'append' => empty($sample_product) ? '' : sprintf($view_button, get_permalink($sample_product[0]), $view_product_message), 'title' => _x('Single product base slug', 'permalinks setting', 'wpsc'), 'validation' => 'required', 'class' => 'regular-text'), 'prefix_product_slug' => array('type' => 'checkboxes', 'title' => _x('Product prefix', 'permalinks setting', 'wpsc'), 'options' => array(1 => __('Include category slug in product URL.', 'wpsc'))), 'hierarchical_product_category_url' => array('type' => 'radios', 'title' => _x('Hierarchical product category URL', 'permalinks setting', 'wpsc'), 'options' => array(1 => _x('Yes', 'settings', 'wpsc'), 0 => _x('No', 'settings', 'wpsc')), 'description' => __('When hierarchical product category URL is enabled, parent product categories are also included in the product URL.', 'wpsc')), 'cart_page_slug' => array('type' => 'textfield', 'prepend' => $base_shop_url, 'append' => sprintf($view_button, wpsc_get_cart_url(), $view_message), 'title' => _x('Cart page', 'page settings', 'wpsc'), 'validation' => 'required', 'class' => 'regular-text'), 'cart_page_title' => array('type' => 'textfield', 'title' => _x('Cart page', 'page settings', 'wpsc'), 'validation' => 'required'), 'checkout_page_slug' => array('type' => 'textfield', 'prepend' => $base_shop_url, 'title' => _x('Checkout page', 'page setting', 'wpsc'), 'validation' => 'required', 'class' => 'regular-text'), 'checkout_page_title' => array('type' => 'textfield', 'title' => _x('Checkout page', 'page settings', 'wpsc'), 'validation' => 'required'), 'customer_account_page_slug' => array('type' => 'textfield', 'prepend' => $base_shop_url, 'append' => sprintf($view_button, wpsc_get_customer_account_url(), $view_message), 'title' => _x('Customer account page', 'permalinks setting', 'wpsc'), 'validation' => 'required|slug_not_conflicted', 'class' => 'regular-text'), 'customer_account_page_title' => array('type' => 'textfield', 'title' => _x('Customer account page', 'page settings', 'wpsc'), 'validation' => 'required'), 'login_page_slug' => array('type' => 'textfield', 'prepend' => $base_shop_url, 'title' => _x('Login page', 'permalinks setting', 'wpsc'), 'description' => __('Leaving this field blank will disable the page.', 'wpsc'), 'validation' => 'slug_not_conflicted', 'class' => 'regular-text'), 'login_page_title' => array('type' => 'textfield', 'title' => _x('Login page', 'page settings', 'wpsc'), 'validation' => 'required'), 'password_reminder_page_slug' => array('type' => 'textfield', 'prepend' => $base_shop_url, 'title' => _x('Password reminder page', 'permalinks setting', 'wpsc'), 'description' => __("Leaving this field blank will disable the page.", 'wpsc'), 'validation' => 'slug_not_conflicted', 'class' => 'regular-text'), 'password_reminder_page_title' => array('type' => 'textfield', 'title' => _x('Password reminder page', 'page settings', 'wpsc'), 'validation' => 'required'), 'register_page_slug' => array('type' => 'textfield', 'prepend' => $base_shop_url, 'title' => _x('Register page', 'permalinks setting', 'wpsc'), 'description' => __("Leaving this field blank will disable the page.", 'wpsc'), 'validation' => 'slug_not_conflicted', 'class' => 'regular-text'), 'register_page_title' => array('type' => 'textfield', 'title' => _x('Register page', 'page settings', 'wpsc'), 'validation' => 'required'));
// display warnings for login, register and password reminder pages when
// "Anyone can register" is disabled.
if (!get_option('users_can_register')) {
$additional_description = '<br /> ' . __('<strong>Note:</strong> Enable "Anyone can register" in <a href="%s">Settings -> General</a> first if you want to use this page.', 'wpsc');
$additional_description = sprintf($additional_description, admin_url('options-general.php'));
$this->form_array['login_page_slug']['description'] .= $additional_description;
$this->form_array['password_reminder_page_slug']['description'] .= $additional_description;
$this->form_array['register_page_slug']['description'] .= $additional_description;
}
}