How to build Categories, Archives and Tags in a Drop down menu without a plugin for Twenty Twelve Theme in WordPress

Over the years, during my ten years of blogging career, I have found one of the most outstanding achievements in bloggers arena is the presence of clutter-free sidebar. Now, side bar is meant only for giving more and more information to the user so that plenty of connectivity of readers with the blog could be made possible. Then comes the concept of drop-down menu, were in a single line plenty of information related to blog such as categories, tags, archive can be generated. With the presence of WordPress as the premier blogging mediums we have found plenty of instruments in terms of plugins are there for decorating these critical aspects dealing with computers.

When plugins or widgets are used that could slow down speed of website and user’s experience further and it is important to move for some light weight solutions and the most light weight solution is not to use any of plugins for this and use coding so that with these short coding directly rendering from hosting through data bases could possibly implement and create the most wonderful form of ideas of generating the faster website rendering time. WordPress does provide us with a wide array of free to use as it provides the maximum number of easy to use and protection methods as well as complete enhancements methods so that ultimately there would be win situation for users as well as for web masters.

How to build Categories, Archives and Tags in a Drop down menu without a plugin for Twenty Twelve Theme in WordPress

How to build Categories, Archives and Tags in a Drop down menu without a plugin for Twenty Twelve Theme in WordPress

Categories provide specific wide ranging subjects for users and tags are the part of categories as one specific category of post could have the presence of multiple tags. All these posts are archived through months and days the data base and it shows the number of posts present during that month or day and it also provides one of the easier solutions for user to move towards understanding the construction of website. For the good distribution of content presentation of category, tag and archive are important. We are living in the world of search engine optimization as most of website owners have to be depended upon it and for better indexing and better conveying of presence of posts the use of these three important facets of blog are very important and for this when these three functions of website such as category, tag and archive are well as these information could provide distinct sharing of the ways your website runs within these set ups.

If you would likely to have drop down boxes for categories, archives and tags then first read this disclaimer and security instructions.

Always back up your theme. Use WordPress cPanel hosting to edit the files. Do not use wordpress front end panel or better known as wordpress administration panel. Do edit the code at your own discretion as slight removal of some other codes could lead to bringing your site down for some time?

Archives drop-down code:

It is better to use it at the sidebar dot php. I prefer to use TwentyTwelve theme so most writings are based on it and if you want to use it on some other theme than this could should suffice.
Open sidebar dot php from panel hosting. It is better to back up this file so that we could replace the original file in the case some wrong in coding part happens inadvertently. Search for this code in the sidebar dots php

<?php dynamic_sidebar( 'sidebar-1' ); ?>

Just below this code add the following code to show archive in drop down menu in side bar without using plugin and widgets.

<select name="archive-dropdown" onChange='document.location.href=this.options[this.selectedIndex].value;'>
<option value=""><?php echo attribute_escape(__('Select Month')); ?></option>
<?php wp_get_archives('type=monthly&format=option&show_post_count=1'); ?> </select>

Save side bar dot php and open website in a web browser to see that archive is now present in the drop down menu if you have completed these steps in absolutely correct manner.

Categories Drop-down Code:

It is better to use it at the sidebar dot php. I prefer to use TwentyTwelve theme so most writings are based on it and if you want to use it on some other theme than this could should suffice.
Open sidebar dot php from panel hosting. It is better to back up this file so that we could replace the original file in the case some wrong in coding part happens inadvertently. Search for this code in the sidebar dot php

<?php dynamic_sidebar( 'sidebar-1' ); ?>

Just below this code add the following code to show category in drop down menu in side bar without using plugin and widgets.

<form action="<?php bloginfo('url'); ?>/" method="get">
<?php
$select = wp_dropdown_categories('show_option_none=Select category&show_count=1&orderby=name&echo=0');
$select = preg_replace("#<select([^>]*)>#", "<select$1 onchange='return this.form.submit()'>", $select); echo $select; ?>
<noscript><input type="submit" value="View" /></noscript>
</form>

Save side bar dot php and then open website in a web browser while connecting to internet and if everything goes in the correct manner you could see and find the presence of category in drop down list at the side bar.

How to display WordPress Tags in drop down menu:

While dealing with archives and categories, we could use the forms of sidebar dot php in editing mode. In order to show tags in the side bar it is somewhat needed an additional process. Most of blogger have so many tags used that to show tags in the form of tag cloud becomes somewhat more cluttered and the principal tags gone missing there and just it makes the invaluable propositions or using and showing tag clouds. There are no ways inside default widgets that you could show tags as a drop down menu. You could show these in the form of tag clouds.

There could have been the presence of some of the plugins to show it but using so many plugins for some easier and little tasks could ultimately slow down website to a considerable extent and the prime focus of showing the tags for the case of search engine optimization has gone overboard. Here with the help of two files of the first being the functions dot php and the second one is being side bar dot php we could enhance and show case the presence of tags in drop down mode.

For this no plugins are used as well as no widgets are used so the loading time of website remains as it is and it becomes even more lighter and more user friendly and search engine optimized website. Within due course of some days, after installing this plugin you could find the presence of showing tags of your website when the search about your website could be made in search engines.

Open functions dot php file from cPanel hosting and back up it and then open it with the post editor and then at the end of it paste the following function code of tags to display.

<?php
function dropdown_tag_cloud( $args = '' ) {
 $defaults = array(
 'smallest' => 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 <= 0 )
 $spread = 1;
 $font_spread = $largest - $smallest;
 if ( $font_spread <= 0 )
 $font_spread = 1;
 $font_step = $font_spread / $spread;

// SQL cannot save you; this is a second (potentially different) sort on a subset of data.
 if ( 'name' == $orderby )
 uksort($counts, 'strnatcasecmp');
 else
 asort($counts);

if ( 'DESC' == $order )
 $counts = array_reverse( $counts, true );

$a = array();

$rel = ( is_object($wp_rewrite) && $wp_rewrite->using_permalinks() ) ? ' rel="tag"' : '';

foreach ( $counts as $tag => $count ) {
 $tag_id = $tag_ids[$tag];
 $tag_link = clean_url($tag_links[$tag]);
 $tag = str_replace(' ', '&nbsp;', wp_specialchars( $tag ));
 $a[] = "t<option value='$tag_link'>$tag ($count)</option>";
 }

switch ( $format ) :
 case 'array' :
 $return =& $a;
 break;
 case 'list' :
 $return = "<ul class='wp-tag-cloud'>nt<li>";
 $return .= join("</li>nt<li>", $a);
 $return .= "</li>n</ul>n";
 break;
 default :
 $return = join("n", $a);
 break;
 endswitch;

return apply_filters( 'dropdown_generate_tag_cloud', $return, $tags, $args );
}
?>

 

Then save it and the next step is to open the sidebar dot php files considering that you wish to show it on the side bar. There are other options if you wish to show it as a menu, or footer or at the end of a single article. If you want to show it menu then you could use the following code at header dot php or if you want to show it at footer then you could paste the following code at footer dot php and if you want to show it at the end of article then you could use it within content dot php or at single dot php files. I this example as I always prefer to use twenty Twelve themes, I use it at the side bar. So, open side bar dot php and search for the following code.

<?php wp_nav_menu( array( 'theme_location' => 'primary', 'menu_class' => 'nav-menu' ) ); ?>

After this code paste this code to show tags in drop down mode.

<select name="tag-dropdown" onchange="document.location.href=this.options[this.selectedIndex].value;">
 <option value="#">Liste d'auteurs</option>
 <?php dropdown_tag_cloud('number=0&order=asc'); ?>
</select>

In term of look and feel of these codes in side bar or at some other places of themes at some themes these look good and at some other these could pose to be slightly misplaced and during these course of events the importance of cascade style sheets come into for- front and for this it is important to review these codes and see how it mingled with yours webs presence and how could you make it better and unable with it.

As web master and owner of self-hosted word press theme one should always look for some of the better looking word press sites as well as provide every other word press information as well as site information within the shortest possible space of home page or at side bar which remain repeat in every page. This is yours site and it is you who to decide upon how to develop and goes upon for complete forms of development and that should make you feel satisfied that you have built every nuke and corner of site with yours own set up of codes and not with the help of some other third party plugins and widgets.

*A few days ago. I read a post on wphacks.com where everything about wordpress is discussed there. I’d never hear of this before, but I was intrigued, so I read on.*