wordpress menu_order no funciona
Frecuentes
Visto 8,989 veces
2
I don't know what is wrong with menu_order but the posts are not displayed as I want. Here is what I mean
I have 3 posts in my blog. Here is how db looks like
id ..... menu_order
56 ..... 2
59 ..... 5
65 ..... 3
index.php (my custom theme)
I want to display only image so here is the code that I use
<?php while ( have_posts() ) : the_post();
$images = get_children(
array( 'post_parent' => $post->ID,
'post_type' => 'attachment',
'post_mime_type' => 'image',
'orderby' => 'menu_order',
'order' => 'DESC',
'numberposts' => 999 )
);
if( $images )
{
$total_images = count( $images );
$image = array_shift( $images );
echo wp_get_attachment_image($image->ID, 'full', 0, array('id' => 'photo'));
}
endwhile; // end of the loop.
?>
The problem is that the posts are displayed in order with id 65,59,56 and not as I expect 59,65, 56
¿Qué hay de malo en esto?
4 Respuestas
3
Use the following code. It will solve your issue
'sort_column' => 'menu_order'
Respondido el 18 de junio de 13 a las 04:06
0
Parece esto menu_order
isn't what you'd think, eg. the order you have chosen on your site custom menu. Instead it's the order you set every page under writing... This is not what I want either so I made this solution:
sort_column=menu_order only sorts pages based on their order in writing not the order you set in view > menus (translated), if you want that you can do like this:
$children = get_pages('child_of='. $topID);
// 'sort_column=menu_order' <-- only sorts by post order in writing mode (page > edit) not the menu order set in view > menus
// wp_nav_menu has what we need, let's sort it the same way.
$options = array(
'container' => '',
'echo' => false,
);
$nav = wp_nav_menu($options);
$nav = strip_tags($nav);
$nav = str_replace("\r", '', $nav);
$nav = explode("\n", $nav);
//print_r($nav);
$newChildren = array();
foreach ($nav as $item) {
$item = trim($item);
$run = true;
for ($c = 0; $c < count($children) && run; $c++) {
$child = $children[$c];
if (strcmp($child->post_title, $item) == 0 && !in_array($child, $newChildren)) {
$newChildren[] = $child;
$run = false;
}
}
// Adding the children the nav_menu is lacking, not sure why not all sub-children
// are added to the first child here..(works but don't know why :/)
if ($run == true) {
for ($c = 0; $c < count($children) && run; $c++) {
$child = $children[$c];
if (!in_array($child, $newChildren)) {
$newChildren[] = $child;
}
}
}
}
$children = $newChildren;
contestado el 22 de mayo de 13 a las 16:05
0
when you populate the menu, add sort_column=menu_order
:
<ul class="main-nav">
<?php wp_list_pages('&title_li=&depth=2&sort_column=menu_order'); ?>
</ul>
Respondido 25 ago 20, 16:08
No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas php wordpress or haz tu propia pregunta.
you should ask this question here: wordpress.stackexchange.com - Anthony
I have the same exact problem :( - OZZIE