Display a text or code only if more than X posts are published

February 1, 2009

To achieve this recipe, we’re going to use a cool new function, introduced in WordPress 2.7, and called wp_count_posts(). Paste the following code anywhere on your template: <?php $count_posts = wp_count_posts(); if ($count_posts->publish > 10) { //Your code to be displayed only if more than ten posts have been published } ?> Note that you’ll need to replace 10 by the number of posts which are displayed at the same time on your homepage.  Read More →

Get words count of your wordpress post

January 26, 2009

How to get and display the word count of a wordpress post? The first thing to do is to create the function. Paste the following code on your functions.php file: function count_words($str){ $words = 0; $str = eregi_replace(" +", " ", $str); $array = explode(" ", $str); for($i=0;$i < count($array);$i++) { if (eregi("[0-9A-Za-zÀ-ÖØ-öø-ÿ]“, $array[$i])) $words++; } return $words; } Then open your single.php file and paste the following code: Word count:... [Read the full story]

Manually define to show full post or excerpt on your homepage

January 23, 2009

Do you use excerpts or full posts on your blog excerpts? Personnally, I think they’re both good. The only problem is that you can’t, by default, use both excerpts and full posts on your blog homepage. Here’s a code to do it. On your index.php file, replace your current loop by this one:   <?php if (have_posts()) : while (have_posts()) : the_post(); $customField = get_post_custom_values("full"); if (isset($customField[0])) { //Custom field is set, display a full post ... [Read the full story]

Link to some external resource in wordpress post title

January 16, 2009

Sometimes, you may want to publish a post which only consist of an url pointing to some external resource. As there’s no built-in function to do that in wordpress, let’s create our own.   The first thing to do is to open your functions.php file and paste the following code:   function print_post_title() { global $post; $thePostID = $post->ID; $post_id = get_post($thePostID); $title = $post_id->post_title; $perm = get_permalink($post_id); $post_keys = array(); $post_val = array(); $post_keys... [Read the full story]

Get thumbnails from specific wordpress posts

January 16, 2009

Nowadays, many WordPress users are using a custom field to illustrate their posts with a thumbnails, then how to get the thumbnails related to a specific kind of posts, most commented? To get a list of thumbnails from the most commented post, we have to use a SQL request and some PHP. Paste the following code anywhere on your theme, where you’d like the thumbnails to be displayed. Each thumbnail contains a link to read the associated post. <ul> <?php //The name of custom field you'd like to get, don't forget to... [Read the full story]

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