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 ... [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]

Embed Adsense anywhere on your posts using shortcode

December 23, 2008

Do you ever wanted to get a total control over the way your adsenses ads are displayed? In the following text, I’m going to teach you how to be able to use adsense only in the post you want and display the ads where you want. To achieve this aim, we just use shortcode of wordpress. First, you have to add the following code to your function.php file. Don’t forget to change the adsense code. function showads() { return 'your adsense code'; } add_shortcode('adsense', 'showads'); Once you saved the functions.php file,... [Read the full story]

Use two or more loops without duplicate wordpress posts

December 23, 2008

How to use multiples loops without having the duplicate wordpress posts? There’s probably many other ways to achieve the same effect. But here’s a pretty nice way to avoid duplicate posts in two or more loops. To avoid wordpress post duplication, we started by creating a php array. And adding the IDs of the posts we get in the first loop to that array: <h2>Loop NO1</h2> <?php $ids = array(); while (have_posts()) : the_post(); the_title(); ?> <br /> <?php $ids[]= $post->ID; endwhile; ?> Now,... [Read the full story]

Page 2 of 7«12345»...Last »