How To: Build a Categories and Archives Drop-down Box

Over the past couple years I’ve really enjoyed monitoring trends in the blogosphere and one of the trends that has come up recently is blogger’s cleaning up their sidebars by adding drop-down boxes.

If you’d like to build drop-down boxes for your categories and archives on your WordPress blog, here is the code you need:

Archives Drop-down Code

<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>

Categories Drop-down Code

<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>

I think something like this can be a good idea if done with the right theme, but I have also seen it on a few sites where it didn’t look very good, so keep that in mind if you decide to move your categories and archives to a drop-down box!

To see other code snippets we’ve featured here over the past year, check out our WordPress Code page!

  • Leave a Comment
  • How to: Create a Multi-Language Blog

    Using WordPress plugins to automatically translate blog content

    This is the easiest solution. A few WordPress plugins allows you to put some clickable flags in your sidebar, that will automatically translate your content to another language using, for example, Google Translate.
    This is a great solution if you’re looking for a way to make your content available for people that doesn’t speak your language, but you guessed it, the automatic translation isn’t as good as a human translated text.

    Anyways, if you’re interested in theses plugins, here’s a small list. I didn’t tried them all myself, though.

    Using categories and a few hacks

    If you’re a perfectionist, you probably don’t really like the automatic translations provided by Google. In my opinion, if it’s okay for a personal blog, but automatic translations should be avoided on a professional blog.

    For this hack, we will use categories. Go to your dashboard and create categories/sub-categories following the example below:

    English
        One category
        Two categories
    Français
        Une catégorie
        Deux catégories
    Deutsch
        Eine kategorie
        Zwei kategorien

    Of course this is just an example, you can add as many categories as you want. The thing to remember here is that we’re using top level categories for languages, each of them having sub-categories organized by topics.

    Now, you should post at least one example post in each sub-category. Once you’re done, we can start editing our header.php template.

    The idea is quite simple: First, we must display the available languages, and then, a menu with the sub-category related to the current language. We must also think about defining a default language, which will be English in this example.

    1 – Creating the language menu
    Insert the following code where you want the language selection menu to appear:

    <?php
    wp_list_categories('title_li=');
    $lang = 1; // Sets the default language
    ?>

    As you can see, we just need the good old wp_list_categories() function to get our available languages.
    Then, we have to keep a php variable containing the id of the top level category, in order to display the navigation menu in the selected language. We must give a default value to the $lang variable. This default value will be the category id of the language you want to set as default.

    I noticed that many people should have trouble to find the ID of a particular category. If you do, you should definitely read this post.

    2 – Navigation menu
    Now, we got a php variable containing the id of the mother category. As the top-level categories are languages, we know which language the user is using.

    We simply have to display second-level categories.

    <ul>
    <?php
    wp_list_categories('title_li=&child_of=$lang');
    ?>
    </ul>

    3 – Retrieving category
    Here’s a sample code you can use to automatically list posts from a category. This code get the current category (in this example, the language) and then displays the related posts.

    <?php foreach((get_the_category()) as $category) {
          	$thecat = $category->cat_ID . ' ';
        	query_posts('child_of='.$thecat);
    	if (have_posts()) : while (have_posts()) : the_post();
    	   //Classic WP loop
    	endwhile;endif;
    ?>
  • Leave a Comment
  • How to: Display your WordPress Tags in a Drop-Down Menu

    Tags are useful to any blog: As you know it, they allow the user to display a list of posts related to a subject.
    Most of the time, tags are displayed with in a tag cloud. If you have 20 different tags, that’s ok, but if you have 100 or more tags your tag cloud will be very hard to read, and no-one will click on it.

    This is probably why many blogs recently stopped displaying their tag cloud, or put it on a separate page. But I got another solution.

    My wife owns a blog where she reviews books. She use tags to display author names, which is a great use of tags, in my opinion. The tags were first displayed as a list, and it was perfect. But after she reviewed 60+ books, the list started to be too long.

    She asked me about a solution, and after some reflection, I came up with the idea of using a drop-down menu (select html element + a bit of javascript). Happily, I was able to found this code on WordPress forums.

    First, we have to create a php function. Copy and paste the following code in the functions.php file of your theme (Be careful with the php opening/closing tags!)

    <?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 );
    }
    ?>

    Once you have your function, you must call it somewhere on your theme. Just open the file where you want the list to be displayed (Most of the time it is sidebar.php) and paste the following code:

    <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>

    Now, you have a very cool drop-down list to display you tags. No more unreadables tag clouds!

  • Leave a Comment
  • Tip: Use Caution When Shopping for a WordPress Theme

    Whether you are in the market for a new custom WordPress theme, premium WordPress theme, or a free WordPress theme, their is one often forgotten factor that you should be considering when shopping for a new WordPress theme.  That factor is the reputation of the theme author.

    Why is author reputation so important?   In addition to things like quality, theme support, etc., you’ve also got to worry about potential problems such as unknown links (these are usually hidden and could get your blog banned from search engines if discovered) and things like malicious code being run via your WordPress theme.

    Recently Viper007Bond wrote about a theme that was discovered with hidden links (not the same thing as sponsored links):

    What I found inside the theme’s footer.php file though was tons of malicious code. The entire contents of the file was heavily encoded (it was encoded with gzinflate(), str_rot13(), and base64_decode() around 150 times) and a ton of eval()’s. Since I was curious what it was doing, I wrote some PHP to decode it without using the nasty (and unsafe) eval()’s and I finally ended up with the HTML for the footer file (I assume to stop people from removing the code) and some more crazy eval() PHP code to display links to websites.

    Luckily the code was just there to insert links (although using such a theme is a good way to get banned from Google), the PHP could just as easily have stolen passwords and other things. Remember, themes are exactly like plugins — they can execute code. You wouldn’t download a random program off and Internet and run it on your PC, so why would you do it with a plugin or theme?

    So please, only download themes and plugins from reputable sites such as WordPress.org. If in doubt, don’t use it.

    The author cites QualityWordPress.com as the source of this theme, so I would recommend avoiding this site if you are looking for a new theme.

    Conclusion

    There is a good chance that no matter which theme you end up going with (free, premium, or custom) you are going to be fine, but author reputation is just one more thing that should factor into your decision.   Find a theme made by an author you can trust.  I’ve seen many situations over the past couple years where people unknowingly get banned from Google or run into other problems because they made a bad choice when picking their theme.

    Do you factor an authors reputation (word of mouth) and theme support into your decision before downloading/buying a WordPress theme?   I know I do and I also try to keep that in mind whenever I support a theme by adding it to our WordPress theme galleries.

  • Leave a Comment
  • How To: Displaying Your Most Commented Posts

    Though this isn’t quite the same as displaying your most popular posts in your sidebar, here is some code you can use to display the posts that have received the most comments.  You’ll want to place it in your sidebar where you want the code to be displayed.

    Most Commented Posts Code

    Go into your theme files and go to header.php file.   Somewhere within the </head> you’ll want to place the following code:

    <?php most_popular_posts($no_posts = 5, $before = '<li>', $after = '</li>', $show_pass_post = false, $duration='') {
    global $wpdb;
    $request = "SELECT ID, post_title, COUNT($wpdb->comments.comment_post_ID) AS 'comment_count' FROM $wpdb->posts, $wpdb->comments";
    $request .= " WHERE comment_approved = '1' AND $wpdb->posts.ID=$wpdb->comments.comment_post_ID AND post_status = 'publish'";
    if(!$show_pass_post) $request .= " AND post_password =''";
    if($duration !="") { $request .= " AND DATE_SUB(CURDATE(),INTERVAL ".$duration." DAY) < post_date ";
    }
    $request .= " GROUP BY $wpdb->comments.comment_post_ID ORDER BY comment_count DESC LIMIT $no_posts";
    $posts = $wpdb->get_results($request);
    $output = '';
    if ($posts) {
    foreach ($posts as $post) {
    $post_title = stripslashes($post->post_title);
    $comment_count = $post->comment_count;
    $permalink = get_permalink($post->ID);
    $output .= $before . '<a href="' . $permalink . '" title="' . $post_title.'">' . $post_title . '</a> (' . $comment_count.')' . $after;
    }
    } else {
    $output .= $before . "None found" . $after;
    }
    echo $output;
    } ?>

    If you’d prefer to display more than 5 posts, you can change the $no_posts = 5 code to whatever number you want to display.

    Okay, now, you need to figure out where you want to display these most commented posts (usually the sidebar) and place the following code:

    <?php most_popular_posts(); ?>

    And as is usually the case, if you want something easier, you can always go with a plugin such as the Popularity Contest plugin.

    To see other code that we’ve featured, check out our WordPress Code page.

  • Leave a Comment
  • How to: Create an Ajax-based Auto-completing Search Field for your WordPress Theme

    Why not helping your visitors to find what they’re looking for on your blog, by using a cool auto-completion on your search field? To do so, we’ll use WordPress tagcloud, php and ajax.

    Please note that even if this code is fully functional, this is an experimentation, and the SQL query isn’t really optimized.

    The idea

    We will use tags as a list of keyword to suggest to the readers.

    When someone will start to type on the search field, we will use Javascript to send a request to a php page which will do the following SQL request SELECT * FROM matable WHERE ‘name’ LIKE ‘$search%’. Via Ajax, we’ll send back the request results to our page, and display it to the visitor.

    First part: PHP

    The first thing to do is to create a php page. This page will send a request to our WP database and display the tags as a html unordered list.
    <?php
    if (isset($_POST['search'])) {
    $search = htmlentities($_POST['search']);
    } else $search ='';
    $db = mysql_connect('localhost','root',''); //Don't forget to change
    mysql_select_db('wp', $db); //theses parameters
    $sql = "SELECT name from wp_terms WHERE name LIKE '$search%'";
    $req = mysql_query($sql) or die();
    echo '<ul>';
    while ($data = mysql_fetch_array($req))
    {
    echo '<li><a href="#" onclick="selected(this.innerHTML);">'.htmlentities($data['name']).'</a></li>';
    }
    echo '</ul>';
    mysql_close();
    ?>

    This code is simple: It receive a POST parameter (The letter(s) typed in the search field by the visitor) and then sends a request to our WP database in order to gets all tags starting with the letter(s) typed in the search box.

    Part two: Ajax

    Now it’s time to start the client-side programming. We need to code 4 Javascript functions in order to make our auto-completion work:

    • Function ajax() will create a XMLHTTPRequest object.
    • Function request() will send an Ajax request to our gettags.php file.
    • Function return() will return gettags.php contents.
    • And the selected() function will update the search field.

    Here’s our gettags.js file and the 4 functions needed:
    var myAjax = ajax();
    function ajax() {
    var ajax = null;
    if (window.XMLHttpRequest) {
    try {
    ajax = new XMLHttpRequest();
    }
    catch(e) {}
    }
    else if (window.ActiveXObject) {
    try {
    ajax = new ActiveXObject("Msxm12.XMLHTTP");
    }
    catch (e){
    try{
    ajax = new ActiveXObject("Microsoft.XMLHTTP");
    }
    catch (e) {}
    }
    }
    return ajax;
    }
    function request(str) {
    //Don't forget to modify the path according to your theme
    myAjax.open("POST", "wp-content/themes/openbook-fr/gettags.php");
    myAjax.onreadystatechange = result;
    myAjax.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    myAjax.send("search="+str);
    }
    function result() {
    if (myAjax.readyState == 4) {
    var liste = myAjax.responseText;
    var cible = document.getElementById('tag_update').innerHTML = liste;
    document.getElementById('tag_update').style.display = "block";
    }
    }
    function selected(choice){
    var cible = document.getElementById('s');
    cible.value = choice;
    document.getElementById('tag_update').style.display = "none";
    }

    Part three: Editing your theme

    Now that we have our php and javascript ready, we can edit the searchform.php file from your WP theme:

    Your searchform.php file should look like this:
    <form method="get" id="searchform" action="<?php bloginfo('url'); ?>/">
    <div>
    <input type="text" value="<?php the_search_query(); ?>" name="s" id="s" />
    <input type="submit" id="searchsubmit" value="Search" />
    </div>
    </form>

    We have to add a div, which will display the received data from the request, as well as a Javascript event on the search form:
    <form method="get" id="searchform" action="<?php bloginfo('url'); ?>/">
    <div>
    <input type="text" value="<?php the_search_query(); ?>" name="s" id="s" onkeyup="request(this.value);"/>
    <input type="submit" id="searchsubmit" value="Search" class="button" />
    </div>
    <div id="tag_update"></div>
    </form>

    Final part: CSS

    Due to the fact that every theme use different color schemes, this is only an example. Anyways, I thought it could be a good start:
    #tag_update {
    display: block;
    border-left: 1px solid #373737;
    border-right: 1px solid #373737;
    border-bottom: 1px solid #373737;
    position:absolute;
    z-index:1;
    }
    #tag_update ul {
    margin: 0;
    padding: 0;
    list-style: none;
    }
    #tag_update li{
    display:block;
    clear:both;
    }
    #tag_update a {
    width:134px;
    display: block;
    padding: .2em .3em;
    text-decoration: none;
    color: #fff;
    background-color: #1B1B1C;
    text-align: left;
    }
    #tag_update a:hover{
    color: #fff;
    background-color: #373737;
    background-image: none;
    }

    That’s all. You now have a very nice auto-completing search form! If you have any questions, feel free to leave a comment below.

  • Leave a Comment
  • Parsing and Hacking External RSS Feeds in WordPress

    It’s a little known fact that WordPress contains it’s own RSS parser, and you can use it to your advantage to make custom dynamic pages!

    This is a tutorial on how to take an ordinary RSS feed, parse it using WordPress’ internal RSS parser, and then create dynamic pages with it. I’m not talking about being a scraper, creating a splog, or doing anything spammy at all. I’m talking about creating added value for visitors and your blog while making money. We all know what a “splog” is. It’s a “spam blog”…or someone who takes RSS feeds and generates pages and posts from them and tries to profit using say Adsense or affiliate ads. The pages are just excerpts and titles from RSS feeds (sometimes full posts), and while they do link back to your site (usually) – they’re not the type of links you want to get. These spam blogs don’t have any redeeming value at all, no contact information, and certainly no original content at all.

    Now – let’s take your blog, let’s say you have a birdwatching club in Buffalo, New York. You’ve developed a great site with loads of original content, bunches of articles, and your members visit regularly. The two things that you and other members talk about regularly are binoculars and digital cameras. This is what you could do…

    Craigslist is America’s garage sale. If you don’t live in America, I’m sure something like this is in your region. Craigslist offers RSS feeds on each and every page. Here’s how the birdwatching club could benefit from that.

    First – create a page template. From your WordPress theme directory, download “single.php” (or the theme template that creates post pages) to your desktop. Open it in Notepad or any text editor, and add the following lines of code to the top:

    /* Template Name: Craigslist Template */ ?>

    This is the tricky part, because each and every theme is different. You need to look for the following block of code (which is what prints the page content out):

    <div class="entry">
    <?php the_content(__('Read more &raquo;')); ?>
    </div>

    Right after those lines (or “the loop” in your template, you want to copy and paste this code:

    <?php include_once(ABSPATH . WPINC . '/rss.php');
    wp_rss('http://example.com/rss/feed/goes/here', 5); ?>

    That code comes from this page in the WordPress Codex. WordPress has a built in “RSS Parser” that will read any RSS feed and spit out a list of links is list ordered fashion to a page. So, if you visit the Buffalo Craigslist Photo page, you’ll find at the bottom of the page a little orange RSS icon. Click on that link, and then copy the URL, and paste it over the example URL in your template. The number (20) that comes after the URL is the number of items from the RSS feed to parse and display. Save the template, and upload it back to your theme directory of your WordPress blog.

    In your WordPress Dashboard, go to “Write -> Page”. Type some original content in the box, and scroll down to the bottom (in WordPress 2.5, on the sidebar in <2.5) and select “Craigslist Template”. Title your page “Craigslist”, and then save and publish the page. Now if you go to www.yourblog.com/craigslist you should see a listing of things from craiglist with your original content on top.

    Look what you did, now the Buffalo Birdwatchers Club won’t can look at photo equipment right on the member web site without having to go to Craigslist unless they see an item they like. You can add multiple feeds to the same page, just copy and paste that code block in multiple times with different RSS feed URL’s. Just remember, the more your add, the longer they take to parse, and the longer the page will take to load. I loaded 6 feeds @ 20 items per feed, and the page took about 20 seconds or so to load.

    This Craigslist example is just that – an example. If you want to see how this looks in realtime, look at this Craiglist RSS example I just built. You could use RSS feeds from just about anything, digg, google news – any site that has a feed. As long as you’re only using headline feeds and not stealing content – nobody should ever think you’re plagiarising them in any way, you’re sending them traffic. In your template file, before you parse the feeds add a few paragraphs of original content about what they user might find (on Craigslist – or whatever) and now you have a page with ever changing (daily) content, AND orignal content that google can index!

    Now, how do you monetize this? Well, use your noggin and add some affiliate banners, adsense, or other items above, below, or in your sidebar. There is a better way to monetize without using these though…

    eBay has RSS feeds – don’t they?  All you have to do is add your affiliate code to an eBay RSS feed, and you could use it instead of the Craigslist feed for a list of eBay items, and every time someone clicks, bids, and buys an auction you profit! First you have to be a member of the eBay Partner Network (EPN). Once logged in go to “Tools->Widgets->RSS Feed Generator”. Then just enter in what you’re looking for. Like Craigslist, you can “geo-target” what you want by scrolling down and checking “Items within 50 miles of xxxxx zip code”. Then click “search” and the page you get should be auctions for only that area. Again, scroll to the bottom of the page and see the orange RSS icon. Click on it and copy the URL and use that as the URL in the code block in your template, save the page now your blog page will list eBay auctions! The difference between these listings and Craigslist is that you profit from each won auction click on these.

    I’ve just given you a few ideas, the sky’s the limit with these. You could probably do the exact same thing with Amazon. Now, there’s one thing I didn’t tell you, often people want to know how to take an RSS feed an automatically create blog posts from the feed and publish them, kind of like what’s called an “auto-blog”. Let me state first that there are very few legit reasons to do this, because of duplicate content issues in google, etc. Most people want to use this to try and create quick spammy blogs with no original content, but there are (just a very few) legit reasons to want to create posts from an RSS feed (like doing a blogroll type page for members of a larger community). You can do that easily (and freely) with RadGeek’s Feed WordPress Plugin.

    Now, get hacking, come back to comment and tell me what you’ve come up with!

  • Leave a Comment
  • Learn How to Secure Your WordPress Blog

    We hear almost every day about bloggers getting their login information comprimised.  Are you one of the many people that are growing increasingly concerned about their blogs security?

    If you are looking up ways to beef up the security of your WordPress blog, Make Tech Easier has posted a great article about 11 ways to secure your WordPress blog.  The post includes a few security tips we’ve already covered in past posts, plus a bunch of other great tips.

    Here is what information the post covers:

    • Encrypt your Login
    • Stop Brute Force Attack
    • Use a Strong Password
    • Protect your WP-Admin Folder
    • Remove WordPress Version Information
    • Hide your Plugins Folder
    • Change your Login Name
    • Upgrade to the Latest Version of WordPress and Plugins
    • Do a Regular Security Scan
    • Backup your WordPress Database
    • Define user Privilege

    Click over to get descriptions, plugin information and more!

    Got any tips to add?  Let us know in the comments below!

  • Leave a Comment
  • 6 WordPress Tips and Tricks

    This guest post was written by Hayes Potter, the 13 year old web developer and designer that gives webmasters tips on protecting their website from common hacking techniques. If you have webmaster or WordPress knowledge and are interested in writing a post for Hack WordPress, please contact us.

    Adding A Side Blog

    1. Pick a desired category and add it in your blog (i.e. category “Side Blog”)
    2. Implement the following code into your “Functions.php” in your theme’s directory:

    <?php
    function asidesFilter($query) {
    if($query->is_feed || $query->is_home || $query->is_ search) {
    $query->set(’cat’, ‘-115?);
    }return $query;}
    >add_filter(’pre_get_posts’, ‘asidesFilter’);>
    ?>

    (Notice the number 115 is the category ID number for the chosen category. Yours will be different.)

    3. Then add the following into your “sidebar.php” file in your theme’s directory:
    <h3>Side Blog
    <a href=”FEED URL” title=”My Side blog's RSS feed.”>
    <img src=”RSS IMAGE URL” alt=”RSS” style=”position: relative; left: 0;” />
    </a>
    </h3>
    <?php query_posts(’cat=115&showposts=2?); ?>
    <?php if(have_posts()) : ?>
    <?php while(have_posts()) : the_post(); ?>
    <div class=”aside_post”>
    <?php the_content(’Continue reading...’); ?>
    </div>
    <?php endwhile; ?>
    <span class=”aside_archive_link”>
    <a href=”CATEGORY URL” title=”More asides.”>Archives</a>
    </span>
    <?php else : ?><p>Sorry, the side blog is having a little trouble.</p>
    <?php endif; //if you delete this the sky will fall on your head ?>

    Enhancing Your “Read More” Link

    1. Open your “index.php” or file and find this line:
      <?php the_content(__(’Read more’));?>
    2. replace it with this one:
      <?php the_content(”Continue reading ” . the_title(”,”,false), 0); ?>

    Enhancing Your “Comments” Link

    1. Open your index.php, archive.php, and single.php and find this line:
      <?php comments_popup_link(’Leave a Comment’, ‘1 Comment’, ‘% Comments’); ?>
    2. Replace it with this one:
      <?php comments_popup_link(__(’No comments on ‘ . the_title(”,”,false)),
      __(’One comment on ‘ . the_title(”,”,false)), __(’% comments on ‘. the_title(”,”,false))); ?>

    Random Tip #1

    Do NOT use the following search code in the
    “search.php” file in your theme’s directory :
    <?php echo $_SERVER [’PHP_SELF’]; ?>
    Nobody should be allowed to search your entire server right?

    Use this instead:

    <?php bloginfo (’home’); ?>

    Random Tip #2

    Yet another bad code used in title tags or search templates:
    <?php echo $s; ?>
    as it allows some harmful Sql injections =(.

    Use this instead:
    <?php echo wp_specialchars($s, 1); ?>

    Random Tip #3

    Block search robots from your archive page by preventing the indexing:
    <?php if(is_archive()) { ?><meta name=”robots” content=”noindex”><?php } ?>
    Paste it anywhere in the “Header.php” file of your current theme’s directory in the <head> tags.

    Hope this helps. Thanks for reading and have a wonderful day!

  • Leave a Comment
  • Top 5 WordPress Navigation Menu Tutorials

    Navigation menu is a really important part of a website, both visually and functionally. Though, I noticed that most blogs use a really simple navigation menu. A simple menu can be good sometimes, but if you’re looking for something more sophisticated, I’m pretty sure you’re going to enjoy this list.

    Here’s 5 really cool tutorials to help you create a stunning navigation for your WordPress blog.

    Creating Two-Tiered Conditional Navigation in WordPress


    Which WordPress user doesn’t know Darren Hoyt, the creator the free magazine theme Mimbo Magazine ? In this great tutorial, Darren explains how to create a professional two-tiered navigation menu. Source

    How To: Making a Categories Drop-Down Menu


    This was my first post on Hack WordPress, and seems like you guys enjoyed it. In this tutorial, I explain how to create a navigation bar with a category drop-drown menu. Source

    Adding a navigation bar to the default kubrick theme


    The default “Kubrick” theme is probably the most used WordPress theme. Though, I think it should be better with a navigation bar. Hopefullt, this tutorial is here to help! Source

    WordPress: “Magazine style” Horizontal dropdown menu


    One of my last tutorials, published on my blog CatsWhoCode. This how-to explain how you can create an horizontal dropdown menu. Source

    Using Sliding Doors with WordPress Navigation

    This sliding doors CSS hack allows you to create sophisticated tabs for your navigation bar. Sadly, WordPress core functions wp_list_pages() and wp_list_categories() don’t allow you to add the required span tag to use this technique.
    This tutorial will show you how to bypass this limitation by using a hack, and then you’ll be ready to enjoy sliding-doors for your WordPress navigation! Source

    Any other navigation tutorial that should be in the list? Leave us a comment below!

  • Leave a Comment