wedocs icon indicating copy to clipboard operation
wedocs copied to clipboard

How to add h2 submenus to dynamic navigation.

Open meteormanaged opened this issue 9 years ago • 5 comments

Hello, I'm attempting to sort through the code to see where the dynamic sidebars are generated so that I can work towards an option for submenus for lesser headings and a true TOC kind of layout.

Any pointers or directions?

meteormanaged avatar May 06 '15 14:05 meteormanaged

+1

imsoftware avatar Jul 01 '15 22:07 imsoftware

Hi meteormanaged, it's located in /templates/content-single.php

You could just change the h1 to h2 there, on the right places (or add them as extra's)

<?php while (have_posts()) : the_post(); ?>
    <article <?php post_class( 'row' ); ?>>

        <?php
            $content = get_the_content();
            $content = apply_filters( 'the_content', $content );
            $content = str_replace( ']]>', ']]&gt;', $content );

            preg_match_all( "/<h2>(.*?)<\/h2>/si", $content, $matches );
            list( $with_tags, $without_tags) = $matches;

            if ( $with_tags ) {
            ?>
            <div class="col-md-4 col-lg-3 hidden-xs hidden-sm">
                <div class="bs-sidebar hidden-print affix">
                    <ul class="nav bs-sidenav">
                        <?php
                        foreach ($without_tags as $link_text) {
                            $slug = sanitize_title_with_dashes( $link_text );

                            printf('<li><a href="#%s"><i class="fa fa-chevron-right pull-right"></i> %s</a></li>', $slug, strip_tags( $link_text ) );
                        }
                        ?>
                    </ul>
                </div>
            </div>
            <?php } ?>

            <div class="<?php echo $with_tags ? 'col-md-8 col-lg-9' : 'col-md-12'; ?>">
                <div class="entry-content">
                    <header>
                        <h1 class="entry-title"><?php the_title(); ?></h1>
                    </header>
                    <?php
                    foreach ($without_tags as $link_text) {
                        $slug = sanitize_title_with_dashes( $link_text );
                        $replace = sprintf('<div class="spy-item" id="%s"></div>', $slug );
                        $replace = $replace . '<div class="page-header"><h2 class="section-title">' . $link_text . '</h2></div>';

                        $content = str_replace("<h2>$link_text</h2>", $replace, $content);
                    }

                    echo $content;
                    ?>
                </div>

status201 avatar Sep 06 '15 14:09 status201

Hey, thanks. Didn't quite have my feet wet when I asked.

Mike Kozak [email protected]:[email protected]

On Sep 6, 2015, at 10:44 AM, status201 <[email protected]mailto:[email protected]> wrote:

Hi meteormanaged, it's located in /templates/content-single.php

You could just change the h1 to h2 there, on the right places (or add them as extra's)

<article <?php post_class( 'row' ); ?>>
    <?php
        $content = get_the_content();
        $content = apply_filters( 'the_content', $content );
        $content = str_replace( ']]>', ']]&gt;', $content );

        preg_match_all( "/<h2>(.*?)<\/h2>/si", $content, $matches );
        list( $with_tags, $without_tags) = $matches;

        if ( $with_tags ) {
        ?>
        <div class="col-md-4 col-lg-3 hidden-xs hidden-sm">
            <div class="bs-sidebar hidden-print affix">
                <ul class="nav bs-sidenav">
                    <?php
                    foreach ($without_tags as $link_text) {
                        $slug = sanitize_title_with_dashes( $link_text );

                        printf('<li><a href="#%s"><i class="fa fa-chevron-right pull-right"></i> %s</a></li>', $slug, strip_tags( $link_text ) );
                    }
                    ?>
                </ul>
            </div>
        </div>
        <?php } ?>

        <div class="<?php echo $with_tags ? 'col-md-8 col-lg-9' : 'col-md-12'; ?>">
            <div class="entry-content">
                <header>
                    <h1 class="entry-title"><?php the_title(); ?></h1>
                </header>
                <?php
                foreach ($without_tags as $link_text) {
                    $slug = sanitize_title_with_dashes( $link_text );
                    $replace = sprintf('<div class="spy-item" id="%s"></div>', $slug );
                    $replace = $replace . '<div class="page-header"><h2 class="section-title">' . $link_text . '</h2></div>';

                    $content = str_replace("<h2>$link_text</h2>", $replace, $content);
                }

                echo $content;
                ?>
            </div>

Reply to this email directly or view it on GitHubhttps://github.com/tareq1988/wedocs/issues/13#issuecomment-138090591.

meteormanaged avatar Sep 06 '15 14:09 meteormanaged

@status201 @meteormanaged

Will the above display this as it is here? I can't seem to figure out the submenu's. http://docs.wedevs.com/docs/wp-user-frontend-pro/getting-started/plugin-installation/

BigIron5 avatar Jan 08 '16 23:01 BigIron5

No @BigIron5, the code above will show only 1 navigation level, made from the H2's in your page/post. Like this: http://dev201.nl/php7-twice-as-fast-half-the-memory-consumption-and-spaceships/

I think Tareq made a 2 level navigation in the "develop" branch: https://github.com/tareq1988/wedocs/tree/develop

status201 avatar Jan 13 '16 13:01 status201