WordPress tutorial, Display wordpress Tags In Dropdown Menu without plugin. we given simple code here which you need to put in theme functions.php file.
If you want to display the tags in drop down menu then use following code in functions.php file.
Display wordpress Tags In Dropdown Menu without plugin
02
function
dropdown_tag_cloud(
$args
=
''
) {
04
'smallest'
=> 8,
'largest'
=> 22,
'unit'
=>
'pt'
,
'number'
=> 45,
05
'format'
=>
'flat'
,
'orderby'
=>
'name'
,
'order'
=>
'ASC'
,
06
'exclude'
=>
''
,
'include'
=>
''
08
$args
= wp_parse_args(
$args
,
$defaults
);
10
$tags
= get_tags(
array_merge
(
$args
,
array
(
'orderby'
=>
'count'
,
'order'
=>
'DESC'
)) );
15
$return
= dropdown_generate_tag_cloud(
$tags
,
$args
);
16
if
( is_wp_error(
$return
) )
19
echo
apply_filters(
'dropdown_tag_cloud'
,
$return
,
$args
);
22
function
dropdown_generate_tag_cloud(
$tags
,
$args
=
''
) {
25
'smallest'
=> 8,
'largest'
=> 22,
'unit'
=>
'pt'
,
'number'
=> 45,
26
'format'
=>
'flat'
,
'orderby'
=>
'name'
,
'order'
=>
'ASC'
28
$args
= wp_parse_args(
$args
,
$defaults
);
33
$counts
=
$tag_links
=
array
();
34
foreach
( (
array
)
$tags
as
$tag
) {
35
$counts
[
$tag
->name] =
$tag
->
count
;
36
$tag_links
[
$tag
->name] = get_tag_link(
$tag
->term_id );
37
if
( is_wp_error(
$tag_links
[
$tag
->name] ) )
38
return
$tag_links
[
$tag
->name];
39
$tag_ids
[
$tag
->name] =
$tag
->term_id;
42
$min_count
= min(
$counts
);
43
$spread
= max(
$counts
) -
$min_count
;
46
$font_spread
=
$largest
-
$smallest
;
47
if
(
$font_spread
<= 0 )
49
$font_step
=
$font_spread
/
$spread
;
52
if
(
'name'
==
$orderby
)
53
uksort(
$counts
,
'strnatcasecmp'
);
57
if
(
'DESC'
==
$order
)
58
$counts
=
array_reverse
(
$counts
, true );
62
$rel
= (
is_object
(
$wp_rewrite
) &&
$wp_rewrite
->using_permalinks() ) ?
' rel="tag"'
:
''
;
64
foreach
(
$counts
as
$tag
=>
$count
) {
65
$tag_id
=
$tag_ids
[
$tag
];
66
$tag_link
= clean_url(
$tag_links
[
$tag
]);
67
$tag
=
str_replace
(
' '
,
' '
, wp_specialchars(
$tag
));
68
$a
[] =
"\t<option value='$tag_link'>$tag ($count)</option>"
;
76
$return
=
"<ul class='wp-tag-cloud'>\n\t<li>"
;
77
$return
.= join(
"</li>\n\t<li>"
,
$a
);
78
$return
.=
"</li>\n</ul>\n"
;
81
$return
= join(
"\n"
,
$a
);
85
return
apply_filters(
'dropdown_generate_tag_cloud'
,
$return
,
$tags
,
$args
);
In footer or sidebar file or where you want to display the tags in dropdown use the following code.
Display wordpress Tags In Dropdown Menu without plugin
1
<select name=
"tag-dropdown"
onchange=
"document.location.href=this.options[this.selectedIndex].value;"
>
2
<option value=
"#"
>Liste d'auteurs</option>
3
<?php dropdown_tag_cloud(
'number=0&order=asc'
); ?>