WordPress hack: Mostra suas tags em um menu dropdown

Alyen

800px web 2 0 map svg - WordPress hack: Mostra suas tags em um menu dropdownEu nunca gostei tag nuvens, pela simples razão de que a maior parte do tempo, eles não são lidos correctamente. Aqui está a solução para este problema: Exibir tags em um menu dropdown.

A primeira coisa quem temos que fazer é criar a função. Cole o seguinte código no seu arquivo functions.php:

[sourcecode language=”php”] 8, ‘largest’ => 22, ‘unit’ => ‘pt’, ‘number’ => 45,
‘format’ => ‘flat’, ‘orderby’ => ‘name’, ‘order’ => ‘ASC’,
‘exclude’ => ”, ‘include’ => ”
);
$args = wp_parse_args( $args, $defaults );

$tags = get_tags( array_merge($args, array(‘orderby’ => ‘count’, ‘order’ => ‘DESC’)) ); // Always query top tags

if ( empty($tags) )
return;

$return = dropdown_generate_tag_cloud( $tags, $args ); // Here’s where those top tags get sorted according to $args
if ( is_wp_error( $return ) )
return false;
else
echo apply_filters( ‘dropdown_tag_cloud’, $return, $args );
}

function dropdown_generate_tag_cloud( $tags, $args = ” ) {
global $wp_rewrite;
$defaults = array(
‘smallest’ => 8, ‘largest’ => 22, ‘unit’ => ‘pt’, ‘number’ => 45,
‘format’ => ‘flat’, ‘orderby’ => ‘name’, ‘order’ => ‘ASC’
);
$args = wp_parse_args( $args, $defaults );
extract($args);

if ( !$tags )
return;
$counts = $tag_links = array();
foreach ( (array) $tags as $tag ) {
$counts[$tag->name] = $tag->count;
$tag_links[$tag->name] = get_tag_link( $tag->term_id );
if ( is_wp_error( $tag_links[$tag->name] ) )
return $tag_links[$tag->name];
$tag_ids[$tag->name] = $tag->term_id;
}

$min_count = min($counts);
$spread = max($counts) – $min_count;
if ( $spread using_permalinks() ) ? ‘ rel=”tag”‘ : ”;

foreach ( $counts as $tag => $count ) {
$tag_id = $tag_ids[$tag];
$tag_link = clean_url($tag_links[$tag]);
$tag = str_replace(‘ ‘, ‘ ‘, wp_specialchars( $tag ));
$a[] = “\t“;
}

switch ( $format ) :
case ‘array’ :
$return =& $a;
break;
case ‘list’ :
$return = “

    \n\t
  • “;
    $return .= join(“
  • \n\t

  • “, $a);
    $return .= “
  • \n

\n”;
break;
default :
$return = join(“\n”, $a);
break;
endswitch;

return apply_filters( ‘dropdown_generate_tag_cloud’, $return, $tags, $args );
}
?>[/sourcecode]

Uma vez feito, você pode usar a função para obter o menu de etiquetas. Basta abrir o arquivo onde você deseja colocar a sua lista (A maior coloca no sidebar.php) e cole o seguinte código:

[sourcecode language=”php”][/sourcecode]

Esta hack foi inicialmente publicado em WpHacks.

Temas

4 comments on “WordPress hack: Mostra suas tags em um menu dropdown”

Deixe um comentário

O seu endereço de e-mail não será publicado. Campos obrigatórios são marcados com *

Ajuda WordPress © 2024 - Todos os direitos reservados.Desenvolvido por AlyenStudio