Guest User

Untitled

a guest
Jan 22nd, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. function new_nav_menu_items($items) {
  2. $items = "";
  3. $args = array(
  4. "post_type" => "page",
  5. "order" => "ASC",
  6. "orderby" => "menu_order"
  7. );
  8. $the_query = new WP_Query($args);
  9.  
  10. if($the_query->have_posts()):
  11. while($the_query->have_posts()):
  12. $the_query->the_post();
  13. $items .= '<li><a href="#post-'. get_the_ID() .'">' . get_the_title() . '</a></li>';
  14. endwhile;
  15. else:
  16. echo "";
  17. endif;
  18.  
  19. return $items;
  20. }
  21.  
  22. add_filter("wp_nav_menu_items", "new_nav_menu_items");
  23.  
  24. function new_nav_menu_items( $items, $args ) {
  25. if ( $args->menu == 'primary' ) {
  26. $items = "";
  27. $args = array(
  28. "post_type" => "page",
  29. "order" => "ASC",
  30. "orderby" => "menu_order"
  31. );
  32. $the_query = new WP_Query( $args );
  33. if ( $the_query->have_posts() ):
  34. while( $the_query->have_posts() ):
  35. $the_query->the_post();
  36. $items .= '<li><a href="#post-' . get_the_ID() . '">' .
  37. get_the_title() . '</a></li>';
  38. endwhile;
  39. else:
  40. echo "";
  41. endif;
  42. }
  43. return $items;
  44. }
  45. add_filter( "wp_nav_menu_items", "new_nav_menu_items" );
Add Comment
Please, Sign In to add comment