Make your wordpress new posts stands out

December 8, 2008

Why not giving a special style to the posts published less than 24 hours ago, to let your readers know about the fact they’re new? Here’s a simple code to do it. Edit your index.php file and look for the loop. Replace it with that one: The following code will add the css class new if the post was published less than 24 hours ago. <?php if (have_posts()) : ?> <?php while (have_posts()) : the_post(); ?> $currentdate = date('Y-m-d'); $postdate = get_the_time('Y-m-d'); if ($postdate==$currentdate)... [Read the full story]

Integrate files on your wordpress blog header

December 7, 2008

When developping a WordPress plugin or widget, you sometimes need to add files as such as CSS or Javascript in the theme header. But how to do it when you can access the theme file? Here’s a simple way to add anything in the blog header without editing header.php. The principe is simple: You first got top create a function that will simply print the required files. Then, you got to hook it to the wp_head() WordPress function, by using the add_action() function. function GetLastPostName_head() { echo '<script type="text/javascript"... [Read the full story]

Access wordpress post data outside the loop

December 6, 2008

How he can access post data outside the loop? paste the following function on the functions.php file from your theme. This function takes a singles argument, which is the ID of the post you’d like to access data. It will return an array, containing post title, date, content, author id, post id, etc. function get_post_data($postId) { global $wpdb; return $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE ID=$postId"); } To use the function, use the following anywhere on your theme files: <?php $data =... [Read the full story]

Allow HTML in wordpress user profiles

December 5, 2008

Do you run a multi-author blog? If yes, you’re probably upset to be unable to use any html in user profile. Happilly, here’s a little recipe to allow html in user profiles. To be able to use html in user profiles, simply append the following line of code to the functions.php file from your theme. (Create that file if it doesn’t exists) remove_filter('pre_user_description', 'wp_filter_kses'); That’s all, authors are now allowed to use html in their profiles  Read More →

Easily get the value of a wordpress custom field

December 4, 2008

Nowadays, most modern WordPress themes uses custom fields, to display a thumbnail near the post excerpt, or for adding any other kind of data. Here’s a custom function to easily get any custom field value. Here’s the function. You have to paste it on your theme functions.php file. If your theme doesn’t have a file named functions.php, create one. First, we use the php function_exists() function to make sure the get_custom_field_value function is defined on our theme. If it is, we use it. The first argument is the custom... [Read the full story]

Page 6 of 7« First...«34567»