I am creating a dynamic custom menu that displays all message links, such as a menu widget in the sidebar of a specific category. It should be dynamic, which means that whenever I make a message in this category, there should be a message on the menu that I did without me to physically drag a new entry into the menu.
Here is my code: (identifier of the category in which I want: 4)
<div class="col-md-4 enigma-sidebar">
<?php if ( is_active_sidebar( 'sidebar-primary' ) )
{ dynamic_sidebar( 'sidebar-primary' ); }
else {
$args = array(
'before_widget' => '<div class="enigma_sidebar_widget">',
'after_widget' => '</div>',
'before_title' => '<div class="enigma_sidebar_widget_title"><h2>',
'after_title' => '</h2></div>' );
the_widget('WP_Widget_Archives', null, $args);
} ?>
<?php
function menu1_loop() {
global $post;
$args = array(
'type' => 'post',
'orderby' => 'date',
'order' => 'ASC',
'hide_empty' => 1,
'include' => '4',
'number' => '',
'taxonomy' => 'category',
);
$categories = get_categories( $args );
foreach($categories as $category) {
$args = array (
'category_name' => 'cat-html',
'order' => 'ASC',
'orderby' => 'date',
);
$query = new WP_Query( $args );
if ( $query->have_posts() ) {
while ( $query->have_posts() ) {
$post.the_permalink();
$post.the_title();
$query->the_post();
}
}
wp_reset_postdata();
}
} ?>
<?php wp_nav_menu( array( 'theme_location' => 'html-menu', 'container_class' => 'enigma_sidebar_widget' ) ); ?>
<?php wp_nav_menu( array( 'theme_location' => 'php-menu', 'container_class' => 'enigma_sidebar_widget' ) ); ?>
</div>
This code does not do what I think should do, here is a picture showing what this means: 
I am not familiar with either WordPress or PHP, so please forgive any stupid mistakes.
source
share