Keith Devon


Tag: WordPress

Cufon visited link color fix

I recently had an issue with the color of visited links when using Cufon. More specifically, I am using the WP-Cufon plugin with WordPress.

The issue I had was that the color I set for the link wasn’t being rendered by Cufon. In firebug it showed that the element color was red, but it was showing as the yellow color I had set as the universal link color.

After fiddling about with this for *ages*, I found the fix. I had checked the ‘Delay-Fix’ box in the plug-in; as soon as I un-checked this box the problem was resolved. I now get a small flicker before the Cufon is rendered, but it’s a small price to pay for being able to select the link color!

I hope that this saves someone some time!

Adding the excerpt function to WordPress pages

The excerpt function that is so useful in WordPress posts, does not come as standard on pages. Luckily, the fix is easy. Add the following code to your functions.php file and voila! Excerpts on wordpress pages.

// add excerpts to pages

function add_page_excerpt_meta_box() { add_meta_box( ‘postexcerpt’, __(‘Excerpt’), ‘post_excerpt_meta_box’, ‘page’, ‘normal’, ‘core’ ); }

add_action( ‘admin_menu’, ‘add_page_excerpt_meta_box’ );

Sorting WordPress Posts Using Surnames

A client recently requested that their ‘Members’ page be sorted by surname and not first name. The lists were generated using the follwing code:

<?php$cat_args = array(
'sort_column' => 'post_title',
'order' => 'ASC',
'parent' => 12);
$categories =   get_categories($cat_args);
foreach($categories as $category) {
echo '<ul id="member"><li><h3>' . $category->name.'</h3></li>';
$post_args = array(
'numberposts' => 50,
'orderby' => 'title',
'order' => 'ASC',
'category' => $category->term_id    );
$posts = get_posts($post_args);
foreach($posts as $post) {	?>
<li><a href="<?php the_permalink(); ?>">
<?php the_title(); ?></a></li>	<?php	}
echo '</ul>';

To sort by surname I created a custom field in the Post Edit screen. The name of the custom field I set to ‘surname’ and I entered the member’s surname in the value field.

I then had to change the PHP code to look for the custom field and sort the list accordingly. I changed the ‘orderby’ => ‘title’, to ‘orderby’ => ‘meta_value’,’meta_key’ => ‘surname’,.

Now the members are sorted by their surnames. Simple! View the code in action here.

Note: If the custom field of ‘surname’ is not given a value then the post title will not display in the list.