Advertisement
Viper007Bond

Untitled

Sep 20th, 2011
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.63 KB | None | 0 0
  1. if ( ! is_admin() ) {
  2.     // Hook in early to modify the menu
  3.     // This is before the CSS classes are calculated
  4.     add_filter( 'wp_get_nav_menu_items', 'replace_placeholder_nav_menu_item_with_latest_post', 10, 3 );
  5. }
  6.  
  7. // Wee long function names! :P
  8. function replace_placeholder_nav_menu_item_with_latest_post( $items, $menu, $args ) {
  9.     foreach ( $items as $item ) {
  10.  
  11.         // Find the placeholder
  12.         if ( '#latestpost' != $item->url )
  13.             continue;
  14.  
  15.         $latestpost = get_posts( array(
  16.             'numberposts' => 1,
  17.         ) );
  18.  
  19.         if ( empty( $latestpost ) )
  20.             continue;
  21.  
  22.         $item->url = get_permalink( $latestpost[0]->ID );
  23.     }
  24.  
  25.     return $items;
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement