views:

26

answers:

2

I'm working on a wordpress theme that uses dropdowns for part of the site navigation.

I'm using wp_pages_dropdown and wp_dropdown_categories to output my menus as a dropdown jump menu, this is all good,works fine, but I would like to add a 'home' link to the end of the list of <option>'s

I have been having a go at it - my html/css is spotless but I am not a programmer, can any one help me out, I'd really appreciate it.

<?php wp_dropdown_pages('show_option_none=Select Page');?>

<?php wp_dropdown_categories('show_option_none=Select Category'); ?>

I am thinking that I need to somehow work <?php echo get_option('home'); ?> into it somehow. Any suggestions? thanks.

A: 

I'd say the simplest approach is to just filter the output of wp_dropdown_... and inject your option just before the closing select tag;

function insert_home_in_dropdown($output)
{
    $end = '<option value="whatever">Home</option></select>';
    return preg_replace('#</select>$#', $end, trim($output)); 
}
add_filter('wp_dropdown_pages', 'insert_home_in_dropdown');
TheDeadMedic
Hey, well I went ahead and edited the post-template.php file and tweaked my jump menu js and got it working but yours is a much more elegant solution, thankyou.For clarification for viewers who know even less than me I have added a more detailed explanation below (or possibly above).thanks TDM, thats really excellent.
theothersimon
A: 

My code looks like this, and in my functions.php code I edited the value to be 0.

    var dropdownf = document.getElementById("page_id");
                function onPageChange() {
                if ( dropdownf.options[dropdownf.selectedIndex].value > 0 ) {
                location.href = "<?php echo get_option('home'); ?>/?page_id="+dropdownf.options[dropdownf.selectedIndex].value;
                    }

                if ( dropdownf.options[dropdownf.selectedIndex].value == 0 ) {
                location.href = "<?php echo get_option('home'); ?>"; // this give the href to the home link 
                    }

                }
                dropdownf.onchange = onPageChange;
theothersimon