How to add ID attribute to each submenu?

In your Walker_N_Menu class’s start_lvl() method, you’re setting the <ul>‘s id to submenu1. You can change this (using, in this example, the $depth parameter passed to start_lvl()) to be unique: function start_lvl( &$output, $depth = 0, $args = array() ) { // Depth-dependent classes. $indent = ( $depth > 0 ? str_repeat( “\t”, $depth ) … Read more

Append a code when at the current page in wp_list_pages()

I would use a custom walker and then extend the Walker_Page::start_el() method, like so: // Based on Walker_Page for WordPress v6.0 // @link https://github.com/WordPress/wordpress-develop/blob/6.0/src/wp-includes/class-walker-page.php#L105-L219 class My_Walker_Page extends Walker_Page { public function start_el( &$output, $data_object, $depth = 0, $args = array(), $current_object_id = 0 ) { /* This checks if the current page in the list … Read more

Querying both pages and posts

Use get_posts() or filter ‘pre_get_posts’ on the front page. Sample code for get_posts(): $my_post_array = get_posts( array ( ‘post_type’ => array ( ‘post’, ‘custom_type’ ) ) ); foreach ( $my_post_array as $post ) { // do something awesome … } There are also parameters for a custom order by meta fields and so on. A … Read more

wp_nav_menu, walker class, categories as classes of li

your walker class is almost perfect for what you need @Gab. instead of line 21: $output .= ‘<li>’; move it down just before line 38 $output .= apply_filters( ‘walker_nav_menu_start_el’ […] and change it to something like $output .= $indent . ‘<li id=”nav-menu-item-‘. $item->ID . ‘” class=”‘. $title . ‘”>’; and you should have the category … Read more

Getting menu items like get_pages

Yes, there is. Use wp_get_nav_menu_items() instead. <?php $items = wp_get_nav_menu_items( $menu, $args ); ?> <?php $args = array( ‘order’ => ‘ASC’, ‘orderby’ => ‘menu_order’, ‘post_type’ => ‘nav_menu_item’, ‘post_status’ => ‘publish’, ‘output’ => ARRAY_A, ‘output_key’ => ‘menu_order’, ‘nopaging’ => true, ‘update_post_term_cache’ => false ); ?> Here is the page on WordPress Codex

custom walker wp menu last element

If you can live without re-creating the menu walker, you can add classes to menu items manually. On the WordPress menu editing screen, click on “Screen Options” and enable “CSS Classes.” Then you’ll be able to add whatever class you want to whichever list item. Creating a custom Walker for something like this will be … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)