Highlight the current category of wordpress

December 29, 2008

Most wordpress readers like to know where they are on a website. To help them knowing what they’re exactly browsing right now, you should definitely highlight the current category. It is very easy to do. When you’re browsing a category, WordPress automatically add a current-cat css class to the <li> element. So the only thing you have to do is to edit your style.css file and add a style for the current-cat class: #nav .current-cat{ background:#999; color:#222; text-decoration:underline; } Now your... [Read the full story]

Make your wordpress title tag SEO friendly

December 29, 2008

SEO is a very important part of your wordpress blog. Because without a good SEO, you’re loosing lots of potential visitors. In this recipe, we will know how to optimise the title of your wordpress blog for a better SEO. Open your header.php file for edition. find the <title> tag, and replace it by the following code:   <title> <?php if (is_home () ) { bloginfo('name'); } elseif ( is_category() ) { single_cat_title(); echo ' - ' ; bloginfo('name'); } elseif (is_single() ) { single_post_title(); }... [Read the full story]

Hide the sidebar on your wordpress blog homepage

December 26, 2008

The sidebar is a very important element of your wordpress, but sometimes, you just don’t want it to be displayed on your wordpress homepage. If you’d like to know how to do, it is simple. To hide your sidebar on your blog homepage, edit the index.php file from your theme and find the code following: <?php get_sidebar(); ?> Replace it by the code following: <?php if (!is_front_page()) { get_sidebar(); } ?>  Read More →

Get post having a specific custom field and a specific value

December 26, 2008

How to get a list of post having a specific custom field and a specific value? Here’s how to do it. we just have to verify if the custom field is set and if its value is the one we expect. If yes, we display the post info. <?php if (have_posts()) : while (have_posts()) : the_post(); $customField = get_post_custom_values("img"); if ( (isset($customField[0])) && ($customField[0] == "myValue") ) { //Custom field have myValue as a value, display info the_title(); ... [Read the full story]

Retrieve images in wordpress post content

December 23, 2008

How to get or count the images contained within the content of a post? To achieve this, simply paste the following code on one of your theme files. It will search for all images contained in the post content, and display it.   <?php if (have_posts()) : ?> <?php while (have_posts()) : the_post(); ?> <?php $szPostContent = $post->post_content; $szSearchPattern = '~<img [^\>]*\ />~'; // Run preg_match_all to grab all the images and save the results in $aPics preg_match_all( $szSearchPattern,... [Read the full story]