サポート » 使い方全般 » 記事とページの更新情報を合体させたい

  • wakakufu

    (@wakakufu)


    いつも参考にさせてもらっています。

    現在、トップページにて「記事の更新情報」と「ページの更新情報」を表示させています。
    この二つを時系列に合わせたいのですが、良い方法が有ればご教授ねがいます。

    【記事の更新情報】

    <?php $myposts = get_posts('numberposts=5&orderby=post_date'); foreach($myposts as $post) : ?>
    <li><a href="<?php the_permalink() ?>"><?php the_time('Y年m月d日') ?>:<?php the_title(); ?></a></li>
    <?php endforeach; ?>

    【ページの更新情報】

    <?php $postslist = get_posts('post_type=page&exclude=125,131'); foreach ($postslist as $post) : setup_postdata($post); ?>
    <li><a href="<?php the_permalink(); ?>"><?php the_time('Y年m月d日'); ?>:<?php the_title(); ?>を更新しました</a></li>
    <?php endforeach; ?>

1件の返信を表示中 - 1 - 1件目 (全1件中)
  • kz

    (@kz)

    未検証:

    <?php
    $postsontop = array();
    
    // recent posts
    $posts = get_posts('numberposts=5&orderby=post_date');
    foreach($posts as $post)
      $postsontop[$post->post_date] = $post;
    
    // pages
    $posts = get_posts('post_type=page&exclude=125,131');
    foreach($posts as $post)
      $postsontop[$post->post_date] = $post;
    
    // sort
    krsort($postsontop);
    
    // output
    foreach($postsontop as $post) :
      setup_postdata($post);
      if($post->post_type == 'post') :
    ?><li>
        <a href="<?php the_permalink() ?>"><?php the_time('Y年m月d日') ?>:<?php the_title(); ?></a>
      </li>
    <?php
      else :
    ?><li>
        <a href="<?php the_permalink(); ?>"><?php the_time('Y年m月d日'); ?>:<?php the_title(); ?>を更新しました</a>
      </li>
    <?php
      endif;
    endforeach;
    ?>

1件の返信を表示中 - 1 - 1件目 (全1件中)
  • トピック「記事とページの更新情報を合体させたい」には新たに返信することはできません。