Estoy usando este código para poder publicar las categorías por locación y funciona (shortcodes.php)
/**
* Location Shortcode
* @param [type] $atts
* @param string $content
* @return [type]
*/
add_shortcode( 'zee_location', function( $atts, $content = null ){
$atts = shortcode_atts(
array(
'column' => '3'
), $atts);
extract($atts);
$args = array(
'posts_per_page' => -1,
'post_type' => 'zee_location',
);
$locations = get_posts( $args );
ob_start();
if(count($locations)>0){ ?>
<div id="portfolio" class="clearfix">
<ul class="portfolio-filter">
<li><a class="btn btn-default active" href="#" data-filter="*"><?php _e('All', ZEETEXTDOMAIN); ?></a></li>
<?php
$terms = get_terms('cat_location', array('hide_empty'=> true));
foreach ($terms as $term) {
?>
<li><a class="btn btn-default" href="#" data-filter=".<?php echo $term->slug; ?>"><?php echo $term->name; ?></a></li>
<?php
}
?>
</ul>
<ul class="portfolio-items col-<?php echo $column; ?>">
<?php foreach ($locations as $key => $value) { ?>
<?php
$terms = wp_get_post_terms( $value->ID, 'cat_location' );
$new_terms = array();
foreach ($terms as $term) $new_terms[] = $term->slug;
$slugs = implode(' ', $new_terms);
?>
<li class="portfolio-item <?php echo $slugs; ?>">
<div class="item-inner">
<?php
echo get_the_post_thumbnail( $value->ID, array(300,300), array(
'class' => "img-responsive",
'alt' => trim(strip_tags( $value->post_title )),
'title' => trim(strip_tags( $value->post_title ))
));
?>
<a href="<?php echo get_permalink( $value->ID ); ?>"><h5><?php echo $value->post_title; ?></h5></a>
<div class="overlay">
<?php
$full_img = wp_get_attachment_image_src( get_post_thumbnail_id($value->ID), 'full');
$img_src= $full_img[0];
?>
<a class="preview btn btn-danger" href="<?php echo $img_src; ?>" rel="prettyPhoto"><i class="icon-eye-open"></i></a>
<a class="preview btn btn-danger" href="<?php echo get_post_permalink( $value->ID ); ?>"><i class="glyphicon glyphicon-link"></i></a>
</div>
</div>
</li>
<?php } ?>
</ul>
</div>
<?php }
else { ?>
<div class="alert alert-danger fade in">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
<?php _e('No location item found!', ZEETEXTDOMAIN); ?>
</div>
<?php
}
return ob_get_clean();
});
Quiero hacer lo mismo, pero para tener una página que publique las etiquetas.
Lo "lógico" sería aplicar un elseif y sustituir cat_location por tag_location... Pero no hace el llamado correspondiente.
Tengo aplicado el código para que cada publicación tenga la etiqueta en functions.php
/** Post type: Locations **/
add_action('init', function(){
$labels = array(
'name' => _x( 'Location', ZEETEXTDOMAIN ),
'singular_name' => _x( 'Location', ZEETEXTDOMAIN ),
'menu_name' => __( 'Locations', ZEETEXTDOMAIN ),
'all_items' => __( 'All Locations', ZEETEXTDOMAIN ),
'parent_item' => __( 'Parent Location', ZEETEXTDOMAIN ),
'parent_item_colon' => __( 'Parent Location:', ZEETEXTDOMAIN ),
'add_new' => __( 'Add New', ZEETEXTDOMAIN ),
'update_item' => __( 'Update Location', ZEETEXTDOMAIN ),
'add_new_item' => __( 'Add New Location', ZEETEXTDOMAIN ),
'edit_item' => __( 'Edit Location', ZEETEXTDOMAIN ),
'new_item_name' => __( 'New Location Name', ZEETEXTDOMAIN ),
'view_item' => __( 'View Location', ZEETEXTDOMAIN ),
'search_items' => __( 'Search Locations', ZEETEXTDOMAIN ),
'not_found' => __( 'No Location item found', ZEETEXTDOMAIN ),
'not_found_in_trash' => __( 'No Location item found in Trash', ZEETEXTDOMAIN )
);
$args = array(
'labels' => $labels,
'public' => true,
'has_archive' => false,
'exclude_from_search' => true,
'menu_icon' => get_template_directory_uri() . '/admin/images/icon-portfolio.png',
'rewrite' => array( 'slug' => 'location'),
'capability_type' => 'page',
'supports' => array('title', 'editor', 'thumbnail', 'revisions')
);
register_post_type('zee_location', $args);
flush_rewrite_rules();
});
register_taxonomy('cat_location',
array('zee_location'),
array(
'label' => __('Categories', ZEETEXTDOMAIN),
'hierarchical' => true,
'singular_label' => __('Location Categories', ZEETEXTDOMAIN),
'rewrite' => true,
'show_ui' => true
)
);
register_taxonomy('tag_location',
array('zee_location'),
array(
'label' => __('Tags', ZEETEXTDOMAIN),
'hierarchical' => true,
'singular_label' => __('Location Tags', ZEETEXTDOMAIN),
'rewrite' => true,
'show_ui' => true
)
);
¿Qué podría aplicar para este caso?
Saludos.