2

menu_order の何が問題なのかわかりませんが、投稿が思い通りに表示されません。ここに私が意味するものがあります

私のブログには3つの記事があります。これはdbがどのように見えるかです

id ..... menu_order
56 ..... 2
59 ..... 5
65 ..... 3

index.php (私のカスタム テーマ)

画像のみを表示したいので、使用するコードは次のとおりです

<?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. 
    ?>

問題は、投稿が id 65,59,56 で順番に表示され、59,65,56 とは異なることです。

これの何が問題なのですか?

4

4 に答える 4

0

これmenu_orderはあなたが考えていることではないようです。サイトのカスタム メニューで選択した順序。代わりに、執筆中のすべてのページを設定する順序です...これも私が望むものではないので、この解決策を作成しました:

sort_column=menu_order は、ビュー > メニュー (翻訳済み) で設定した順序ではなく、書面での順序に基づいてのみページを並べ替えます。必要に応じて、次のようにすることができます。

    $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;
于 2013-05-22T14:12:54.583 に答える
0

get_posts()代わりに同じパラメーターを使用します。ここを参照してください。

于 2012-08-28T12:57:34.447 に答える
0

メニューに入力するときは、次を追加しますsort_column=menu_order

 <ul class="main-nav">

    <?php wp_list_pages('&title_li=&depth=2&sort_column=menu_order'); ?>

 </ul>
于 2020-08-25T15:24:40.347 に答える