Dynamically highlight current page

October 20, 2008

The function used to create a list of published pages, wp_list_pages(), automatically add a class current_page_item to the list item corresponding to the page you’re viewing. You just have to add the .current_page_item class to your style.css file: /* Style the list element */ li.current_page_item{ background:#eee; color:#777; } /* Style the link element */ li.current_page_item a{ text-decoration:underline; }  Read More →

Display the total number of posts on your WordPress

October 20, 2008

Wouldn’t it be nice to be able to display the total number of posts published on your WordPress blog? WordPress don’t have a function to do that by default, but happilly this hack is here to help. Here’s the code: We’re using the $wpdb object to make a custom query to WordPress database: $numposts = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_status = 'publish'"); if (0 < $numposts) $numposts = number_format($numposts); Right now, the $numposts variable contains the total number of posts.... [Read the full story]

Display one full post and three excerpts

October 20, 2008

To achieve this, we’ll use a simple WordPress loop. The only thing we have a to add is a variable (here named $count) which will count how many posts are listed. Here’s the code. Paste it instead your current WP loop and customize it a bit to make it fit your needs. <?php if (have_posts()) : ?> <?php $count = 0; ?> <?php while (have_posts()) : the_post(); ?> <?php $count++; ?> <?php if ($count < 2) : ?> <?php the_content() ?> <?php else : ?> <?php... [Read the full story]

Protect your WordPress blog from hotlinking

October 20, 2008

The first thing to do is to create a small image saying something like “Please do not hotlink from my server“. and upload it on your blog server. Then, we’ll have to edit the .htaccess file, located in your WordPress blog root directory. When modifying .htaccess, always create a backup. Append this code to your .htaccess: RewriteEngine On #Replace ?mysite\.com/ with your blog url RewriteCond %{HTTP_REFERER} !^http://(.+\.)?mysite\.com/ [NC] RewriteCond %{HTTP_REFERER} !^$ #Replace /images/nohotlink.jpg with your “don’t... [Read the full story]

Display wordpress today’s posts

October 20, 2008

If you provide a lot of posts per days, it can be nice to display only today’s posts on a separate page. To achieve this, we’ll use the php date() function, and the WordPress query_posts() function. Paste the following code where you want today’s posts to be displayed: $current_day = date('j'); query_posts('day='.$current_day); if (have_posts()) : while (have_posts()) : the_post(); ?> // WordPress loop endwhile; endif; ?>  Read More →

Page 6 of 9« First...«45678»...Last »