ブログのアーカイブ記事で商品が出力される

フォーラム 使い方全般 ブログのアーカイブ記事で商品が出力される

  • このトピックには4件の返信、2人の参加者があり、最後にnekoにより10年、 2ヶ月前に更新されました。
5件の投稿を表示中 - 1 - 5件目 (全5件中)
  • 投稿者
    投稿
  • #68765
    neko
    参加者

    ——————————————–
    WordPress のバージョン:3.8.1
    Welcart のバージョン:1.3.11
    ご利用のテーマ:独自テーマ
    症状を確認したブラウザ:
    サーバー(会社名、サービス名):エックスサーバー
    SSLの利用: 専用SSL
    WordPress のパーマリンク設定:/archives/%post_id%/
    ——————————————–
    お世話になります。

    ショップにカスタム投稿でブログを設置しているのですが、こちらwp_get_archives(‘type=monthly&post_type=blog&show_post_count=true’)
    で出力させている月別のリンクをクリックするとarchive.phpへ飛んで商品が出力されてしまいました。
    システム設定の表示モードにチェックを入れると商品は出てこなくなりますが、記事も表示されません。
    archive.phpではif(have_posts()):while(have_posts()):the_post();……させてるだけです。

    きっとシンプルな問題だと思うのですが、色々試しても全くうまくいきません。
    それ以外のカテゴリー別記事などはtaxonomy.phpでちゃんと出力できています。

    あと思い当たるのはfunctions.phpに記述したカスタム投稿の設定でしょうか。
    すこし長いのですが一応記載しておきます。

    今月末にお店がオープンですので非常に焦っています。
    どうかご教授お願いします。

    /* カスタム投稿タイプの追加 */
    add_action( 'init', 'create_post_type' );
    function create_post_type() {
    	register_post_type( 'blog', /* post-type */
    		array(
    			'labels' => array(
    			'name' => __( 'ブログ' ),
    			'singular_name' => __( 'ブログ' )
    		),
    		'public' => true,
    		'has_archive' => true,
    		'menu_position' =>5,
        	)
    	);
    	
    	register_taxonomy(
        'blog-cat', /* タクソノミーの名前 */
        'blog', /* books投稿で設定する */
        array(
          'hierarchical' => true, /* 親子関係が必要なければ false */
          'update_count_callback' => '_update_post_term_count',
          'label' => 'ブログのカテゴリー',
          'singular_label' => 'ブログのカテゴリー',
          'public' => true,
          'show_ui' => true
        )
      );
    }
    
    /*カスタム投稿月別アーカイブ表示*/
    global $my_archives_post_type;
    add_filter( 'getarchives_where', 'my_getarchives_where', 10, 2 );
    function my_getarchives_where( $where, $r ) {
      global $my_archives_post_type;
      if ( isset($r['post_type']) ) {
        $my_archives_post_type = $r['post_type'];
        $where = str_replace( '\'post\'', '\'' . $r['post_type'] . '\'', $where );
      } else {
        $my_archives_post_type = '';
      }
      return $where;
    }
    add_filter( 'get_archives_link', 'my_get_archives_link' );
    function my_get_archives_link( $link_html ) {
      global $my_archives_post_type;
      if ( '' != $my_archives_post_type )
        $add_link .= '?post_type=' . $my_archives_post_type;
    	$link_html = preg_replace("/href=\'(.+)\'\s/","href='$1".$add_link." '",$link_html);
     
      return $link_html;
    }
    
    //カスタム投稿のパーマリンク設定
    function myposttype_rewrite() {
        global $wp_rewrite;
      
        $queryarg = 'post_type=blog&p=';
        $wp_rewrite->add_rewrite_tag('%blog_id%', '([^/]+)',$queryarg);
        $wp_rewrite->add_permastruct('blog', '/blog/%blog_id%', false);  
      
    }
    
    function myposttype_permalink($post_link, $id = 0, $leavename) {
        global $wp_rewrite;
        $post = &get_post($id);
        if ( is_wp_error( $post ) )
            return $post;
        $newlink = $wp_rewrite->get_extra_permastruct($post->post_type);
        $newlink = str_replace('%'.$post->post_type.'_id%', $post->ID, $newlink);
        $newlink = home_url(user_trailingslashit($newlink));
        return $newlink;
    }
    add_action('init', 'myposttype_rewrite');
    add_filter('post_type_link', 'myposttype_permalink', 1, 3);
    
    #68792
    nanbu
    キーマスター

    こんにちは。

    wp_get_archives(‘type=monthly&post_type=blog&show_post_count=true’)
    で出力させている月別のリンクというのは、どのようなURLになっているか教えていただけますか?

    #68854
    neko
    参加者

    こんにちわ。

    ありがとうございます。
    お返事遅くなりましてすみませんでした。

    URLは下記のようになっています。
    /archives/date/2014/01/

    一応試行錯誤のうえarchive.phpのファイルに下記を書き込んだらうまくいきました。
    query_posts($query_string.’&post_type=blog’);

    ただこのやり方でいいのでしょうか?
    パーマリンクの設定とかでしょうか。。

    もしちゃんとしたスマートなやり方がありましたらご教授お願いします。

    • この返信は10年、 2ヶ月前にnekoが編集しました。
    #68867
    nanbu
    キーマスター

    wp_rewrite_rules を使うと良いかと思います。
    「wp_rewrite_rules 投稿タイプ」などでググるといろいろ出てきますよ。

    #68883
    neko
    参加者

    ありがとうございます。
    ちょっと調べてみます。

5件の投稿を表示中 - 1 - 5件目 (全5件中)
  • このトピックに返信するにはログインが必要です。