0

afc に加えて、サイドバーで wp_list_pages を使用します。

リストページの通常の出力は次のようなものです

<ul>
 <li>page 1</<li>
 <li>page 2</<li>
<ul>
 <li>page 2.1</<li>
 <li>page 2.2</<li>
 <li>page 2.3</<li>
</ul>
 <li>page 3</<li>
 <li>page 4</<li>
 <li>page 5</<li>
 <li>page 6</<li>
</ul>

一部のページにはカスタム フィールドがあり、このようなものが必要です

<ul>
 <li>page 1</<li>
 <li>page 2 <span> - **custom field info**</span></<li>
<ul>
 <li>page 2.1</<li>
 <li>page 2.2<span> - custom field info</span></<li>
 <li>page 2.3</<li>
</ul>
 <li>page 3</<li>
 <li>page 4<span> - custom field info</span></<li>
 <li>page 5</<li>
 <li>page 6</<li>
</ul>

通常のワードプレスのカスタムフィールドで、私はこれを試しました:

wp_list_pages("title_li=".$post->ID."&meta_key=key");

しかし、これは追加ではなく、キーを持つページのみをフィルタリングして表示します。どうすればこの小さな問題を解決できますか? (他の)アイデアはありますか?

ありがとうございました

4

1 に答える 1

1

次のようなことをする必要があります:

$args = array(
    'post_type' => 'page',
);
// The Query
$query = new WP_Query( $args );

// The Loop
if ( $query->have_posts() ) {

    echo '<ul>';

    while ( $query->have_posts() ) {

        $query->the_post();

        if ( get_field( "field_name" ) ) {
            $custom_field_value = ' <span>' . get_field( "field_name" ) . '</span>';
        } else {
            $custom_field_value = '';
        }

        echo '<li>' . get_the_title() . $custom_field_value . '</li>';
    }

    echo '</ul>';

} else {
    // no posts found
}

/* Restore original Post Data */
wp_reset_postdata();
于 2013-08-18T01:28:56.087 に答える