Posts by date

Modified Post Function

Posted by The Doctor on Mar 18, 2010 with 1 Comment | Short Link
in Functions
as , , ,

Here is a simple bit of code you can drop into your functions.php file then use in any of your templates where you want to display a short statement telling when a post was last modified.

// Modified Post - requires WordPress version 3.0 or greater
function modified_post(){
  global $wp_version;
  if (version_compare($wp_version, "2.999", ">")) {
    /* If the post date and the last modified date are different display modified post details */
    if ( get_the_date() <> get_the_modified_date() ) {
      echo '<div class="modified-post">'; /* CSS wrapper for modified post details */
      echo 'Last modified by ' . get_the_modified_author() . ' on ' . get_the_modified_date();
      echo '</div><!-- .modified-post -->';
    }
  }
}

Of course, you may have noticed the check for WordPress version 3.0 or greater. This is required as the function get_the_date() on line 6 is currently only found in versions of WordPress starting at 3.0

Once the above code has been added to your functions.php file and you are using a version of WordPress greater than or equal to 3.0 then all you need to do is drop the following line of code inside the loop of the template file you want to display the modified post details on.

<?php modified_post(); ?>

Also included is a CSS class element for easy styling. The code can be easily edited to add more elements, too.

Now, what good is this little bit of code? Have a look around and see it in action.

WordPress 3.0 Navigation Menu Styles

Posted by The Doctor on Mar 17, 2010 with No Comments | Short Link
Last modified by The Doctor on April 15, 2010
in Functions, Tips
as , , , , ,

Let’s jump right in …

Using the default definition from the register_sidebar() function found in ../wp-includes/widgets.php of WordPress version 3.0-alpha 3.0-beta12 (see below):

	$defaults = array(
		'name' => sprintf(__('Sidebar %d'), $i ),
		'id' => "sidebar-$i",
		'description' => '',
		'before_widget' => '<li id="%1$s" class="widget %2$s">',
		'after_widget' => "</li>\n",
		'before_title' => '<h2 class="widgettitle">',
		'after_title' => "</h2>\n",
	);

… and the default Navigation Menu widget, the following CSS style elements are generated:

  • #nav-menu-<widget instance>
  • .widget
  • .widget_nav_menu
  • .widgettitle

… with these elements generated specifically by the wp_nav_menu() function found in ../wp-includes/default-widgets.php of WordPress version 3.0-alpha 3.0-beta12:

  • .menu-<menu name>-container2
  • #menu-<menu name>
  • .menu
  • #menu-item-<unique identifier*>
  • .menu-item-type-<types: page, category, Custom>1
  • .menu-item2
  • .menu-item-type-<post_type, custom, or taxonomy>2
  • .menu-item-object-<page, or category>2
  • .current_page_item
  • .sub-menu1

This is just an initial listing of my observations as of the March 16, 2010 3.0-alpha version of WordPress. Look for future updates; and, please feel free to make note of your own observations below.

Bonus – A suggested addition to style.css for theme developers:

/* WordPress 3.0 Navigation Menu default widget */
.widget_nav_menu .menu {margin: 0;}
.widget_nav_menu .menu li {
  display: block;
  float: none;
  /* text-align: left; */
}
*N.B. – each new menu item generates its own post ID in the WordPress database ‘posts’ table. This appears to be in a similar fashion to post revisions.
    Notes:

  1. Mar 21, 2010
    • menu item type class further defined
    • sub-menu class noted
  2. Apr 15, 2010 (3.0-beta1 updates)
    • additional menu classes defined and/or modified
    • new menu container class noted