This topic has 10 replies, 2 voices, and was last updated 9 years by lopreg.

  • Author
  • #79688
     lopreg
    Participant

    Please, I need help on how to create a drop down jump menu of categories on my site. I need to place it on my site’s header below the main menu.

    #79689
     lopreg
    Participant
    This reply has been set as private.
    #79741
     sharmstr
    Moderator

    Do a google search for code that will produce the menu you want. Then you can inject it into the pages below the menu using this code in your child theme’s functions.php file

    COPY CODE
    
    add_action('kleo_before_content','my_header_menu');
    function my_header_menu() {
        // yourcode here
    }
    
    Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solution

    This support site is not about custom work. If you need custom development please contact cornel@seventhqueen.com

    #79817
     lopreg
    Participant

    After doing a google search, I came across this page http://codex.wordpress.org/Template_Tags/wp_dropdown_categories.

    The issue I am having now is how to properly add the code to the function without breaking the site. Please, pardon me, am not that great with php.
    Here is what I have at the moment which breaks on line 25;
    <?php
    /**
    * @package WordPress
    * @subpackage Kleo
    * @author SeventhQueen <themesupport@seventhqueen.com>
    * @since Kleo 1.0
    */

    /**
    * Kleo Child Theme Functions
    * Add custom code below
    */
    add_action( ‘wp_enqueue_scripts’, ‘load_buddypress_js’ );
    function load_buddypress_js () {
    if (bp_is_group() || is_page( ‘activity’ )) {
    wp_enqueue_script(‘buddypress_query’,plugins_url() . ‘/buddypress/bp-core/js/jquery-query.min.js’,array(“jquery”));
    wp_enqueue_script(‘buddypress_members’,plugins_url() . ‘/buddypress/bp-core/js/widget-members.min.js’,array(“jquery”));
    wp_enqueue_script(‘buddypress_cookie’,plugins_url() . ‘/buddypress/bp-core/js/jquery-cookie.min.js’,array(“jquery”));
    wp_enqueue_script(‘buddypress_scroll’, plugins_url() . ‘/buddypress/bp-core/js/jquery-scroll-to.min.js’, array(“jquery”));
    wp_enqueue_script(‘buddypress_js’,get_template_directory_uri() . ‘/buddypress/js/buddypress.min.js’,array(“jquery”));
    }
    }
    add_action(‘kleo_before_content’,’my_header_menu’);
    function my_header_menu() {
    <li id=”categories”>
    <h2><?php _e( ‘Posts by Category’ ); ?></h2>
    <form id=”category-select” class=”category-select” action=”<?php echo esc_url( home_url( ‘/’ ) ); ?>” method=”get”>

    <?php
    $args = array(
    ‘show_option_none’ => __( ‘Select category’ ),
    ‘show_count’ => 1,
    ‘orderby’ => ‘name’,
    ‘echo’ => 0,
    );
    ?>

    <?php $select = wp_dropdown_categories( $args ); ?>
    <?php $replace = “<select$1 onchange=’return this.form.submit()’>”; ?>
    <?php $select = preg_replace( ‘#<select([^>]*)>#’, $replace, $select ); ?>

    <?php echo $select; ?>

    <noscript>
    <input type=”submit” value=”View” />
    </noscript>

    </form>

    }

    #79837
     sharmstr
    Moderator
    COPY CODE
    
    function my_header_menu() { ?>
    <li id="categories">
    	<h2><?php _e( 'Posts by Category' ); ?></h2>
    <form id="category-select" class="category-select" action="<?php echo esc_url( home_url( '/' ) ); ?>" method="get">
    
        <?php
        $args = array(
            'show_option_none' => __( 'Select category' ),
            'show_count'       => 1,
            'orderby'          => 'name',
            'echo'             => 0,
        );
        ?>
    
        <?php $select  = wp_dropdown_categories( $args ); ?>
        <?php $replace = "<select$1 onchange='return this.form.submit()'>"; ?>
        <?php $select  = preg_replace( '#<select([^>]*)>#', $replace, $select ); ?>
    
        <?php echo $select; ?>
    
        <noscript>
            <input type="submit" value="View" />
        </noscript>
    
    </form>
    </li>
    <?php }
    
    Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solution

    This support site is not about custom work. If you need custom development please contact cornel@seventhqueen.com

    #79843
     lopreg
    Participant

    Thanks a lot for the response. I tried the code but the form didn’t display anywhere on the site.
    If I add only the form code without the function my_header_menu() code, the form display but not positioned in the desired location. Kindly review the code you supplied me. Thanks again.

    #79846
     sharmstr
    Moderator

    Did you delete the add action code? You shouldnt have. I was merely fixing the bad function code you had.

    Keep in mind, this is not supported. I was only showing you how to inject code below the menu. You’ll have to find code and css to make it work and look the way you want.

    Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solution

    This support site is not about custom work. If you need custom development please contact cornel@seventhqueen.com

    #79847
     sharmstr
    Moderator

    And actually, it would be right after the title section. If you want it between the menu and the title section, you’ll have to copy /kleo/page-parts/general-header-section.php to your child theme and put this at the bottom

    COPY CODE
    
    <li id="categories">
            <h2><?php _e( 'Posts by Category' ); ?></h2>
            <form id="category-select" class="category-select" action="<?php echo esc_url( home_url( '/' ) ); ?>" method="get">
    
                <?php
                $args = array(
                    'show_option_none' => __( 'Select category' ),
                    'show_count'       => 1,
                    'orderby'          => 'name',
                    'echo'             => 0,
                );
                ?>
    
                <?php $select  = wp_dropdown_categories( $args ); ?>
                <?php $replace = "<select$1 onchange='return this.form.submit()'>"; ?>
                <?php $select  = preg_replace( '#<select([^>]*)>#', $replace, $select ); ?>
    
                <?php echo $select; ?>
    
                <noscript>
                    <input type="submit" value="View" />
                </noscript>
    
            </form>
        </li>
    Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solution

    This support site is not about custom work. If you need custom development please contact cornel@seventhqueen.com

    #79849
     lopreg
    Participant

    Hi,
    Sorry to bother you. I didn’t actually delete the add action code, I only temporarily tested the form code alone to be sure nothing is wrong with it. Your code actually fixed my bad function code but my form didn’t get to display anywhere on the page. I have also moved the general-header-section.php file to my child’s theme like you suggested but adding the code to the bottom did not still display the form anywhere.
    I suspect something is preventing it from appearing below the menu because when I placed the form code alone in the function.php, it appeared at the top most of the site.

    Please, don’t be upset. I know this is not supported, I am only asking for your help as I couldn’t get help elsewhere.
    Thanks for your anticipated kind response.

    #79850
     sharmstr
    Moderator

    When you copied the file, did you retain the directory path?

    /kleo-child/page-parts/general-header-section.php

    Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solution

    This support site is not about custom work. If you need custom development please contact cornel@seventhqueen.com

    #79851
     lopreg
    Participant

    Wow. You are a life saver! That was actually where I got it wrong. It worked out immediately I created the correct file path you stated above. Thanks and Thanks again for your patience and understanding

Viewing 11 posts - 1 through 11 (of 11 total)

The forum ‘KLEO’ is closed to new topics and replies.

Log in with your credentials

Forgot your details?