Redifine wordpress title tag with a custom field

February 1, 2009

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() ) { $customField = get_post_custom_values("title"); if (isset($customField[0])) { echo $customField[0]; } else { single_post_title(); } } elseif (is_page() ) { bloginfo(’name’); echo ‘: ‘; single_post_title(); }... [Read the full story]

Embed CSS in your wordpress posts with a custom field

December 29, 2008

Sometimes, a specific post needs to be styled with some custom css styles. You can directly embed CSS in your post, but that not very clean. In this recipe, we will show you how to embed css in a clean way, by using a custom field. First, open your header.php file and insert the following code between the <head> and </head> html tags:   <?php if (is_single()) { $css = get_post_meta($post->ID, 'css', true); if (!empty($css)) { ?> <style type="text/css"> <?php echo... [Read the full story]

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]

Get wordpress posts having a specific custom field

December 23, 2008

How we can only get posts that have a certain custom field. As far as we know, this question has been asked many times on several blogs and WordPress forums. It is quite simple. What I’ve done is simply using a normal loop (That you can enhance with query_post() for exemple) and then, using a conditional instruction to check out if the post have the esired custom field. <?php if (have_posts()) : while (have_posts()) : the_post(); $customField = get_post_custom_values("img"); if (isset($customField[0]))... [Read the full story]

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 2 of 2«12