the_content inside menu (7 posts)

  1. DsNL
    Posted 3 years ago #


    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.

  2. DsNL
    Posted 3 years ago #

    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.

  3. invot
    Posted 3 years ago #

    Did you nest this in a loop?

  4. DsNL
    Posted 3 years ago #

    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?

  5. invot
    Posted 3 years ago #

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

  6. padams02
    Posted 3 years ago #

    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?

  7. DsNL
    Posted 3 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.