Risposte nei forum create
-
AutorePost
-
19 Novembre 2015 alle 15:39 in risposta a: ordinare custom taxonomy category in ordine gerarchico e alfabetico #119252manucnxPartecipante
ho risolto in questo modo
$taxonomy = 'casestudies_category';
// get the term IDs assigned to post.
$post_terms = wp_get_object_terms( $post->ID, $taxonomy, array( 'fields' => 'ids' ) );
// separator between links
$separator = ' ';
if ( !empty( $post_terms ) && !is_wp_error( $post_terms ) ) {
$term_ids = implode( ',' , $post_terms );
$terms = wp_list_categories( 'title_li=&style=none&echo=0&taxonomy=' . $taxonomy . '&include=' . $term_ids );
$terms = rtrim( trim( str_replace( '', $separator, $terms ) ), $separator );
// display post categories
echo $terms;
}manucnxPartecipanteforse ho sbagliato dall’inizio, ho un sito che contiene una sezione blog.
l’elenco dei post (single.php) gli ho richiamati in una pagina (page.php).
il problema è che quando entro nel dettaglio del post non rimane lo stato attivo nel menu.
manucnxPartecipanteGrazie mille
manucnxPartecipanteho risolto cosà¬
<?php
// $terms = get_the_term_list( $post->ID, ‘casestudies_category’);
echo get_the_term_list( $post->ID, ‘casestudies_category’, ”, ‘
‘, ” );?>
manucnxPartecipanteok, probabilmente sono custom taxonomies, io le chiamavo categorie perché da backend vengono visualizzate come le categorie del post di default.
in sostanza dovevo creare le categorie e i tag per il custom post.
ti incollo il mio function, magari ho sbagliato qualcosa nel crearle.
//creo il custom post
add_action( 'init', 'create_my_post_types' );
function create_my_post_types() {
register_post_type( 'casestudy',
array(
'labels' => array(
'name' => __( 'Case Study' ),
'singular_name' => __( 'Case Study' ),
'add_new' => __( 'Add New' ),
'add_new_item' => __( 'Add New' ),
'edit' => __( 'Edit' ),
'edit_item' => __( 'Edit post' ),
'new_item' => __( 'New post' ),
'view' => __( 'View post' ),
'view_item' => __( 'View post' ),
'search_items' => __( 'Search post' ),
'not_found' => __( 'No post found' ),
'not_found_in_trash' => __( 'No post found in Trash' ),
'parent' => __( 'Parent slide' ),
),
'public' => true,
'rewrite' => array( 'slug' => 'casestudy', 'with_front' => true ),
'has_archive' => true,
'capability_type' => 'post',
'supports' => array('title','editor','thumbnail','revisions', 'taxonomy')
)
);
// creo le categorie per i poost_type case study
function my_taxonomies_casestudies() {
$labels = array(
'name' => __('Categorie Case Study', 'taxonomy general name'),
'singular_name' => __('Categoria Case Study', 'taxonomy singular name'),
'menu_name' => __('Categorie'),
);
$args = array(
'labels' => $labels,
'hierarchical' => true,
);
register_taxonomy( 'casestudies_category', 'casestudy', $args );
}
add_action('init','my_taxonomies_casestudies',0);
//creo i tag per le case study
function reg_tag() {
register_taxonomy_for_object_type('post_tag', 'casestudy');
}
add_action('init', 'reg_tag');manucnxPartecipanteCiao grazie per il supporto
ho modificato il codice, ora mi visualizza sia le categorie che i tag del post.
è possibile far visualizzare solo le categorie senza i tag?
$customPostTaxonomies = get_object_taxonomies('casestudy');
foreach($customPostTaxonomies as $tax)
{
echo "<ul class='menu'>" ;
the_terms( $id, $tax,'','');
echo "" ;
}12 Ottobre 2015 alle 14:00 in risposta a: Visualizzare descrizione categoria all'hover sulla voce menu #118990manucnxPartecipantemi sono dimenticato di aggiungere che è la descrizione delle categorie di un custom post
manucnxPartecipantecon questo codice me le mostra tutte, se volessi mostrare solo quelle selezionate da be ?
$customPostTaxonomies = get_object_taxonomies('casestudy');
foreach($customPostTaxonomies as $tax)
{
$args = array(
'public' => true,
'_builtin' => false,
'taxonomy' => $tax,
);
echo "<ul class='menu'>" ;
wp_list_categories( $args );
echo "" ;
}manucnxPartecipanteè un tema che sto costruendo.
se ti può essere utile, le categorie che non riesco a visualizzare sono quelle del custom post (le categorie dell’articolo di “base” riesco a visualizzarle.
manucnxPartecipantesi, è dentro il loop
-
AutorePost