サポート » 使い方全般 » 取得した上層ページのタイトルを『』で括りたい

  • 解決済 azunai

    (@azunai)


    子または孫ページに親ページと子ページのタイトル表示したくて、Codexなどを参考に以下のコードを書きました。

    <?php if($post -> post_parent != 0 ): ?>
    <?php $ancestors = array_reverse( $post-> ancestors );?>
    <?php foreach($ancestors as $ancestor): ?>
    <?php echo get_the_title($ancestor); ?>
    <?php endforeach; ?>
    <?php endif; ?>

    これに下の例のように孫ページの子ページだけを「」で括りたいのですが、その方法がわかりません。
    どなたか、ご教授願い致します。

    子ページでの表示 → 親ページタイトル

    孫ページでの表示 → 親ページ「子ページ」

3件の返信を表示中 - 1 - 3件目 (全3件中)
  • トピック投稿者 azunai

    (@azunai)

    追記です。

    「」のかわりに、以下のようにする方法でも構いません。よろしくお願いいたします。

    <span class="revell1">親ページ</span><span class="revell2">子ページ</span>

    こちらの方です。

    <span class=”revell1″>親ページ</span><span class=”revell2″>子ページ</span>

    <?php if($post -> post_parent != 0 ): ?>
    <?php $ancestors = array_reverse( $post-> ancestors );?>
    <?php $depth = 1; ?>
    <?php foreach($ancestors as $ancestor): ?>
    <span class="revell<?php echo $depth; ?>"><?php echo get_the_title($ancestor); ?></span>
    <?php $depth++; ?>
    <?php endforeach; ?>
    <?php endif; ?>
    トピック投稿者 azunai

    (@azunai)

    ありがとうございます。希望通りの表示ができました。

3件の返信を表示中 - 1 - 3件目 (全3件中)
  • トピック「取得した上層ページのタイトルを『』で括りたい」には新たに返信することはできません。