Domanda

E 'questa funzionalità integrata in wordpress? Non ho visto nulla all'interno del codice.

codex.wordpress.org/Function_Reference/wp_tag_cloud

Ho un paio di pagine che sono specifica categoria e vorrei mostrare tutti i tag associati a tali posti.

Ho trovato questo, ma non sono sicuro se il suo corretto o se un modo migliore esiste ( fonte ) ( vecchio metodo !!!! ):

<?php
    query_posts('category_name=html');
    if (have_posts()) : while (have_posts()) : the_post();
        $posttags = get_the_tags();
        if ($posttags) {
            foreach($posttags as $tag) {
                $all_tags_arr[] = $tag -> name;
            }
        }
    endwhile; endif; 

    $tags_arr = array_unique($all_tags_arr);
?>
    <ul>
<?php
    foreach($tags_arr as $tag){
        echo '<li>'.$tag.'</li>';
    }
?>
</ul>
<?php wp_reset_query(); ?>

UPDATE (semplificato) :::

per fare una lista delle tag da una specifica categoria di questo codice è molto meglio (basta cambiare il nome della categoria):

:: Appena aggiornati di nuovo a causa di un errore di ciclo ::

    <ul>
                <?php
                    query_posts('category_name=html');
                    if (have_posts()) : while (have_posts()) : the_post();

                        if( get_the_tag_list() ){
                            echo $posttags = get_the_tag_list('<li>','</li><li>','</li>');
                        }

                    endwhile; endif; 

                    wp_reset_query(); 
                ?>
</ul>

Anche duro io possa avere una soluzione, si prega di aggiornare questo se uno nuovo viene intorno.

È stato utile?

Soluzione

Credo che il metodo che hai trovato è l'unico modo è possibile ottenere quello che stai cercando. Forse è possibile modificare alcune linee, ma il concetto è giusto.

Al momento non credo che ci sia un modo per tag di filtro come si farebbe con una funzione fondamentale wordpress.

Altri suggerimenti

Non ho ricevuto il codice qui sopra per lavorare la mia installazione di WordPress. tuttavia sono riuscito a modificarlo fino a quando ha funzionato. Ecco la mia Tweak:

$catid = get_cat_ID(single_cat_title("",false));
$catobj = get_category($catid);
$catslug = $catobj->slug;
$all_tags_arr = array();
query_posts('category_name='.$catslug);
if (have_posts()) : while (have_posts()) : the_post();
    $posttags = get_the_tags();
    if ($posttags) {
        foreach($posttags as $tag) {
            $all_tags_arr[] = $tag -> term_id;
        }
    }
endwhile; endif; 

$tags_arr = array_unique($all_tags_arr);

$tagcloud_args = array(
    'include'   =>  implode(',',$tags_arr),
);

wp_tag_cloud( $tagcloud_args ); 
wp_reset_query();

Ecco un esempio molto più facile .... Basta cambiare il nome della categoria e oplà hai fatto. I tag associati stamperanno in forma di elenco.

<?php query_posts('category_name=html'); if (have_posts()) : while (have_posts()) : the_post();

    $posttags = get_the_tags();

    if ($posttags) {
        foreach($posttags as $tag) {
            $all_tags[] = $tag -> name;
        }
    }
    endwhile; endif; 

    //This snippet removes any duplicates.
    $tags_unique = array_unique($all_tags); 

    echo '<ul>';
        foreach($tags_unique as $unique) {
          echo  '<li>'.$unique.'</li>';
        }
    echo '</ul>';

    wp_reset_query();

?>
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top