Support » Themes and Templates » the_content inside menu

  • Hi!

    I’m creating my own template right now, but i don’t know how the handle the_content inside a menu item.

    I’ve my content written in a page and i want to display the content inside te menu, let me explain:

    $('li.current-menu-item a').after('<?php if(have_posts()):while(have_posts()):the_post();the_content();endwhile; endif;?>');
      <li><a href="#">Menu item 1</a></li>
      <li class="current-menu-item"><a href="#">Menu item 2</a><?php the_content();?></li>

    I’ve written a jquery script, but i can’t add the_content using .after in jquery.

Viewing 6 replies - 1 through 6 (of 6 total)
  • After hours of searching and just aksing my question here, i’ve found a solution, but i’m not sure if it’s the corrent way. I render my content using the_content, after that i use appendTo to move the content to my current-menu-item.

    Did you nest this in a loop?

    Yes, i’ve nested the standard wordpress loop inside of the jquery. Using appendTo feels a bit like cheating, how do you think about that?

    Why don’t you just echo the content via php? I don’t understand why you’ve decided to resort to jquery here.

    I was thinking about doing something like this as well, but not sure how to incorporate the_content loop inside a menu.

    Is there a chance you’d post a quick example?

    Sure no problem:

    There you go the php part:

    <nav id="menu">
        $args = array(
        'menu'            => 'mainmenu',
         echo'            => true,
        'fallback_cb'     => 'wp_page_menu',
        'items_wrap'      => '<ul>%3$s</ul>',
        'depth'           => 0
        wp_nav_menu( $args );?>
        <div class="description">
    	<?php if(have_posts()):while(have_posts()):the_post();
    	endwhile; endif;?>

    Jquery part:


    dont forget to put it in the document ready statement.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘the_content inside menu’ is closed to new replies.