サポート » 使い方全般 » get_query_var('year')が0年と返る

  • 解決済 tsutto0119

    (@tsutto0119)


    月別アーカイブを作成している時に、以下のようにしました。

    <?php echo get_query_var(‘year’) . “年 ” . get_query_var(‘monthnum’) . “月”; ?>

    結果”0年0月”となってしまいますが、なぜでしょうか??

    header.phpとindex.phpは以下の通りです。

    【header.php】

    <!DOCTYPE html>
    <html <?php language_attributes(); ?>>
    <head>
    <title><?php bloginfo(‘name’); wp_title(‘|’, true, ‘left’); ?></title>
    <link rel=”stylesheet” type=”text/css” media=”all” href=”<?php bloginfo(‘stylesheet_url’); ?>” />
    <meta charset=”<?php bloginfo(‘charset’); ?>” />
    </head>

    <body <?php body_class(); ?>>
    <div id=”wrapper”>
    <div id=”header”>
    <h1>
    “>
    <img src=”<?php bloginfo(‘template_directory’); ?>/images/logo.png” width=”175″ height=”27″
    alt=”<?php bloginfo(‘name’); ?>”>

    </h1>
    </div><!–end of #header–>

    <div id=”container”>

    【index.php】

    <?php get_header(); ?>

    <div id=”main”>
    <?php // 月別アーカイブページの場合は日付をタイトル出力 ?>
    <?php // それ以外の場合は”News”を出力 ?>
    <?php if (is_month()) : ?>
    <h1><?php echo get_query_var(‘year’) . “年 ” . get_query_var(‘monthnum’) . “月”; ?></h1>
    <?php else: ?>
    <h1>News</h1>
    <?php endif; ?>

    <?php // 投稿・アーカイブページで投稿を出力するループ ?>
    <?php if(have_posts()) : ?>
    <?php while(have_posts()) : the_post(); ?>
    <?php // 記事の内容を抜粋で出力 ?>
    <div class=”entry”>
    <h2>“><?php the_title(); ?></h2>
    <p class=”date”><?php the_time(‘Y.m.d’); ?></p>
    <?php the_excerpt(); ?>
    <p class=”more”>“>続きを読む</p>
    </div><!–end of .entry–>
    <?php endwhile; ?>

    <?php // ページリンク出力 ?>
    <div class=”navPage”>
    <div class=”prev”><?php previous_posts_link(‘前のページへ’); ?></div>
    <div class=”next”><?php next_posts_link(‘次のページへ’); ?></div>
    </div><!–end of .navPage–>
    <?php else: ?>
    <p>現在表示する記事がありません。</p>
    <?php endif; ?>

    </div><!–end of main–>

    <?php get_sidebar(); ?>
    <?php get_footer(); ?>

2件の返信を表示中 - 1 - 2件目 (全2件中)
2件の返信を表示中 - 1 - 2件目 (全2件中)
  • トピック「get_query_var('year')が0年と返る」には新たに返信することはできません。