Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
0
Help us understand the problem. What is going on with this article?
@wunoe

新着記事一覧の中に特定の固定ページを差し込む【WordPress】

More than 1 year has passed since last update.
<?php 

// 条件
$args = Array(
        'post_type' => 'post',
        'posts_per_page' => '20', // 投稿数
        'category' => '2,3,4,10', // カテゴリを絞る場合
);
$the_query = get_posts( $args );

echo '<dl>'."\n";

// ループ開始
if ($the_query) {

    global $post;
    foreach ($the_query as $post) {

        setup_postdata($post);

        $loop++;

        // 上から2番目までNEWマークを付ける
        $new_class = '';
        if ($loop < 2) {
            $new_class = ' class="new_topics"';
        }

        // 挿入する固定ページ(1)
        if (!$loop_flag1) {
            if(strtotime(get_the_date('Y-m-d')) < strtotime('2019-10-25')) {
                // 一度しか表示させないためのフラグ
                $loop_flag1 = 1;
                echo '<dt>2019/10/25</dt><dd '.$new_class.'><a href="http://www.xxxx.com/page1">固定ページのタイトル</a></dd>'."\n";
            }
        }

        // 挿入する固定ページ(2)
        if (!$loop_flag2) {
            if(strtotime(get_the_date('Y-m-d')) < strtotime('2018-09-06')) {
                // 一度しか表示させないためのフラグ
                $loop_flag2 = 1;
                echo '<dt>2018/9/6</dt><dd><a href="http://www.xxxx.com/page2">固定ページのタイトル</a></dd>'."\n";
            }
        }

        // 投稿の更新情報
        echo '<dt>'.get_the_time('Y/m/j').'</dt><dd '.$new_class.'><a href="'.get_the_permalink().'">'.get_the_title().'</a></dd>'."\n";
    }
}

echo '</dl>'."\n";

wp_reset_postdata();

?>
0
Help us understand the problem. What is going on with this article?
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
wunoe

Comments

No comments
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account Login
0
Help us understand the problem. What is going on with this article?