WordPress.org

Ready to get started?Download WordPress

Forums

the_content inside menu (7 posts)

  1. DsNL
    Member
    Posted 1 year ago #

    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;?>');
    
    <ul>
      <li><a href="#">Menu item 1</a></li>
      <li class="current-menu-item"><a href="#">Menu item 2</a><?php the_content();?></li>
    </ul>

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

  2. DsNL
    Member
    Posted 1 year 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
    Member
    Posted 1 year ago #

    Did you nest this in a loop?

  4. DsNL
    Member
    Posted 1 year 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
    Member
    Posted 1 year 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
    Member
    Posted 1 year 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
    Member
    Posted 1 year ago #

    Sure no problem:

    There you go the php part:

    <nav id="menu">
     <?php
        $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();
    	    the_content();
    	endwhile; endif;?>
        </div>
    </nav>

    Jquery part:

    $(".description").appendTo("li.current-menu-item");

    dont forget to put it in the document ready statement.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.