|
|
Want to know more about Packt's Article Network? Interested in contributing your article ideas? Please visit our FAQ for more information. See More BROWSE
All Titles WordPress Web Services SOA BPEL Web Graphics & Video Web Development RAW Portugues, Espanol, Italiano, French PHP/MySQL Oracle Open Source Networking & Telephony Moodle Microsoft & .NET Linux Servers jQuery Joomla! JBoss Java e-Learning e-Commerce Dynamics Drupal CRM Cookbook Content Management Beginner Guides Architecture and Analysis AJAX Future Titles Recently Published Titles In this two-part article by Jean-Baptiste Jung, we will see what can be done for enhancing user experience and making your WordPress blog a better place. In this part, you will learn:
See More |
Enhancing User Experience with WordPress 2.7(Part 2)
Creating a drop-down menu for your categoriesDo you use a lot of categories along with their sub-categories? If so, using a drop-down menu is a nice way to categorize content, especially on larger sites. However, giving a quick access to the categories or sub-categories to readers can become a pain. Over the years, the drop-down menu has become very popular on the Internet. In this recipe, I'm going to show you how to create your own drop-down menu for your WordPress blog categories. Getting readyThe menu you are going to create will first list your pages, and then at last a tab called Categories will obviously list your categories. This menu is achieved only with XHTML and CSS. No JavaScript is needed (unless you want to maintain compatibility with it commonly referred to as IE6) to ensure the best SEO possible for your WordPress blog.
How to do itIn order to make this recipe more readable, I have divided it in 3 steps—the PHP and the HTML, the CSS, and the JavaScript for IE6 compatibility. Step 1: PHP and HTMLOpen the header.php file from your theme and paste the following code where you'd like your drop-down menu to be displayed: <ul id="nav" class="clearfloat"> The purpose of this code is to make a list of all our pages and subpages, as well as a last list element named Categories. When a reader hovers on one of the top-level menu, the subpages (or categories) are displayed. Step 2: The CSSOpen the style.css file from your theme and paste the following styles: #nav{You may have to tweak this code a bit to match up to your blog's look and feel, for example, by adjusting colors. Once you are finished, simply save the file. Step 3: Optional JavaScriptI'm not going to teach you something new here since, Internet Explorer 6 is a totally obsolete, crappy, and buggy browser. Sadly, many peoples are still using it and you may want to make sure that your blog is IE6 compliant. Modern browsers as such as Safari, Firefox, Opera, and even Internet Explorer 7 will not have any problem with the :hover pseudo-class on li elements. But you guessed it, it is asking too much from the IE6.
That's all! Your blog now has a very professional looking drop-down menu. How it worksAs IE6 cannot deal with :hover pseudo-classes on <li> elements, this small piece of code automatically ads a new CSS class, named sfhover to <li> elements when they are hovered over. When the mouse goes out of the top level element, a new function is executed, using a regular expression to remove the sfhover class. There's more...Now that I have shown you're the principle of creating a drop-down menu, you can use what you have just learned to create various kinds of menus. As an example, let's see how to re-use the previous code and create a very nice horizontal drop-down menu. Creating a horizontal drop-down menuAs you'll notice by observing the code, there's a lot of similar things between this code and the one that you saw earlier. Part 1: PHP and HTMLSimply copy this code where you want the menu to be displayed, for example, in your header.php file: <ul id="nav2" class="clearfloat"> Part 2: The CSSIn modern drop-down menus, CSS are a very important part. Indeed, in this example it is CSS that display our menus horizontally. Paste the following code in your style.css file: #nav2{Once you have added theses lines to your style.css file and saved it, your WordPress blog will feature a very cool horizontal menu for displaying your categories. Part 3: (Optional) JavaScriptAs usual, if you want to maintain backward compatibility with Internet Explorer 6, you'll have to use the Javascript code that you have already seen in the previous example. WordPress 2.7 Cookbook
Adding a breadcrumb to your themeWhen you're looking for a way to improve your blog's usability, a breadcrumb is definitely an option to consider. According to Wikipedia, Breadcrumbs typically appear horizontally across the top of a webpage, usually below any title bars or headers. They provide links back to each previous page that the user navigated through in order to get to the current page, for hierarchical structures usually the parent pages of the current one. Breadcrumbs provide a trail for the user to follow back to the starting/entry point of a website. Generally, a greater than (>) is used as hierarchy separator, although other glyphs can be used to represent this.
Getting readyThere are many different solutions available in order to implement a breadcrumb on your WordPress blog, such as hacks and plugins. In this recipe, I'm going to show you how to use the Yoast Breadcrumb plugin, that in my opinion, is the best solution available. But don't worry if you're a hack fanatic, or if you're just curious to know about how breadcrumbs work; I'll also be explaining how to create a breadcrumb without using a plugin. How to do itUsing Yoast Breadcrumbs is definitely easy. Follow these simple steps to install and configure it on your own blog:
The Yoast Breadcrumb plugin allows you to print your breadcrumb directly on your blog page or post. You may also want to get the result only as a PHP variable for further tweaking. Getting the breadcrumb as a PHP variableThe following code will create a $breadcrumb variable that will contain your breadcrumb: <?php if ( function_exists('yoast_breadcrumb') ) {How it worksThe Yoast Breadcrumb plugin takes three arguments. Let's see in detail what these are:
The Yoast Breadcrumbs plugin works by getting information from your blog, such as the post (or page) name, the category where the post belongs to, and the blog homepage URL. This can be seen in the following example: Home > Category name > Sub-Category name (if any) > Post name The Yoast Breadcrumbs plugin will then dynamically create a clickable breadcrumb, which allows visitors to click on any of the links to go on to the selected section of your blog. For example, if a visitor clicks on the Category name link in the above Breadcrumb, he or she will be redirected to that category page. Clicking on Home will lead him or her to your blog homepage. There's more...As we have already discussed, it can sometimes be better to use a hack instead of a plugin. Now that we saw how to easily add a breadcrumb to your WordPress blog by using the excellent "Yoast breadcrumbs" plugin by Joost de Valk, let's see how we can create a breadcrumb on our own. Using a hack to display breadcrumbsOne more time, WordPress conditional tags will be very useful. With them, we'll be able to know easily if the page displayed by a visitor is an article, a page, or a category archive. Then, we'll have to use the right functions to show the site's hierarchy. Nothing difficult here, WordPress has all of the functions that we need to get links to the homepage, articles, and single pages. Simply paste this code in the functions.php file of your theme: function the_breadcrumb() {Now, when you'll want to display breadcrumbs, simply use the_breadcrumb() function: <?php the_breadcrumb(); ?>
Displaying related postsGuess what your readers will do when they finish reading one of your posts? 90% of them simply leave without even trying to see if you have any interesting related articles. It is a well known fact that the typical Internet user doesn't spend a lot of time on a web site: however, a few tips can increase your chance to have longer visits and maybe new RSS subscriptions. One of them is to display related posts at the end of your articles.
Getting readyThe easiest way to display related posts on your WordPress blog is to use the "WordPress Related Posts" plugin (Version 1.0). This plugin is compatible with WordPress 2.3 and later versions. You can use it with any theme. How to do itTo display related posts, follow these simple steps:
Available options are: How it worksThe "WordPress Related Posts" plugin executes some SQL queries based on tags. For example, if you tag a post with the cats tag and have two other posts tagged with cats, you can be sure that these two posts will be shown as related in the first post. If the plugin doesn't seem to work properly, the first thing to check would be to make sure that your posts are tagged. Display tabs on your sidebarThere are a lot of things that you can add in your blog sidebar such as Blogroll, Feedburner suscribers, categories, 125*125 pixels ads, and more. The problem is, your sidebar becomes quite lengthy which isn't visually appealing. And to make it worse, not too many people will scroll down your blog to see what is available at the very bottom of your sidebar. Getting readyYou can create a tabbed sidebar by using some custom HTML, CSS, and JavaScript codes. But the easiest solution is to use the "Fun With Sidebar Tabs" plugin, by Andrew Rickmann. The latest version of the plugin is 0.5.4. The plugin author has stopped maintaining it, but the plugin has been tested for its compatibility with WordPress versions up to 2.8. So, there's no particular reason that the plugin will stop working properly for higher versions, but there's no guarantee either.
How to do itThe "Fun With Sidebar Tabs" plugin can be installed easily. Just follow these steps to get started.
How it worksThe "Fun With Sidebar Tabs" plugin adds a new widget-ready sidebar which displays the widgets in it as tabs, instead of a list. It adds a widget and a template tag, so that it can be inserted wherever it needs to be. SummaryWe have learned how to enhance the user experience in a WordPress blog. We have created and added a few very helpful features into our WordPress blog. In this article, we have learned:
If you have read this article you may be interested to view :
WordPress 2.7 Cookbook
About the AuthorJean-Baptiste Jung is a Web developer, Web designer, and blogger born in Paris, France and now living in Wallonia (French-speaking part of Belgium) with his wife and cat. Jean unearthed the World Wide Web in 1998 and started creating web sites three years later. In 2006, while working as a freelance Web developer for a well known French TV channel, Jean started to work with blogs and WordPress. A few months later, he created his first blog. He became immensely passionate about WordPress and launched a blog dedicated to WordPress hacks, http://www.wprecipes.com, which quickly managed to become one of the most popular WP-related web sites over the Internet. Meanwhile, Jean is also an author on some prestigious blogs, such as WpHacks, ProBlogDesign, and Smashing Magazine. Books from Packt
|
TOP TITLES ![]()
In the first part of this two-part article by Jean Baptiste-Jung, we learned about managing a a multi author blog. When you are running a multi author blog, you need to have sufficient content to attract the visitors. In this part we shall learn how glorify your multi-author blog. Specifically, you will learn:
See More |
| ||||||||