Hot answers tagged

40

The parameter 'items_wrap' for wp_nav_menu() defaults to: '<ul id="%1$s" class="%2$s">%3$s</ul>' This a a template that is parsed with sprintf(): $nav_menu .= sprintf( $args->items_wrap , esc_attr( $wrap_id ) // %1$s , esc_attr( $wrap_class ) // %2$s , $items // %3$s ); The numbered placeholders – %1$s, ...


20

You can't do this with wp_nav_menu, because it outputs list items, and you'll generate invalid markup with your code. Try using wp_get_nav_menu_items() instead. A quick solution for a drop down menu with a custom walker: class Walker_Nav_Menu_Dropdown extends Walker_Nav_Menu{ // don't output children opening tag (`<ul>`) public function ...


9

Here is an example. I have also created a Gist with more generic code. add_action('add_meta_boxes', 'my_custom_metabox'); function my_custom_metabox() { add_meta_box('custom-taxonomy-dropdown','Brands','taxonomy_dropdowns_box','post','side','high'); } function taxonomy_dropdowns_box( $post ) { wp_nonce_field('custom-dropdown', 'dropdown-nonce'); ...


9

Actually, with a little digging this is quite easy to do. WooCommerce has already set up a filter so all you have to do it add a small snippet in your functions.php file. // Modify the default WooCommerce orderby dropdown // // Options: menu_order, popularity, rating, date, price, price-desc function my_woocommerce_catalog_orderby( $orderby ) { ...


6

I downloaded this plugin and took a look and it does work as advertised for me. The function it uses for displaying the page list is: wp_list_pages(array( 'sort_column'=>'menu_order', 'depth'=>'4', 'title_li'=>'', 'exclude'=>$exclude )); ?> Which is very straightforward and does very explicitly order ...


6

You'll need to use get_posts and roll your own drop down. Something like this (somewhere in functions.php): <?php function wpse34320_type_dropdown( $post_type ) { $posts = get_posts( array( 'post_type' => $post_type, 'numberposts' => -1 ) ); if( ! $posts ) return; $out = '<select ...


4

Sorry about that feels a bit weird answering ones own question, but here you go.... Firstly declare the variable: (customcategory) global $userdata; $errors = array(); $title = trim($_POST['wpuf_post_title']); $customcategory = trim($_POST['customcategory']); $content = trim($_POST['wpuf_post_content']); $tags = ...


4

This is what I do: Static Options <select id="<?php echo $this->get_field_id('posttype'); ?>" name="<?php echo $this->get_field_name('posttype'); ?>" class="widefat" style="width:100%;"> <option <?php selected( $instance['posttype'], 'Option 1'); ?> value="Option 1">Option 1</option> <option <?php ...


4

This suppose you have a custom post type "sponsors" and a custom taxonomy "types"... function custom_meta_box() { remove_meta_box( 'tagsdiv-types', 'sponsors', 'side' ); add_meta_box( 'tagsdiv-types', 'Types', 'types_meta_box', 'sponsors', 'side' ); } add_action('add_meta_boxes', 'custom_meta_box'); /* Prints the taxonomy box content */ function ...


4

There are couple of things wrong with your code... when filtering it is not term that gives the ID of the term, but business (in this case), since this is the name you've provided for the drop-down menu. Replace all instances of term with business Taxonomy is not set when filtering. Remove this check from parse_query function. The following worked for ...


4

To change <option value='http://someurl'>item one</option> <option value='http://someurl'>item two</option> <option value='http://someurl'>item three</option> to <option value='http://someurl'>1. item one</option> <option value='http://someurl'>2. item two</option> <option ...


3

WordPress has Custom Navigation Menus built-in. Simply register a theme_location for each menu in functions.php, then go to Dashboard -> Appearance -> Menus to create the custom menu(s), and apply the custom menu(s) to the appropriate Theme Location(s). The rest is a matter of CSS (or jQuery, if you really want to go that route).


3

Here is a quick snippet I use to get started on my projects: The first step is to add some code to the functions.php file. This is what will enable the WordPress Custom Navigation. The controls will be in Appearance>Menu's once your finished. Code for functions.php: <?php add_action( 'init', 'register_my_menus' ); function register_my_menus() { ...


3

You can add new taxonomy with your own metabox since wp 3.8 by meta_box_cb "drop_cat()" - consist of rebuild original core category metabox wp-admin/includes/meta-boxes.php function realty_type() { $args = array( 'show_ui' => true, 'meta_box_cb' => 'drop_cat', ); register_taxonomy( 'realty_type', array( ...


3

A filter called wp_dropdown_pages exists in the wp_dropdown_pages() function. That filter allows you to modify the output of the function. However, for the thing you want to do I would not recommend using this filter since this will apply to all code that calls wp_dropdown_pages(), including plugins. So, one way to approach your situation may be to simply ...


3

It's called a 'Mega Menu', it allows a full HTML control over dropdown elements of a menu. There is a free option here - http://wordpress.org/extend/plugins/jquery-mega-menu/ - and CodeCanyon offers a lot premium and fancy mega menu plugins to be purchased.


3

Yes, we can sort Wordpress posts in different orders, You can do following sorts without installing plugins. sort post by date ( ascending / descending ) Sort post by title (ascending / descending ) Sort post by comment count ( ascending / descending ) -- These are just basic we can do even more using categories and tags etc Wordpress already stores the ...


3

You can use the standard WordPress function, get the dropdown already formatted and solve both problems at once. Like so: define( 'WP_USE_THEMES', false ); require( './wp-load.php' ); wp_dropdown_categories( array( 'child_of' => 0, 'class' => 'postform', 'depth' => 0, 'echo' => 1, 'exclude' => ...


3

You will need to write a custom walker extending Walker_Nav_Menu, more or less like so: class My_Custom_Nav_Walker extends Walker_Nav_Menu { function start_lvl(&$output, $depth = 0, $args = array()) { $output .= "\n<ul class=\"dropdown-menu\">\n"; } function start_el(&$output, $item, $depth = 0, $args = array(), $id = 0) { ...


3

Ok I found a solution thanks to this: Using wp_dropdown_categories in widget options Here is the code I used instead: function form( $instance ) { /* Default Widget Settings */ $defaults = array( 'title' => 'Highlight Category' ); $instance = wp_parse_args( (array) $instance, $defaults ); ?> <!-- Widget Title --> ...


3

As answered by Steven Jones in the comments, I just want to confirm that the key thing is to specify your custom post type's settings to be 'hierarchical' => true, not the hierarchical argument in wp_dropdown_pages function. If you are using a custom plugin like Types or CPT UI, just set the option to true.


3

We can get the categories via get_categories() function (which will get the same categories as wp_dropdown_categories() function), but as array and without the markup. As the value is returned as array, we can loop through the categories and generate the HTML ourself. Usually, we would aim for a structure like this: <select name="categories"> ...


3

I'm surprised it's all that slow but you can remove all but one of the database calls & most of the looping by passing the term data instead of just slugs to my_dropdown_categories() so get_terms() doesn't have to be called, plus a few other improvements (see comments) eg: function my_dropdown_categories( $taxonomy, $current_selected = '', $terms = ...


2

You can use wp_dropdown_categories() to create your dropdown: wp_dropdown_categories(array('taxonomy'=> 'post_tag','hide_empty' => 0, 'name' => 'my_tags')); Update the reason you are getting the term ID is because wp_dropdown_categories sets the ID's as values so instead of just echo'ing it out you need to get the term, something like: $term = ...


2

The solution was very simple! Just use Superfish.js as instructed on http://users.tpg.com.au/j_birch/plugins/superfish/#getting-started Be sure to include superfish, hoverIntent and jQuery in your wordpress. In your custom js script file, something like this works like a charm: $('ul#theidofyourmenu').superfish({ delay: 600, // This will fire ...


2

Well first of all you can use the menu feature in the newer WordPress. First you want to activate the fact that you want to use this feature via your functions.php file. // This theme uses wp_nav_menu() in two locations. register_nav_menus( array( 'primary' => __( 'Primary Navigation', 'your_theme_name' ), 'secondary' => __('Secondary ...


2

if you are using it in a metabox then you really don't need this part: onchange='document.location.href=this.options[this.selectedIndex].value;' So change the select fields to: <select name="event-dropdown"> <option value=""><?php echo esc_attr(__('Select Event')); ?></option> <?php //get saved data ...


2

Same as Matthews, tried it and works like a charm, I think you might have a plugin conflict. Alternatively, check if data is written to DB, but I really don't think that's the case, because the pages work fine


2

You just need to pull the Labels via get_post_type_object(); <?php $args=array( 'public' => true, '_builtin' => false ); $output = 'names'; $operator = 'and'; $post_types=get_post_types($args,$output,$operator); ?> <select id="" name=""> <?php foreach ($post_types as $post_type ) { $label_obj = ...


2

Hello Everyone out there, who are facing difficulty to display the parent and child taxonomies in drop down, i found the solution for the above problem...... edit the code in the functions.php file, before the code was $categories= get_categories('child_of='.$_POST['main_catid'].'hide_empty=0'); now edit the code, like this... $categories= ...



Only top voted, non community-wiki answers of a minimum length are eligible