Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- First of all I add my taxonomy "Clienti" in the file functions.php:
- `/**
- * Add custom taxonomies
- *
- * Additional custom taxonomies can be defined here
- * http://codex.wordpress.org/Function_Reference/register_taxonomy
- */
- function add_custom_taxonomies() {
- // Add new "Clienti" taxonomy to Posts
- register_taxonomy('cliente', 'post', array(
- // Hierarchical taxonomy (like categories)
- 'hierarchical' => true,
- // This array of options controls the labels displayed in the WordPress Admin UI
- 'labels' => array(
- 'name' => _x( 'Clienti', 'taxonomy general name' ),
- 'singular_name' => _x( 'Cliente', 'taxonomy singular name' ),
- 'search_items' => __( 'Cerca Clienti' ),
- 'all_items' => __( 'Tutti i clienti' ),
- 'parent_item' => __( 'Cliente genitore' ),
- 'parent_item_colon' => __( 'cliente genitore:' ),
- 'edit_item' => __( 'Edit Cliente' ),
- 'update_item' => __( 'Update Cliente' ),
- 'add_new_item' => __( 'Aggiungi nuovo Cliente' ),
- 'new_item_name' => __( 'Nuovo nome cliente' ),
- 'menu_name' => __( 'Clienti' ),
- ),
- // Control the slugs used for this taxonomy
- 'rewrite' => array(
- 'slug' => 'clienti', // This controls the base slug that will display before each term
- 'with_front' => false, // Don't display the category base before "/locations/"
- 'hierarchical' => true // This will allow URL's like "/locations/boston/cambridge/"
- ),
- ));
- }
- add_action( 'init', 'add_custom_taxonomies', 0 );`
- Then I added this code in my loop.I also found the way to show my posts randomly.
- `<div class="sidebarpost">
- <?php
- global $post;
- remove_all_filters('posts_orderby');
- $terms = get_the_terms( $post->ID , 'cliente', 'string');
- $do_not_duplicate[] = $post->ID;
- if(!empty($terms)){
- foreach ($terms as $term) {
- query_posts( array(
- 'cliente' => $term->slug,
- 'showposts' => 5,
- 'caller_get_posts' => 1,
- 'orderby' => 'rand',
- 'post__not_in' => $do_not_duplicate ) );
- if(have_posts()){
- while ( have_posts() ) : the_post(); $do_not_duplicate[] = $post->ID; ?>
- <li class="articlecontextual">
- <a href="<?php the_permalink() ?>"><?php the_post_thumbnail(); ?></a>
- <?php the_ID(); ?>"
- <h2><a href="<? the_permalink()?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a></h2>
- </li>
- <?php endwhile; wp_reset_query();
- }
- }
- }
- ?>
- </div> `
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement