ページへのタグ・カテゴリー付加と表示について
永らくありがとうございました › フォーラム › プラグイン › ページへのタグ・カテゴリー付加と表示について
- このトピックには6件の返信、2人の参加者があり、最後に
匿名により11年、 11ヶ月前に更新されました。
-
投稿者投稿
-
2011 年 2 月 18 日 2:22 AM #2668
匿名
ゲストtoemon様
毎度お世話になります。
xoopsでpicoを使うか、WPのページを使うかで迷っておりまして、
WPのページでpicoのようにコンテンツを整理できないものかと考えておりました。
すると、Ninja Page Categories and TagsというWPのページに
タグとカテゴリーを付加できるプラグインを見つけ早速インストール。
すると、ページの編集画面に投稿と同様、
タグとカテゴリーの選択ボックスが出現しました。
実際ちゃんと動いているようです。
次に、page.phpにsingle.phpから以下の部分を追加しましたところ、
<code><div class ="xpress-post-footer"><br /> <?php<br /> echo the_tags(__('Tags:', 'xpress') . ' ', ', ', ' | ');<br /> printf(__('Posted in %s', 'xpress'), get_the_category_list(', '));<br /> echo ' | ';<br /> edit_post_link(__('Edit', 'xpress'), '', ' | ');<br /> ?><br /> </div></code>
タグ: タグ1, タグ2 | カテゴリー: | 編集 |
というように、タグは表示されたのですが、
カテゴリーが表示されませんでした…orz
<code>printf(__('Posted in %s', 'xpress'), get_the_category_list(', '));</code>
このコードを
<code>printf(__('Pages in %s', 'xpress'), get_the_category_list(', '));</code>
としてみましたが…ダメです。
出力させる方法はありますでしょうか。
また、WPのページをxoopsのpicoのように
ブログとは別にコンテンツとして構築していくにあたって、
xpressとの上手い使い方はございますでしょうか。
たとえば、
xpressの最近の記事内容ブロックでページコンテンツだけ
表示させるなど。
宜しくお願いいたします。
2011 年 2 月 18 日 5:54 AM #3230toemon
キーマスターky982339さんこんにちは
カテゴリーが表示されませんでした…orz
Ninja Page Categories and Tagsのコメント
You could use <?php echo get_the_term_list( $post_id, ‘category’, ‘Category: ‘, ‘, ‘, ” ); ?> anywhere in that template file where you would like the category to be shown.
にありますようにget_the_term_list関数を使用しなさいとのことです。
ただし、このプラグインではページのカテゴリー、タグは投稿のものと共有になります。
#個人的にはCustom Post Type UIプラグインを使ってページ用にCustom Taxonomy(カスタム分類)を作成する方が汎用性があって好きですけど・・・
(この場合もget_the_term_list関数を使っての表示になります。)
xpressとの上手い使い方はございますでしょうか。
たとえば、
xpressの最近の記事内容ブロックでページコンテンツだけ
表示させるなど。
WordPressでページを表示させる方法と同じ感じで
拡張ブロックで、ページコンテンツを表示するブロックを作成できます。
WP_Queryのパラメータでpost_type=pageとすれば、ページのクエリーになります。
[例]
<code><?php<br /> global $wpdb,$wp_query;<br /> $disp_count = 10;<br /> $tag_select = '';<br /> $cat_select = '' ;<br /> <br /> if(empty($tag_select)) $tag_where = ''; else $tag_where = "tag='$tag_select'&";<br /> if(empty($cat_select)) $cat_where = ''; else $cat_where = "cat=$cat_select&";<br /> <br /> if (!is_null($wpdb)){<br /> $wp_query->in_the_loop = true; //for use the_tags() in multi lopp<br /> $r = new WP_Query($tag_where .$cat_where."showposts=$disp_count&post_type=page&nopaging=0&post_status=publish");<br /> while($r->have_posts()){<br /> $r->the_post();<br /> ?><br /> <div class="xpress-post" id="post-<?php the_ID(); ?>"><br /> <div class ="xpress-post-header"><br /> <?php if (function_exists('hotDates')) { hotDates(); }?><br /> <div class ="xpress-post-title"><br /> <?php if(function_exists('the_title_attribute')) : ?><br /> <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php printf(__('Permanent Link to %s', 'xpress'), the_title_attribute('echo=0')); ?>"><?php the_title(); ?></a></h2><br /> <?php else : ?><br /> <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php printf(__('Permanent Link to %s', 'xpress'), the_title('','',false)); ?>"><?php the_title(); ?></a></h2><br /> <?php endif; ?><br /> <br /> </div><br /> </div><br /> <div class="xpress-post-entry"><br /> <?php the_content(); ?><br /> </div><br /> <div class="xpress-link-pages"><?php wp_link_pages() ?></div><br /> <div class ="xpress-post-footer"><br /> <?php<br /> the_time('Y/m/d l');<br /> echo ' - ';<br /> the_author_posts_link();<br /> echo get_the_term_list( $post_id, 'post_tag', ' | Tag: ', ', ', '' );<br /> echo get_the_term_list( $post_id, 'category', ' | Posted in ', ', ', '' );<br /> ?><br /> </div><br /> </div><br /> <?php<br /> }<br /> }<br /> ?></code>
2011 年 2 月 18 日 4:46 PM #3231匿名
ゲストありがとうございます!
Custom Post Type UIプラグインはじめて知りました。
最初よく意味がわからなかったのですが、
デフォルトのカテゴリ?のような分類をページに設置できるんですね。
ただし、このプラグインではページのカテゴリー、タグは投稿のものと共有になります。
そうなんです。
投稿と共有なので、どのようにわかりやすく分けるかで迷ってました。
ということで、Custom Post Type UIプラグインを導入して
分類名を「contents」、分類表示を「コンテンツ」にしたのでpage.phpに
<code><?php<br /> echo get_the_term_list( $post->ID, 'contents', 'コンテンツ:', ', ', '' );<br /> echo ' | ';<br /> edit_post_link(__('Edit', 'xpress'), '', '');<br /> ?></code>
これで表示させることができました。
また、ページのクエリー?の方は以下のようにして表示させることができました!
<code><?php<br /> global $wpdb,$wp_query;<br /> $disp_count = 10;<br /> $tag_select = '';<br /> $contents_select = '' ;<br /> <br /> if(empty($tag_select)) $tag_where = ''; else $tag_where = "tag='$tag_select'&";<br /> if(empty($contents_select)) $contents_where = ''; else $contents_where = "contents=$contents_select&";<br /> <br /> if (!is_null($wpdb)){<br /> $wp_query->in_the_loop = true; //for use the_tags() in multi lopp<br /> $r = new WP_Query($tag_where .$contents_where."showposts=$disp_count&post_type=page&nopaging=0&post_status=publish");<br /> while($r->have_posts()){<br /> $r->the_post();<br /> ?><br /> <div class="xpress-post" id="post-<?php the_ID(); ?>"><br /> <div class ="xpress-post-header"><br /> <?php if (function_exists('hotDates')) { hotDates(); }?><br /> <div class ="xpress-post-title"><br /> <?php if(function_exists('the_title_attribute')) : ?><br /> <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php printf(__('Permanent Link to %s', 'xpress'), the_title_attribute('echo=0')); ?>"><?php the_title(); ?></a></h2><br /> <?php else : ?><br /> <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php printf(__('Permanent Link to %s', 'xpress'), the_title('','',false)); ?>"><?php the_title(); ?></a></h2><br /> <?php endif; ?><br /> <br /> </div><br /> </div><br /> <div class="xpress-post-entry"><br /> <?php the_content(); ?><br /> </div><br /> <div class="xpress-link-pages"><?php wp_link_pages() ?></div><br /> <div class ="xpress-post-footer"><br /> <?php<br /> the_time('Y/m/d l');<br /> echo ' - ';<br /> the_author_posts_link();<br /> echo get_the_term_list( $post_id, 'post_tag', ' | Tag: ', ', ', '' );<br /> echo get_the_term_list( $post_id, 'contents', ' | contents ', ', ', '' );<br /> ?><br /> </div><br /> </div><br /> <?php<br /> }<br /> }<br /> ?></code>
これでxpressの幅がだいぶ広がった気がします。
もうひとつ、xpressのブロック「カテゴリ一覧」のように、
ここで設置したcontentsをリスト一覧表示させることも可能でしょうか。
申し訳ありません。
2011 年 2 月 19 日 12:49 AM #3232toemon
キーマスターもうひとつ、xpressのブロック「カテゴリ一覧」のように、
ここで設置したcontentsをリスト一覧表示させることも可能でしょうか。
これも拡張ブロックのお世話になります。get_terms() を使って表示させますが、WP3.0以降であれば、wp_list_categories() にパラメータに’taxonomy=xxxxx’ の指定が可能となったので、こちらのほうが簡単です。 (wp_list_categoriesもget_termsを使っています。)
[例]
<code><?php<br /> wp_list_categories('taxonomy=contents');<br /> ?></code>
2011 年 2 月 19 日 6:13 AM #3233匿名
ゲストこんな感じにして表示させることができました。
<code><?php<br /> wp_list_categories( 'taxonomy=contents&show_count=1&number=3&title_li=');<br /> ?></code>
ひとつ前に戻りますが、拡張ブロックでページコンテンツを表示させた際に、
more(続きを読む)を画像化したいのですが、通常の投稿のようには
いきませんでした。
通常の「最近の記事内容」ブロックでは、
index.phpに以下のようにして画像化しているのですが・・・。
<code><?php xpress_the_content('more_link_text=<div class="moretext"><img src="http://example.com/xpress/wp-content/themes/xpress_default/images/read.gif" alt="read more" title="続きを読む!" /></div>'); ?></code>
拡張ブロックの場合は、先ほど教えていただいたコード
<code><?php the_content(); ?></code>
この部分に入れると、何も表示されなくなってしまいます。
いかがでしょうか。
2011 年 2 月 19 日 12:50 PM #3234toemon
キーマスターmore(続きを読む)を画像化したいのですが、通常の投稿のようには
いきませんでした。
xpress_the_contentでなくても
<code><?php the_content('<div class="moretext"><img src="http://localhost/cube/modules/pico/images/navicon_up.gif" alt="read more" title="続きを読む!"/></div>'); ?></code>
でも表示できます。
ただし、いずれの方法でも
title=”続きを読む!”の記述があるのでUTF-8でファイルしないと、なにも出力しなくなります。
2011 年 2 月 19 日 1:04 PM #3235匿名
ゲスト申し訳ありませんでした。。。
UTF-8で保存するのも忘れていました。
無事、表示することができました。
誠にありがとうございます。
-
投稿者投稿
- このトピックに返信するにはログインが必要です。