9月
13
2012

welcartにカスタム投稿でブログをつけるカスタマイズ

wordpress welcart tips
IT GIRLネタ!
今もカスタマイズ中ですが、welcartにブログ機能を付ける!(カスタム投稿・カスタムタクソノミーで!)
いや、ブログでなくてもいいんですけど、カスタム投稿・カスタムタクソノミーがもう、ややこしくて、
探して探して・・・。

と言うわけで、自分用まとめでもあります。

welcartにカスタム投稿でブログを作る!

:普通の投稿機能を使うと、ブログ記事と商品のループが混じる。
:ブログにもカテゴリー・タグを付ける!
:ブログは月別アーカイブを出したい!
:ブログは商品ページとテンプレートを変えたい!
:ついでに商品ページと違う、ウィジェットも使いたい!

こんな感じでしょうか?
welcartの開発フォーラム?にも記事が載ってたんですが、何故か商品が混じる!ので、
カスタム投稿でブログを作る事にしました!

:ブログにもカテゴリー・タグを付ける!
→これは結構探せば載っているTIPS!
商品のカテゴリーやタグとは別にブログ(カスタム投稿)のカテゴリー・タグを使いたい時。
function.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,
‘supports’ => array( ‘title’, ‘editor’, ‘author’, ‘thumbnail’, ‘excerpt’, ‘custom-fields’ ,’comments’ ),
‘menu_position’ =>5,
‘has_archive’ => true
)
);
//カスタムタクソノミー、カテゴリタイプ
register_taxonomy(
‘blog-cat’,
‘blog’,
array(
‘hierarchical’ => true,
‘update_count_callback’ => ‘_update_post_term_count’,
‘label’ => ‘ブログのカテゴリー’,
‘singular_label’ => ‘ブログのカテゴリー’,
‘public’ => true,
‘show_ui’ => true
)
);
//カスタムタクソノミー、タグタイプ
register_taxonomy(
‘blog-tag’,
‘blog’,
array(
‘hierarchical’ => false,
‘update_count_callback’ => ‘_update_post_term_count’,
‘label’ => ‘ブログのタグ’,
‘singular_label’ => ‘ブログのタグ’,
‘public’ => true,
‘show_ui’ => true
)
);
}
view raw gistfile1.txt hosted with ❤ by GitHub

:ブログ(カスタム投稿)だけの月別アーカイブを出したい時。
→function.phpに

add_filter( 'getarchives_where', 'my_getarchives_where', 10, 2 );
function my_getarchives_where( $where, $r ) {
global $taxonomy_getarchives_data;
if ( isset($r['post_type']) ){
$taxonomy_getarchives_data['post_type'] = $r['post_type'];
$where = str_replace( '\'post\'', '\'' . $r['post_type'] . '\'',
$where );
}
return $where;
}
/*リンク先にpost_type=の引数を付ける*/
function archive_link_for_taxonomy($url){
global $taxonomy_getarchives_data;
if (isset($taxonomy_getarchives_data['post_type'])){
$url .= strpos($url, '?') === false ? '?' : '&';
$url .= 'post_type=' . $taxonomy_getarchives_data['post_type'];
}
return $url;
}
add_filter('year_link', 'archive_link_for_taxonomy');
add_filter('month_link', 'archive_link_for_taxonomy');
add_filter('day_link', 'archive_link_for_taxonomy');
view raw gistfile1.php hosted with ❤ by GitHub

→月別アーカイブを載せたい場所に(サイドバーやフッター)
<?php wp_get_archives(array(‘post_type’ => ‘my_custum_post’,
‘type’ => ‘monthly’));>

:商品ページとは異なるウィジェットをサイドバーで使いたい
→function.phpに2個目のウィジェットエリアを作る

// Area 2, located below the Primary Widget Area in the sidebar. Empty by default.
register_sidebar( array(8,
'name' => __( 'Secondary Widget Area', 'テンプレート名' ),
'description' => __( 'The secondary widget area', 'テンプレート名' ),
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h2 class="widgettitle">',
'after_title' => '</h2>',
));
view raw gistfile1.txt hosted with ❤ by GitHub

→sidebar-2.phpに記載(2個目のサイドバー)のテンプレートを作る。sidebar.phpとsidebar-2.phpの2つ。
<?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar(8) ) : ?>
<?php endif; ?>
view raw gistfile1.php hosted with ❤ by GitHub

ブログ(カスタム投稿)のsingleページのカスタマイズ

:カスタム投稿の関連記事をブログのシングルページに出したい!
:カスタム分類の記事に使われたタグを表示したい!
:カスタム分類の記事がカテゴライズされたカテゴリーを表示したい!
:カスタム投稿の最新記事の5件を出力したい!
:カスタム投稿の関連記事を出したい!
→商品ページにはYARPPで関連商品を出していますが、カスタム投稿のみの関連記事を出す!
(アイキャッチ150×150.タイトルの表示)

<?php
$loop = new WP_Query( array( 'post_type' => 'blog', 'posts_per_page' => 4, 'orderby' =>rand ) );
while ( $loop->have_posts() ) : $loop->the_post();
?>
<div class="thumbnail_box3">
<li><a href="<?php the_permalink() ?>"><?php the_post_thumbnail(array(150,150)); ?> </a></li>
<div class="thumtitle"><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php printf(__(' %s', 'uscestheme'), the_title_attribute('echo=0')); ?>"><?php the_title(); ?></a></div></div>
<?php endwhile;wp_reset_query(); ?>
view raw gistfile1.php hosted with ❤ by GitHub

:カスタム分類の記事に使われたのタグを表示
→全部のタグクラウドでなく、書いた記事に使われたタグの表示

<?php echo get_the_term_list( $post->ID, 'blog-tag', 'TAG: ', ' , ', '' ); ?>
view raw gistfile1.php hosted with ❤ by GitHub
:カスタム分類の記事がカテゴライズされたカテゴリーの表示 →記事毎のカテゴリーの表示!
<?php
$taxo_list = get_the_term_list( $post->ID, 'blog-cat', '<strong>categotry:</strong> ', ', ', '' );
if ( $taxo_list ):
view raw gistfile1.php hosted with ❤ by GitHub

:カスタム投稿の最新記事5件を出力したい!
→(アイキャッチ&タイトル)

<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$newloop = new WP_Query(array(
'post_type' => blog,
'posts_per_page' => 5,
'paged' => $paged
));
if ($newloop->have_posts()) :
while ($newloop->have_posts()) : $newloop->the_post();
?>
<!--ループ内 -->
<div class="thumbnail_box2">
<a href="<?php the_permalink() ?>"><?php the_post_thumbnail(array(100,40)); ?> </a>
<br />
<div class="thumtitle"><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php printf(__(' %s', 'uscestheme'), the_title_attribute('echo=0')); ?>"><?php the_title(); ?></a></div></div>
<?php endwhile; endif; ?>
view raw gistfile1.php hosted with ❤ by GitHub

:カスタム分類のタグ一覧表示(リスト表示)

<ul>
<?php wp_list_categories('taxonomy=blog-tag&title_li='); ?>
</ul>
view raw gistfile1.txt hosted with ❤ by GitHub

あかん。書いてて、おかしくなりそう!

日々勉強ーー!
こういう感じなんですけど、参考になれば。。
もっと簡単なんあったら&間違えてたら教えてください。(プラグインは使わずで。)

Maybe you like!!


Comment

【コメントの投稿について】
   Furaha clothingでは、「Disqus」のコメントを使っています。
  ツイッターやフェイスブックなどにアカウントをお持ちの方は、ログインすることで
  自分のプロフィールでコメント出来ます。アカウントの無い方もメールアドレスでコメント出来ます。
  (入力したアドレスはコメントには表示されません。)
  


ブログの感想や質問など お気軽にお書きください。

Shop Now

セレクトショップ furaha clothing
コーディネートブログ

Recent post

BLOG Tag