Advanced styling of the prev/next post links

when you use the ‘previous/next post’ navigation in single posts, you will have noticed that these links appear empty when there is no previous or next post, as for the latest and the first article.

to keep your page design and to style these occurences by showing a special image or text, you can make use of the virtually undocumented wordpress function ‘get_adjacent_post()’.

see this screenshot of the navigation in a single post page:


the example below is done for the default theme, and will show a greyed-out text in the place of the links.

<div class="navigation">
<div class="alignleft">
<?php if(get_adjacent_post(false, '', true)) { echo 'Previous older article: '; previous_post_link('%link'); }
else { echo '<span style="color:#bbb;">"'.get_the_title().'" is the oldest post, no further articles. </span>'; } ; ?>
<div class="alignright">
<?php if(get_adjacent_post(false, '', false)) { echo 'Next newer article: '; next_post_link('%link'); }
else { echo '<span style="color:#bbb;">"'.get_the_title().'" is the latest post: no newer articles. </span>'; } ; ?>

Defining the writing area of the dashboard editor

the first of my upcoming ‘tips and tricks’ – a handy function to style the editor area of your self-hosted wordpress blog or cms:
if you are working on a modern widescreen monitor, but want to restrict the wordpress editor area (your writing paper, so to speak) to the width as it will later show in your blog, here is a tip what to add to functions.php of your theme:

function custom_max_width_editor() {
echo '<style type="text/css"> textarea#content, #content_ifr {
border-right: 1px solid #ddd; }</style>';
add_action('admin_head', 'custom_max_width_editor');

the ‘min-height’ is optional, and will give you a larger writing area to start with.
and the border shows clearly how wide the defined writing area is.
adjust the number values, and enjoy the next level of control over your wordpress.

you might even want to add the predominant background-color of your blog’s content area …

a big thank you to @Purren from the wordpress support forum, who submitted a correction to make it also work for the visual editor.

wp3 has brought the ‘add_editor_style()‘ function which makes the above tip redundant.

for theme independant, more permament changes, the principle can also be turned into a basic plugin; in this example to change the font-size in the html editor:

Plugin Name: Html Editor Font Size
Description: set the font size for the html editor.
License: GPL2
function custom_font_size_html_editor() {
echo '<style type="text/css"> #editorcontainer textarea#content {
font-size: 20px; }</style>';
add_action('admin_head', 'custom_font_size_html_editor');

Highlight the post’s categories in the category list

highlighting the categories of a post in single post view is a useful trick to allow the viewer to find related posts.

there are plugins available which extend the functionality of the standard category widget to do this.

sometimes, however, it can be desirable to have the same feature with a function that you can use like you would use ‘wp_list_categories();’ – exactly with the same arguments.

/* hi_list_categories() to highlight the current categories of a post in single.php;
uses the arguments in the same way as wp_list_categories();
alchymyth 2010 / */
function hi_list_categories($args) {
//following section is extracted from
$defaults = array(
'show_option_all' => '',
'orderby' => 'name',
'order' => 'ASC',
'show_last_update' => 0,
'style' => 'list',
'show_count' => 0,
'hide_empty' => 1,
'use_desc_for_title' => 1,
'child_of' => 0,
'feed' => '',
'feed_type' => '',
'feed_image' => '',
'exclude' => '',
'exclude_tree' => '',
'current_category' => 0,
'hierarchical' => true,
'title_li' => __( 'Categories' ),
'echo' => 1,
'depth' => 0
$r = wp_parse_args( $args, $defaults );
if ( !isset( $r['pad_counts'] ) && $r['show_count'] && $r['hierarchical'] ) {
$r['pad_counts'] = true;
if ( isset( $r['show_date'] ) ) {
$r['include_last_update_time'] = $r['show_date'];
if ( isset( $r['echo'] ) ) {
$echo_or_return = $r['echo'];
} ; $r['echo'] = 0;
if ( true == $r['hierarchical'] ) {
$r['exclude_tree'] = $r['exclude'];
$r['exclude'] = '';
extract( $r );
//end of extracted code
global $post;
// highlighting only for single post view
if(is_single()) :
$categories = wp_get_post_categories($post->ID);
foreach ($categories as $catid) {
$cat = get_category($catid);
$cats[] = $cat->cat_ID;
$cats_list = wp_list_categories( $r );
foreach($cats as $value) {
if(preg_match('#-item-' . $value . '">#', $cats_list)) {
$cats_list = str_replace('item-' . $value . '">', 'item-' . $value . ' current-cat">', $cats_list);
if($echo_or_return == 1) { echo $cats_list; }
else { return $cats_list; } ;
else :
//use default category list if not single post view
wp_list_categories( $args );
} //end of function hi_list_categories();

in the same way, as you would have used ‘wp_list_categories();’ you can now use ‘hi_list_categories();’ which will add the class ‘.current-cat’ to each of the categories of the post in single post view.

Continuous post numbers for your blog

post_numbersif you look at my blog, you may notice that all posts are numbered with a unique number – starting with 1 for the oldest post and increasing continuous for each published post.

how is it done?

with a function that is hooked to some wordpress core actions;

the function takes care of everything:

  • gets a list of all published posts
  • counts through the posts
  • adds or updates the custom field
function updateNumbers() {
/* numbering the published posts: preparation: create an array with the ID in sequence of publication date, /
/ save the number in custom field 'incr_number' of post with ID /
/ to show in post (within the loop) use <?php echo get_post_meta($post->ID,'incr_number',true); ?>
/ alchymyth 2010 */
global $wpdb;
$querystr = "SELECT $wpdb->posts.* FROM $wpdb->posts WHERE $wpdb->posts.post_status = 'publish' AND $wpdb->posts.post_type = 'post' ";
$pageposts = $wpdb->get_results($querystr, OBJECT);
$counts = 0 ;
if ($pageposts):
foreach ($pageposts as $post):
add_post_meta($post->ID, 'incr_number', $counts, true);
update_post_meta($post->ID, 'incr_number', $counts);
add_action ( 'publish_post', 'updateNumbers' );
add_action ( 'deleted_post', 'updateNumbers' );
add_action ( 'edit_post', 'updateNumbers' );

save it to functions.php of your wordpress theme.

anywhere you want to display this post number, use the following line:

<?php echo get_post_meta($post->ID,'incr_number',true); ?>

just be aware that these numbers are not unique numbers ‘for life’ as they will be reallocated when you delete a post, or when you change the post order by changing the publish date.

to trigger the function to generate the custom fields and fill them with the numbers, you need at least to make a new post, edit one post, or delete one post.

PS: the same thing starting with number 1 for the latest post –
different custom field key, hidden.