サポート » 使い方全般 » 月別アーカイブでdate.phpが読み込まれない

  • higakou0529

    (@higakou0529)


    現在、MAMP環境でwordpress3.8.1を使用してサイトを作っております。

    wordpressを使用するのは初めてなのですが、既存テーマを使用しておらず、オリジナルで組み込んでいっております。

    archive.phpにて
    <?php wp_get_archives(‘type=monthly&limit=12’); ?>
    を記述して月別アーカイブリストを表示しているのですが、
    「2014年3月」というところをクリックしても、index.phpが読み込まれてしまいます。

    date.phpを設置していると、そちらが優先されるはずだと思うのですが、なにか邪魔をする要因などはあるのでしょうか?

    ちなみに、カスタム投稿タイプも使用しており、下記にfunctions.phpの内容を記載します。(今回の月別アーカイブに関してはカスタム投稿タイプの記事は表示しません。)
    functions.phpの内容は理解できておらず、色々なところからの情報をかき集めてコピペしているので、どこかおかしいのかもしれません。

    <?php
    // カスタム投稿タイプ「サンプルカスタム」
    add_action(‘init’,’create_samplecustom_post_type’,0);
    function create_calligraphy_post_type() {
    register_post_type(‘samplecustom’, array(
    ‘label’ => ‘サンプルカスタム’,
    ‘description’ => ‘サンプルカスタムの内容’,
    ‘public’ => true,
    ‘menu_position’ => 5,
    ‘has_archive’ => true,
    ‘supports’ => array(‘title’, ‘editor’, ‘thumbnail’),
    ));
    }

    // カスタムタクソノミー 「カテゴリー」
    add_action(‘init’,’create_samplecustom_cat’,0);
    function create_samplecustom_cat() {
    register_taxonomy(‘genre’, ‘samplecustom’, array(
    ‘hierarchical’ => true,
    ‘label’ => ‘サンプルカスタムのカテゴリー’,
    ‘singular_name’ => ‘サンプルカスタムのカテゴリー’,
    ‘query_var’ => true,
    ‘rewrite’ => true));
    }
    // カスタムタクソノミー 「タグ」
    add_action(‘init’,’create_samplecustom_tag’,0);
    function create_samplecustom_tag() {
    register_taxonomy(‘classify’, ‘samplecustom’, array(
    ‘hierarchical’ => false,
    ‘label’ => ‘サンプルカスタムのタグ’,
    ‘singular_name’ => ‘サンプルカスタムのタグ’,
    ‘query_var’ => true,
    ‘rewrite’ => true));
    }

    //月別アーカイブリスト設定
    function add_my_post_type($where, $r) {

    $my_current_cpt = get_post_type();

    return str_replace(
    “post_type = ‘post'”,
    “post_type = ‘$my_current_cpt'”,
    $where
    );
    }
    add_filter(‘getarchives_where’,’add_my_post_type’,10,2);

    //月別アーカイブページ設定
    function my_get_archives_link($link_html) {
    return str_replace(
    home_url(‘/’),
    home_url(‘/’).get_post_type().’/’,
    $link_html
    );
    }
    add_filter(‘get_archives_link’, ‘my_get_archives_link’);

    $mycpts = get_post_types(array(‘builtin’ => false));
    foreach ($mycpts as $mycpt) {
    add_rewrite_rule($mycpt.’/cat/([^/]+)/?$’ , ‘index.php?’.$mycpt.’_cat=$matches[1]’, ‘top’);

    add_rewrite_rule($mycpt.’/tag/([^/]+)/?$’ , ‘index.php?’.$mycpt.’_cat=$matches[1]’, ‘top’);

    add_rewrite_rule($mycpt.’/([0-9]{4})/([0-9]{2})/?$’, ‘index.php?post_type=’.$mycpt.’&year=$matches[1]&monthnum=$matches[2]’, ‘top’);

    }

    ?>

2件の返信を表示中 - 1 - 2件目 (全2件中)
  • ishihara takashi

    (@ishihara-takashi)

    上記コードでは、カスタム投稿タイプの月別アーカイブを参照しようとしています。

    //月別アーカイブリスト設定
    function add_my_post_type($where, $r) {
    
    $my_current_cpt = get_post_type();
    
    return str_replace(
    "post_type = 'post'",
    "post_type = '$my_current_cpt'",
    $where
    );
    }
    add_filter('getarchives_where','add_my_post_type',10,2);
    
    //月別アーカイブページ設定
    function my_get_archives_link($link_html) {
    return str_replace(
    home_url('/'),
    home_url('/').get_post_type().'/',
    $link_html
    );
    }
    add_filter('get_archives_link', 'my_get_archives_link');
    
    $mycpts = get_post_types(array('builtin' => false));
    foreach ($mycpts as $mycpt) {
    add_rewrite_rule($mycpt.'/cat/([^/]+)/?$' , 'index.php?'.$mycpt.'_cat=$matches[1]', 'top');
    
    add_rewrite_rule($mycpt.'/tag/([^/]+)/?$' , 'index.php?'.$mycpt.'_cat=$matches[1]', 'top');
    
    add_rewrite_rule($mycpt.'/([0-9]{4})/([0-9]{2})/?$', 'index.php?post_type='.$mycpt.'&year=$matches[1]&monthnum=$matches[2]', 'top');
    
    }

    上記コードを削除して見て下さい。

    トピック投稿者 higakou0529

    (@higakou0529)

    ishihara takashi様

    ありがとうございます!
    解決致しました。

    ちなみに、カスタム投稿タイプの中でも月別アーカイブを作成したい場合は
    どのようにすればいいのでしょうか?

2件の返信を表示中 - 1 - 2件目 (全2件中)
  • トピック「月別アーカイブでdate.phpが読み込まれない」には新たに返信することはできません。