Advertisement
MoonWatch

Untitled

Jan 23rd, 2014
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.24 KB | None | 0 0
  1. <?php
  2. add_filter( 'wp_get_nav_menu_items', 'cpt_archive_menu_filter', 10, 3 );
  3. function cpt_archive_menu_filter( $items, $menu, $args ) {
  4.     /* alter the URL for cpt-archive objects */
  5.  
  6.     $menu_order = count($items); /* Offset menu order */
  7.    
  8.     // We'll reorder all items and add new ones, so we want to have an independent counter
  9.     $curr_order = 0;
  10.     $new_items = array();
  11.     foreach ( $items as &$item ) {
  12.         $item->menu_order = $curr_order;
  13.         $new_items[] = $item;
  14.         $curr_order ++;
  15.  
  16.         if ( '##post##' == $item->title ) {
  17.             $item->url = get_bloginfo('url') .'/growing-new-ideas/';
  18.             $item->title = 'Growing New Ideas';
  19.  
  20.             foreach ( get_posts( 'post_type=projects&showposts=6&orderby=menu_order&order=asc' ) as $post ) {
  21.                 $post->menu_item_parent = $item->menu_item_parent;
  22.                 $post->post_type = 'nav_menu_item';
  23.                 $post->object = 'custom';
  24.                 $post->type = 'custom';
  25.                 $post->menu_order = $curr_order;
  26.                 $post->title = $post->post_title;
  27.                 $post->url = get_permalink( $post->ID );
  28.                 // Add a custom class - you can use this to indent the item, or add special styles
  29.                 $post->classes = array( 'project-link' );
  30.                 /* add children */
  31.                 $new_items[] = $post;
  32.                 $curr_order ++;
  33.             }
  34.         }
  35.     }
  36.  
  37.     return $new_items;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement