本文整理汇总了PHP中get_terms函数的典型用法代码示例。如果您正苦于以下问题:PHP get_terms函数的具体用法?PHP get_terms怎么用?PHP get_terms使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_terms函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: html
/**
* Get field HTML
*
* @param $html
* @param $field
* @param $meta
*
* @return string
*/
static function html($html, $meta, $field)
{
$options = $field['options'];
$terms = get_terms($options['taxonomy'], $options['args']);
$html = '';
// Checkbox LIST
if ('checkbox_list' === $options['type']) {
$html = array();
foreach ($terms as $term) {
$checked = checked(in_array($term->slug, $meta), true, false);
$html[] = "<label><input type='checkbox' name='{$field['field_name']}' value='{$term->slug}'{$checked} /> {$term->name}</label>";
}
$html = implode('<br />', $html);
} elseif ('checkbox_tree' === $options['type']) {
$elements = self::process_terms($terms);
$html .= self::walk_checkbox_tree($meta, $field, $elements, $field['options']['parent'], true);
} elseif ('select_tree' == $options['type']) {
$elements = self::process_terms($terms);
$html .= self::walk_select_tree($meta, $field, $elements, $field['options']['parent'], '', true);
} else {
$multiple = $field['multiple'] ? " multiple='multiple' style='height: auto;'" : "'";
$html .= "<select name='{$field['field_name']}'{$multiple}>";
foreach ($terms as $term) {
$selected = selected(in_array($term->slug, $meta), true, false);
$html .= "<option value='{$term->slug}'{$selected}>{$term->name}</option>";
}
$html .= "</select>";
}
return $html;
}
示例2: jellythemes_photos_list
function jellythemes_photos_list($atts, $content = null)
{
extract(shortcode_atts(array('limit' => 8), $atts));
$return = '
<nav class="primary"><ul>
<li><a class="selected" href="#" data-filter="*"><span>' . __('All photos', 'jellythemes') . '</span></a></li>';
$types = get_terms('type', array('hide_empty' => 0));
if ($types && !is_wp_error($types)) {
foreach ($types as $type) {
$return .= '<li><a href="#" data-filter=".' . esc_js($type->slug) . '"><span>' . $type->name . '</span></a></li>';
}
}
$return .= '</ul></nav>
<div class="portfolio">';
$photos = new WP_Query(array('post_type' => 'photo', 'posts_per_page' => esc_attr($limit)));
while ($photos->have_posts()) {
$photos->the_post();
$term_list = wp_get_post_terms(get_the_ID(), 'type', array("fields" => "names"));
$images = rwmb_meta('_jellythemes_project_images', 'type=plupload_image', get_the_ID());
foreach ($images as $image) {
$img = wp_get_attachment_image($image['ID'], 'full', false, array('class' => 'img-responsive'));
$src = wp_get_attachment_image_src($image['ID'], 'full');
}
$return .= '<article class="' . implode(' ', get_post_class('entry')) . '">
<a class="swipebox" href="' . $src[0] . '">
' . $img . '
<span class="magnifier"></span>
</a>
</article>';
}
$return .= '</div>';
return $return;
}
示例3: get_values
protected function get_values()
{
$terms = array();
// Load all available event categories
$source = get_terms(TribeEvents::TAXONOMY, array('orderby' => 'name', 'order' => 'ASC'));
if (empty($source) || is_wp_error($source)) {
return array();
}
// Preprocess the terms
foreach ($source as $term) {
$terms[(int) $term->term_id] = $term;
$term->parent = (int) $term->parent;
$term->depth = 0;
$term->children = array();
}
// Initally copy the source list of terms to our ordered list
$ordered_terms = $terms;
// Re-order!
foreach ($terms as $id => $term) {
// Skip root elements
if (0 === $term->parent) {
continue;
}
// Reposition child terms within the ordered terms list
unset($ordered_terms[$id]);
$term->depth = $terms[$term->parent]->depth + 1;
$terms[$term->parent]->children[$id] = $term;
}
// Finally flatten out and return
return $this->flattened_term_list($ordered_terms);
}
示例4: sf_ajax_optionsearch
function sf_ajax_optionsearch()
{
$data = array();
$i = 0;
preg_match_all('^(.*)\\[(.*)\\]^', $_POST['val'], $match);
$data_type = $match[1][0];
$data_value = $match[2][0];
if ($data_type == 'meta') {
$terms = get_postmeta_values($data_value);
if (is_array($terms)) {
foreach ($terms as $term) {
$data[$i]['key'] = $term->meta_value;
$data[$i]['val'] = $term->meta_value;
$i++;
}
}
} elseif ($data_type == 'tax') {
$args = array('orderby' => 'name', 'order' => 'ASC', 'hide_empty' => true);
$terms = get_terms($data_value, $args);
if (is_array($terms)) {
foreach ($terms as $term) {
$data[$i]['key'] = $term->term_id;
$data[$i]['val'] = $term->name;
$i++;
}
}
}
echo json_encode($data);
die;
}
示例5: hmp_category_meta_box
function hmp_category_meta_box($post)
{
global $post;
?>
<p><label for="hmp_portfolio_category">Category</label></p>
<select name="hmp_portfolio_category">
<option value="">Select Category...</option>
<?php
$cats = get_terms('hmp-entry-category', array('hide_empty' => false));
$obj_cat = wp_get_object_terms($post->ID, 'hmp-entry-category');
$obj_cat = $obj_cat[0];
foreach ($cats as $cat) {
?>
<option <?php
if ($cat->term_id == $obj_cat->term_id) {
echo 'selected="selected" ';
}
?>
value="<?php
echo $cat->term_id;
?>
"><?php
echo $cat->name;
?>
</option>
<?php
}
?>
</select>
<p><label for="hmp_portfolio_new_category">Add New Category</label></p>
<input name="hmp_portfolio_new_category" type="text" />
<?php
}
示例6: uni_calendar_display_categories
function uni_calendar_display_categories()
{
?>
<div class="pagePanel clear">
<?php
$aEventCats = get_terms('uni_calendar_event_cat');
if (!empty($aEventCats) && !is_wp_error($aEventCats)) {
?>
<ul class="productFilter classesFilter clear">
<li><a class="active" data-filter="all" href="#"><?php
_e('All', 'uni-calendar');
?>
</a></li>
<?php
foreach ($aEventCats as $oTerm) {
?>
<li><a data-filter="<?php
echo $oTerm->slug;
?>
" href="#"><?php
echo $oTerm->name;
?>
</a></li>
<?php
}
?>
</ul>
<?php
}
?>
</div>
<?php
}
开发者ID:primus1989,项目名称:https---github.com-DataDesignSystems-drishtiq,代码行数:33,代码来源:uni-events-calendar-functions.php
示例7: _get_html_for_taxonomy
/**
* Generates the HTML for a taxonomy selector.
*
* @param array $view_args Arguments to the parent view
* @param bool $tag whether it's tags or categories.
*
* @return string Markup for categories selector
*/
protected function _get_html_for_taxonomy($view_args, $tag = false)
{
$taxonomy_name = 'events_categories';
$type = 'category';
$type_for_filter = 'cat_ids';
$type_for_view_args = 'categories';
if (true === $tag) {
$taxonomy_name = 'events_tags';
$type = 'tag';
$type_for_filter = 'tag_ids';
$type_for_view_args = 'tags';
}
$terms = get_terms($taxonomy_name, array('orderby' => 'name'));
if (empty($terms)) {
return '';
}
foreach ($terms as &$term) {
$href = $this->_registry->get('html.element.href', $view_args, $type);
$href->set_term_id($term->term_id);
$term->href = $href->generate_href();
if (false === $tag) {
$taxonomy = $this->_registry->get('view.event.taxonomy');
$term->color = $taxonomy->get_category_color_square($term->term_id);
}
}
$href_for_clearing_filter = $this->generate_href_without_arguments($view_args, array($type_for_filter));
$args = array($type_for_view_args => $terms, 'selected_' . $type_for_filter => $view_args[$type_for_filter], 'data_type' => $view_args['data_type'], 'clear_filter' => $href_for_clearing_filter, 'text_clear_category_filter' => __('Clear category filter', AI1EC_PLUGIN_NAME), 'text_categories' => __('Categories', AI1EC_PLUGIN_NAME), 'text_clear_tag_filter' => __('Clear tag filter', AI1EC_PLUGIN_NAME), 'text_tags' => __('Tags', AI1EC_PLUGIN_NAME));
$loader = $this->_registry->get('theme.loader');
return $loader->get_file($type_for_view_args . '.twig', $args, false)->get_content();
}
示例8: get_shows
public function get_shows($hide_empty = true)
{
$args = array('orderby' => 'name', 'order' => 'ASC', 'hide_empty' => $hide_empty, 'cache_domain' => 'core');
$podcast_show_slug = dipo_get_podcast_show_slug();
$podcast_show = get_terms($podcast_show_slug, $args);
return isset($podcast_show) ? $podcast_show : null;
}
示例9: smamo_widgets_init
function smamo_widgets_init()
{
$terms = get_terms('tax_widget', array('orderby' => 'id', 'hide_empty' => false));
foreach ($terms as $widget) {
register_sidebar(array('id' => $widget->slug, 'name' => $widget->name, 'description' => $widget->description, 'before_widget' => '<div class="widget">', 'after_widget' => '</div>', 'before_title' => '<h4 class="widget-title">', 'after_title' => '</h4>'));
}
}
示例10: cleanup
public function cleanup($opt = NULL, $cpt = NULL, $tax = NULL)
{
// Perform security checks.
if (self::authorize() == TRUE) {
// Remove plugin options from wp_options database table.
if ($opt) {
foreach ($opt as $option) {
delete_option($option);
}
}
// Remove plugin-specific custom post type entries.
if ($cpt) {
$entries = get_posts(array('post_type' => $cpt, 'numberposts' => -1));
foreach ($entries as $entry) {
wp_delete_post($entry->ID, TRUE);
}
}
// Remove plugin-specific custom taxonomy terms.
if ($tax) {
global $wp_taxonomies;
foreach ($tax as $taxonomy) {
register_taxonomy($taxonomy['taxonomy'], $taxonomy['object_type']);
$terms = get_terms($taxonomy['taxonomy'], array('hide_empty' => 0));
foreach ($terms as $term) {
wp_delete_term($term->term_id, $taxonomy['taxonomy']);
}
delete_option($taxonomy['taxonomy'] . '_children');
unset($wp_taxonomies[$taxonomy['taxonomy']]);
}
}
}
}
示例11: get_category_list
function get_category_list()
{
$terms = get_terms('category', 'orderby=name&hide_empty=0');
// 获取到的分类数量
$count = count($terms);
$data = array();
if ($count > 0) {
// 循环输出所有分类信息
foreach ($terms as $term) {
$term_array = get_object_vars($term);
// ["term_id"]=> string(1) "7"
// ["name"]=> string(7) "ASP.NET"
// ["slug"]=> string(6) "aspnet"
// ["term_group"]=> string(1) "0"
// ["term_taxonomy_id"]=> string(1) "7"
// ["taxonomy"]=> string(8) "category"
// ["description"]=> string(0) ""
//["parent"]=> string(1) "4"
// ["count"]=> string(1) "1" }
// echo '<li><a href="'.get_term_link($term, $term->slug).'" title="'.$term->name.'">'.$term->name.'</a></li>';
$array = array('text' => $term_array['name'], 'id' => $term_array['term_id'], 'count' => $term_array['count'], 'description' => $term_array['description'], 'iconCls' => 'x-fa fa-inbox', 'leaf' => true);
// if (!$is_leaf) {
// $array =array_merge($array, $NextAgent);
// }
array_push($data, $array);
}
}
$res = new Response();
$res->success = true;
$res->message = '';
$res->data = $data;
echo $res->to_json();
}
示例12: woocommerce_product_categories
/**
* List all (or limited) product categories
**/
function woocommerce_product_categories($atts)
{
global $woocommerce_loop;
extract(shortcode_atts(array('number' => null, 'orderby' => 'name', 'order' => 'ASC', 'columns' => '4', 'hide_empty' => 1), $atts));
if (isset($atts['ids'])) {
$ids = explode(',', $atts['ids']);
$ids = array_map('trim', $ids);
} else {
$ids = array();
}
$hide_empty = $hide_empty == true || $hide_empty == 1 ? 1 : 0;
$args = array('number' => $number, 'orderby' => $orderby, 'order' => $order, 'hide_empty' => $hide_empty, 'include' => $ids);
$terms = get_terms('product_cat', $args);
$woocommerce_loop['columns'] = $columns;
ob_start();
if ($product_categories) {
echo '<ul class="products">';
foreach ($product_categories as $category) {
woocommerce_get_template('content-product_cat.php', array('category' => $category));
}
echo '</ul>';
}
wp_reset_query();
return ob_get_clean();
}
示例13: gdlr_add_import_action
function gdlr_add_import_action()
{
// setting > reading area
update_option('show_on_front', 'page');
update_option('page_on_front', 3720);
update_option('page_for_posts', 0);
// style-custom file
if ($_POST['import-file'] == 'demo.xml') {
$default_file = GDLR_LOCAL_PATH . '/include/function/gdlr-admin-default.txt';
$default_admin_option = unserialize(file_get_contents($default_file));
update_option(THEME_SHORT_NAME . '_admin_option', $default_admin_option);
$source = get_template_directory() . '/stylesheet/style-custom-light.css';
$destination = get_template_directory() . '/stylesheet/style-custom.css';
copy($source, $destination);
} else {
if ($_POST['import-file'] == 'demo-dark.xml') {
$default_file = GDLR_LOCAL_PATH . '/include/function/gdlr-admin-default-dark.txt';
$default_admin_option = unserialize(file_get_contents($default_file));
update_option(THEME_SHORT_NAME . '_admin_option', $default_admin_option);
$source = get_template_directory() . '/stylesheet/style-custom-dark.css';
$destination = get_template_directory() . '/stylesheet/style-custom.css';
copy($source, $destination);
} else {
if ($_POST['import-file'] == 'demo-modern.xml') {
$default_file = GDLR_LOCAL_PATH . '/include/function/gdlr-admin-default-modern.txt';
$default_admin_option = unserialize(file_get_contents($default_file));
update_option(THEME_SHORT_NAME . '_admin_option', $default_admin_option);
$source = get_template_directory() . '/stylesheet/style-custom-modern.css';
$destination = get_template_directory() . '/stylesheet/style-custom.css';
copy($source, $destination);
} else {
if ($_POST['import-file'] == 'demo-hostel.xml') {
$default_file = GDLR_LOCAL_PATH . '/include/function/gdlr-admin-default-hostel.txt';
$default_admin_option = unserialize(file_get_contents($default_file));
update_option(THEME_SHORT_NAME . '_admin_option', $default_admin_option);
$source = get_template_directory() . '/stylesheet/style-custom-hostel.css';
$destination = get_template_directory() . '/stylesheet/style-custom.css';
copy($source, $destination);
}
}
}
}
// menu to themes location
$nav_id = 0;
$navs = get_terms('nav_menu', array('hide_empty' => true));
foreach ($navs as $nav) {
if ($nav->name == 'Main menu') {
$nav_id = $nav->term_id;
break;
}
}
set_theme_mod('nav_menu_locations', array('main_menu' => $nav_id));
// import the widget
$widget_file = GDLR_LOCAL_PATH . '/plugins/goodlayers-importer-widget.txt';
$widget_data = unserialize(file_get_contents($widget_file));
// retrieve widget data
foreach ($widget_data as $key => $value) {
update_option($key, $value);
}
}
示例14: index_action
/**
* Displays the 'tagcloud' display type
*
* @param stdClass|C_Displayed_Gallery|C_DataMapper_Model $displayed_gallery
*/
function index_action($displayed_gallery, $return = FALSE)
{
$display_settings = $displayed_gallery->display_settings;
$application = $this->object->get_registry()->get_utility('I_Router')->get_routed_app();
$tag = $this->param('gallerytag');
// we're looking at a tag, so show images w/that tag as a thumbnail gallery
if (!is_home() && !empty($tag)) {
return $this->object->get_registry()->get_utility('I_Displayed_Gallery_Renderer')->display_images(array('source' => 'tags', 'container_ids' => array(esc_attr($tag)), 'display_type' => $display_settings['display_type'], 'original_display_type' => $displayed_gallery->display_type, 'original_settings' => $display_settings));
}
$defaults = array('exclude' => '', 'format' => 'list', 'include' => $displayed_gallery->get_term_ids_for_tags(), 'largest' => 22, 'link' => 'view', 'number' => $display_settings['number'], 'order' => 'ASC', 'orderby' => 'name', 'smallest' => 8, 'taxonomy' => 'ngg_tag', 'unit' => 'pt');
$args = wp_parse_args('', $defaults);
// Always query top tags
$tags = get_terms($args['taxonomy'], array_merge($args, array('orderby' => 'count', 'order' => 'DESC')));
foreach ($tags as $key => $tag) {
$tags[$key]->link = $this->object->set_param_for($application->get_routed_url(TRUE), 'gallerytag', $tag->slug);
$tags[$key]->id = $tag->term_id;
}
$params = $display_settings;
$params['inner_content'] = $displayed_gallery->inner_content;
$params['storage'] =& $storage;
$params['tagcloud'] = wp_generate_tag_cloud($tags, $args);
$params['displayed_gallery_id'] = $displayed_gallery->id();
$params = $this->object->prepare_display_parameters($displayed_gallery, $params);
return $this->object->render_partial('photocrati-nextgen_basic_tagcloud#nextgen_basic_tagcloud', $params, $return);
}
示例15: search_terms
public static function search_terms($request = null)
{
$response = (object) array('status' => false, 'message' => __('Your request has failed', 'fakerpress'), 'results' => array(), 'more' => true);
if (!Admin::$is_ajax && is_null($request) || !is_user_logged_in()) {
return Admin::$is_ajax ? exit(json_encode($response)) : $response;
}
$request = (object) wp_parse_args($request, array('search' => isset($_POST['search']) ? $_POST['search'] : '', 'post_type' => isset($_POST['post_type']) ? $_POST['post_type'] : null, 'page' => absint(isset($_POST['page']) ? $_POST['page'] : 0), 'page_limit' => absint(isset($_POST['page_limit']) ? $_POST['page_limit'] : 10)));
if (is_null($request->post_type) || empty($request->post_type)) {
$request->post_type = get_post_types(array('public' => true));
}
$response->status = true;
$response->message = __('Request successful', 'fakerpress');
preg_match('/@(\\w+)/i', $request->search, $response->regex);
if (!empty($response->regex)) {
$request->search = array_filter(array_map('trim', explode('|', str_replace($response->regex[0], '|', $request->search))));
$request->search = reset($request->search);
$taxonomies = $response->regex[1];
} else {
$taxonomies = get_object_taxonomies($request->post_type);
}
$response->taxonomies = get_object_taxonomies($request->post_type, 'objects');
$response->results = get_terms((array) $taxonomies, array('hide_empty' => false, 'search' => $request->search, 'number' => $request->page_limit, 'offset' => $request->page_limit * ($request->page - 1)));
if (empty($response->results) || count($response->results) < $request->page_limit) {
$response->more = false;
}
return Admin::$is_ajax ? exit(json_encode($response)) : $response;
}