<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Little.ws &#187; カスタムフィールド</title>
	<atom:link href="http://little.ws/tag/%e3%82%ab%e3%82%b9%e3%82%bf%e3%83%a0%e3%83%95%e3%82%a3%e3%83%bc%e3%83%ab%e3%83%89/feed" rel="self" type="application/rss+xml" />
	<link>http://little.ws</link>
	<description>web制作とかcssとかデザインとか色々～な覚え書き</description>
	<lastBuildDate>Sat, 04 Feb 2012 07:27:16 +0000</lastBuildDate>
	<language>ja</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>wordpress:アーカイブページをカスタムフィールドの値で並び替える</title>
		<link>http://little.ws/200907/218.html</link>
		<comments>http://little.ws/200907/218.html#comments</comments>
		<pubDate>Wed, 08 Jul 2009 03:58:08 +0000</pubDate>
		<dc:creator>chibi</dc:creator>
				<category><![CDATA[Wordpress応用]]></category>
		<category><![CDATA[wordpress]]></category>
		<category><![CDATA[カスタムフィールド]]></category>
		<category><![CDATA[テンプレート]]></category>
		<category><![CDATA[プラグイン]]></category>

		<guid isPermaLink="false">http://little.ws/?p=218</guid>
		<description><![CDATA[フォーラムでも同じ事で悩んでる方がいて、 投稿をカスタムフィールド値でソートし、更に時系列に並べる こちらは解決したようですが、ぼくがやりたいことはちょーっと違っていたのです！ たとえば、良くショッピングサイトであるよう&#8230;]]></description>
			<content:encoded><![CDATA[<p>フォーラムでも同じ事で悩んでる方がいて、<br />
<a href="http://ja.forums.wordpress.org/topic/1851" class="liwp">投稿をカスタムフィールド値でソートし、更に時系列に並べる</a><br />
こちらは解決したようですが、ぼくがやりたいことはちょーっと違っていたのです！<br/><br />
たとえば、良くショッピングサイトであるような『価格順』『新着順』なんかのボタンをアーカイブページに実装したかったのです。<br />
例として、カスタムフィールド名を『item_price』とします。<br />
これをボタンで昇順降順で自在に並び替えたい。<br />
ということで以下覚え書き</p>
<p><span id="more-218"></span></p>
<p>プラグイン使わなくても出来ますが、めんどくさいのでプラグイン頼み。<br />
<a href="http://www.dyasonhat.com/wp-smart-sort/" class="liexternal">WP Smart Sort</a>を使用します。<br />
これデフォルト使用でもいいんですが、スマートではないので。。<br/><br />
プラグインフォルダにUP後有効化したら、オプション画面からSmart Sort設定画面へ。</p>
<p><a href="http://little.ws/wp-content/uploads/2009/07/smartsort.jpg" rel="fancybox-gallery" rel='lightbox' class="liimagelink"><img src="http://little.ws/wp-content/uploads/2009/07/smartsort-300x220.jpg" alt="smartsort" title="smartsort" width="300" height="220" class="alignnone size-medium wp-image-219" /></a><br />
使用するカスタムフィールド名を探し、Display Text欄に名前をつけ、右側の追加ボタンを押します。<br />
今回は例としてフィールド名『item_price』にDisplay Text欄を『価格』としてみました。<br />
追加後、下にスクロールすると次のような項目があります。<br />
<a href="http://little.ws/wp-content/uploads/2009/07/sort2.jpg" rel="fancybox-gallery" rel='lightbox' class="liimagelink"><img src="http://little.ws/wp-content/uploads/2009/07/sort2-300x141.jpg" alt="sort2" title="sort2" width="300" height="141" class="alignnone size-medium wp-image-220" /></a><br />
この、価格（_item_price-pm）ASC　という部分が非常に重要で、<br/><br />
_item_price-pmが並べ替えのキーで、<br />
ASCが並び順のキー（昇順（asc）・降順（desc）となります。<br/><br />
ここまで分かれば、あとはテンプレート側で値をとってquery_postsの引数に追加するだけです。<br />
（query postsの引数に関しては、<a href="http://wpdocs.sourceforge.jp/%E3%83%86%E3%83%B3%E3%83%97%E3%83%AC%E3%83%BC%E3%83%88%E3%82%BF%E3%82%B0/query_posts" class="liexternal">テンプレートタグ/query posts</a>を参照）<br/><br />
引数は<br />
ssort = 並び替えのキー<br />
sdir = 並び順のキー</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php
$ssort = $_GET['ssort'];
$sdir = $_GET['sdir'];
?&gt;
 &lt;?php if (have_posts()) :  query_posts(&quot;ssort=$ssort&amp;sdir=$sdir&quot;);  ?&gt;
</pre>
<p>最後に、ページ内に実装するボタン、『価格順』のリンクを</p>
<p>http://○○.com/?cat=カテゴリID<strong>&#038;ssort=_item_price-pm&#038;sdir=asc</strong></p>
<p>とか</p>
<p>http://○○.com/?cat=カテゴリID<strong>&#038;ssort=_item_price-pm&#038;sdir=desc</strong></p>
<p>にする。カテゴリIDの取得についてはさすがに割愛します。<br />
以上、ものすごく省略しながらの覚え書きでした。</p>
]]></content:encoded>
			<wfw:commentRss>http://little.ws/200907/218.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>wordpress：Custom Field GUI Utilityでカスタムフィールドを・・</title>
		<link>http://little.ws/200905/201.html</link>
		<comments>http://little.ws/200905/201.html#comments</comments>
		<pubDate>Fri, 29 May 2009 03:27:50 +0000</pubDate>
		<dc:creator>chibi</dc:creator>
				<category><![CDATA[wordpress]]></category>
		<category><![CDATA[ただの覚え書き]]></category>
		<category><![CDATA[カスタムフィールド]]></category>
		<category><![CDATA[プラグイン]]></category>

		<guid isPermaLink="false">http://little.ws/?p=201</guid>
		<description><![CDATA[何度かカスタムフィールドについて書きましたが、 （wordpress:カスタムフィールドを使いやすく！その２とか wordpress:カスタムフィールドを使いやすく！とか） Custom Field GUI Utilit&#8230;]]></description>
			<content:encoded><![CDATA[<p>何度かカスタムフィールドについて書きましたが、<br />
（<a href="http://little.ws/200903/193.html" class="liinternal">wordpress:カスタムフィールドを使いやすく！その２</a>とか<br />
<a href="http://little.ws/200903/182.html" class="liinternal">wordpress:カスタムフィールドを使いやすく！</a>とか）<br />
<a href="http://www.tinybeans.net/blog/download/wp-plugin/cfg-utility-100.html" class="liexternal">Custom Field GUI Utility</a>という便利なプラグインがあります。<br/><br />
いままでwordpress2.7に対応していなかったのですが、<br />
ついにバージョンアップで対応されたみたいです！！<br/><br />
ちょー便利なのです。<br />
詳しくは本家サイト様でどうぞー。<br />
<a href="http://www.tinybeans.net/blog/download/wp-plugin/cfg-utility-100.html" class="liexternal">Custom Field GUI Utility &#8211; WordPress プラグイン &#8211; かたつむりくんのWWW</a></p>
]]></content:encoded>
			<wfw:commentRss>http://little.ws/200905/201.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>wordpress:カスタムフィールドを使いやすく！その２</title>
		<link>http://little.ws/200903/193.html</link>
		<comments>http://little.ws/200903/193.html#comments</comments>
		<pubDate>Wed, 18 Mar 2009 03:35:25 +0000</pubDate>
		<dc:creator>chibi</dc:creator>
				<category><![CDATA[wordpress]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[wordpressタグ]]></category>
		<category><![CDATA[カスタムフィールド]]></category>
		<category><![CDATA[人にやさしく]]></category>

		<guid isPermaLink="false">http://little.ws/?p=193</guid>
		<description><![CDATA[カスタムフィールドを呼び出す方法、wordpress:Get Custom Field Valuesでプラグインを使用して呼び出す方法は書いていたみたいです。 これ、先の記事（wordpress:カスタムフィールドを使い&#8230;]]></description>
			<content:encoded><![CDATA[<p>カスタムフィールドを呼び出す方法、<a href="http://little.ws/200901/103.html" class="liinternal">wordpress:Get Custom Field Values</a>でプラグインを使用して呼び出す方法は書いていたみたいです。<br />
これ、先の記事（<a href="http://little.ws/200903/182.html" class="liinternal">wordpress:カスタムフィールドを使いやすく！</a>）の続きですので、先にそっちを読んだ方がいいです。<br/><br />
でも、今回はプラグインを使用せずに呼び出しましょう。<br />
<span id="more-193"></span><br />
前回の記事で、サムネイル表示用のメタボックスを作成したので、<br />
それを呼び出してあげましょう。<br />
先にソース書きます！</p>
<pre class="brush: php; title: ; notranslate">
&lt;div class=&quot;eximg&quot;&gt;
	&lt;?php
		$smallimg = get_post_meta($post-&gt;ID, &quot;smallimg_value&quot;, true);
	?&gt;

   &lt;p&gt;
	&lt;?php if($smallimg !== '') { ?&gt;
	&lt;a title=&quot;&lt;?php the_title(); ?&gt;&quot; href=&quot;&lt;?php the_permalink() ?&gt;&quot; rel=&quot;bookmark&quot;&gt;&lt;img style=&quot;width:100px; height:100px;&quot; src=&quot;&lt;?php echo $smallimg; ?&gt;&quot; alt=&quot;&lt;?php the_title(); ?&gt;&quot;/&gt;&lt;/a&gt;
	&lt;?php } else { ?&gt;
	&lt;a title=&quot;&lt;?php the_title(); ?&gt;&quot; href=&quot;&lt;?php the_permalink() ?&gt;&quot; rel=&quot;bookmark&quot;&gt;&lt;img src=&quot;&lt;?php bloginfo('template_url'); ?&gt;/images/postsmall.jpg&quot; style=&quot;width:100px; height:100px; &quot; alt=&quot;&lt;?php the_title(); ?&gt;&quot;/&gt;&lt;/a&gt;
    &lt;?php } ?&gt;
   &lt;/p&gt;
&lt;/div&gt;
</pre>
<p>簡単に説明すると、メタボックスに入力した画像を読み込み表示プラス記事へのリンクです。<br />
んで、もしメタボックスに何も入力されていないときは、テーマフォルダ内の/images/postsmall.jpgという画像を表示させて記事へのリンクを張ります。<br />
ただ、これは先の記事で書いたstdの部分にデフォルトの画像として入力しておいてあげればすむことなのですが、<br />
万が一空白にしてしまったときのための保険みたいなモノとして書いてあげています。<br />
100pxの値は任意の値に変えてあげて下さい。</p>
]]></content:encoded>
			<wfw:commentRss>http://little.ws/200903/193.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>wordpress:カスタムフィールドを使いやすく！</title>
		<link>http://little.ws/200903/182.html</link>
		<comments>http://little.ws/200903/182.html#comments</comments>
		<pubDate>Wed, 18 Mar 2009 03:22:19 +0000</pubDate>
		<dc:creator>chibi</dc:creator>
				<category><![CDATA[wordpress]]></category>
		<category><![CDATA[wordpressタグ]]></category>
		<category><![CDATA[カスタムフィールド]]></category>
		<category><![CDATA[人にやさしく]]></category>

		<guid isPermaLink="false">http://little.ws/?p=182</guid>
		<description><![CDATA[wordpressのカスタムフィールドを無駄にしている人がきっと沢山いると思います。 こんなに便利なものを！！ でもきっと、使いにくいと思っている人もおおいはず。 ましてや、素人さんに、カスタムフィールドを使用させるのも&#8230;]]></description>
			<content:encoded><![CDATA[<p>wordpressのカスタムフィールドを無駄にしている人がきっと沢山いると思います。<br/><br />
こんなに便利なものを！！<br />
でもきっと、使いにくいと思っている人もおおいはず。<br />
ましてや、素人さんに、カスタムフィールドを使用させるのも・・。<br/><br />
ということで、今回はカスタムフィールドをばっちり使いやすくします。<br />
以下の画像の様に投稿画面に誰でも分かりやすい入力欄を作成します。<br />
<a href="http://little.ws/wp-content/uploads/2009/03/custom_panel.jpg" rel="fancybox-gallery" rel='lightbox' class="liimagelink"><img src="http://little.ws/wp-content/uploads/2009/03/custom_panel-300x257.jpg" alt="custom_panel" title="custom_panel" width="300" height="257" class="alignnone size-medium wp-image-183" /></a><br />
<span id="more-182"></span><br />
functions.phpに書いてもOKですが、すぐぐちゃぐちゃになっちゃうので、今回は別にFileを作っちゃいます。<br />
適当なFile名でOKです。ではソースを</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php

	$work_meta_boxes =
	array(
	&quot;smallimg&quot; =&gt; array(
	&quot;name&quot; =&gt; &quot;smallimg&quot;,
	&quot;std&quot; =&gt; &quot;&quot;,
	&quot;title&quot; =&gt; &quot;サムネイルイメージ&quot;,
	&quot;description&quot; =&gt; &quot;画像をUPした場合、画像のサムネイルimgのアドレスをコピペ！&quot;)

/* 以下の段落をカスタムして増やせます。
	&quot;company&quot; =&gt; array(
	&quot;name&quot; =&gt; &quot;カスタムフィールドの名前&quot;,
	&quot;std&quot; =&gt; &quot;&quot;,
	&quot;title&quot; =&gt; &quot;入力欄のタイトル&quot;,
	&quot;description&quot; =&gt; &quot;説明文（ﾀｸﾞ使用可能）&quot;),
*/

	);
</pre>
<p>今回は『smallimg』という名前のカスタムフィールドで『サムネイルイメージ』がタイトルです。descriptionはその通り説明書きみたいなものです。stdは初期値です。初期値の変更で、imgが無いときにデフォルトの画像URLを入力しておくとか、そんな感じの使い方です。<br/><br />
次に、投稿画面への入力欄の追加のために以下を追加。</p>
<pre class="brush: php; title: ; notranslate">
	function work_meta_boxes() {
		global $post, $work_meta_boxes;
		foreach($work_meta_boxes as $meta_box) {
			$meta_box_value = get_post_meta($post-&gt;ID, $meta_box['name'].'_value', true);

			if($meta_box_value == &quot;&quot;)
			$meta_box_value = $meta_box['std'];

			echo'&lt;input type=&quot;hidden&quot; name=&quot;'.$meta_box['name'].'_noncename&quot; id=&quot;'.$meta_box['name'].'_noncename&quot; value=&quot;'.wp_create_nonce( plugin_basename(__FILE__) ).'&quot; /&gt;';

			echo'&lt;h2&gt;'.$meta_box['title'].'&lt;/h2&gt;';

			echo'&lt;input type=&quot;text&quot; name=&quot;'.$meta_box['name'].'_value&quot; value=&quot;'.$meta_box_value.'&quot; size=&quot;55&quot; /&gt;&lt;br /&gt;';

			echo'&lt;p&gt;&lt;label for=&quot;'.$meta_box['name'].'_value&quot;&gt;'.$meta_box['description'].'&lt;/label&gt;&lt;/p&gt;';
		}
	}

	function create_meta_box() {
		global $theme_name;

		if ( function_exists('add_meta_box') )
			add_meta_box( 'work-meta-boxes', 'TOPページサムネイル追加', 'work_meta_boxes', 'post', 'normal', 'high' );
	}
</pre>
<p>この辺の説明は割愛します。<br />
知りたければ書きますが・・<br/><br />
上のソースの23行目の説明だけ・・</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php add_meta_box('id', 'title', 'callback', 'page', 'context', 'priority'); ?&gt;
</pre>
<p><strong>id </strong><br />
    編集画面でのID（識別名）です。<br />
<strong>title </strong><br />
    編集画面で表示されるタイトル（ラベル）です。<br />
<strong>callback </strong><br />
    コールバック関数です。（今回はwork_meta_boxes）<br />
<strong>page</strong><br />
    投稿画面orページ作成画面orリンク編集画面どれで表示させるか。 (&#8216;post&#8217;, &#8216;page&#8217;, or &#8216;link&#8217;)<br />
<strong>context </strong><br />
    コンテキスト<br />
<strong>priority </strong><br />
    プライオリティ（優先順位です）。メタボックスが呼び出される順番。<br/><br />
あとは、記事と一緒に入力したデータをどこに保存するかの設定です。</p>
<pre class="brush: php; title: ; notranslate">
	function save_postdata( $post_id ) {
		global $post, $work_meta_boxes;
		foreach($work_meta_boxes as $meta_box) {
		// Verify
			if ( !wp_verify_nonce( $_POST[$meta_box['name'].'_noncename'], plugin_basename(__FILE__) )) {
				return $post_id;
			}

			if ( 'page' == $_POST['post_type'] ) {
				if ( !current_user_can( 'edit_page', $post_id ))
					return $post_id;
			} else {
				if ( !current_user_can( 'edit_post', $post_id ))
					return $post_id;
			}

			$data = $_POST[$meta_box['name'].'_value'];

			if(get_post_meta($post_id, $meta_box['name'].'_value') == &quot;&quot;)
				add_post_meta($post_id, $meta_box['name'].'_value', $data, true);
			elseif($data != get_post_meta($post_id, $meta_box['name'].'_value', true))
				update_post_meta($post_id, $meta_box['name'].'_value', $data);
			elseif($data == &quot;&quot;)
				delete_post_meta($post_id, $meta_box['name'].'_value', get_post_meta($post_id, $meta_box['name'].'_value', true));
		}
	}
</pre>
<p>ここも割愛。<br/><br />
んで、最後に</p>
<pre class="brush: php; title: ; notranslate">
	add_action('admin_menu', 'create_meta_box');
	add_action('save_post', 'save_postdata');
</pre>
<p>あとはfunctions.phpに以下の一文を付け足して、呼び出してあげましょう。</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php
	include_once (TEMPLATEPATH . '/保存したfile名.php');
?&gt;
</pre>
<p>なんだか説明になってないので、File上げときます。<br />
適当にいじって使って下さい。<br/><br />
ダウンロードする方、何かｺﾒいただけるとうれしいです。<br />
<strong>右クリ保存でお願いしますYO</strong><br />
<a href="http://little.ws/wp-content/uploads/2009/03/custom-write-panel.zip" class="lizip">ダウンロード</a><br/><br />
functions.phpだけは自分で一文を付け足して下さい。<br />
カスタムフィールドの呼び出し方は。。前に書いた気がするので探して下さいｗ<br />
無ければ後で書きます。</p>
]]></content:encoded>
			<wfw:commentRss>http://little.ws/200903/182.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>wordpress:Get Custom Field Values</title>
		<link>http://little.ws/200901/103.html</link>
		<comments>http://little.ws/200901/103.html#comments</comments>
		<pubDate>Tue, 06 Jan 2009 05:17:02 +0000</pubDate>
		<dc:creator>chibi</dc:creator>
				<category><![CDATA[wordpress]]></category>
		<category><![CDATA[カスタムフィールド]]></category>
		<category><![CDATA[プラグイン]]></category>
		<category><![CDATA[人にやさしく]]></category>

		<guid isPermaLink="false">http://little.ws/?p=103</guid>
		<description><![CDATA[カスタムフィールドを有効活用したら、wordpressの活用の幅が広がると思います。 今日の天気、気分、一言、使ったお金とか。何でもメモ出来るしねー。 ちなみに、その日の写真のimgソース書いて別ページにサムネ表示させた&#8230;]]></description>
			<content:encoded><![CDATA[<p>カスタムフィールドを有効活用したら、wordpressの活用の幅が広がると思います。<br />
今日の天気、気分、一言、使ったお金とか。何でもメモ出来るしねー。<br/><br />
ちなみに、その日の写真の<a href="http://little.ws/200901/92/" class="liinternal">imgソース書いて別ページにサムネ表示</a>させたりも出来ます。<br />
それはまた別ページで紹介しているので、今回はプラグインの覚え書き。<br/><br />
カスタムフィールドに記入した値を表示させるタグといえば、<strong>the_meta()</strong>でOKですが、<br />
これだと、色んなプラグイン入れてるひとは要らないものまで吐き出してくれます。<br />
なので必要な値を必要な場所に。それが<a href="http://coffee2code.com/wp-plugins/get-custom-field-values/" class="liexternal">Get Custom Field Values</a>です。<br/></p>
<p>例えば、こんな感じで毎日自分の体重を書き込んでいったとします。<br/><br />
<a href="http://little.ws/wp-content/uploads/2009/01/01061.jpg" rel="fancybox-gallery" rel='lightbox' class="liimagelink"><img src="http://little.ws/wp-content/uploads/2009/01/01061-300x94.jpg" alt="01061" title="01061" width="300" height="94" class="alignnone size-medium wp-image-105" /></a><br/><br />
これを、</p>
<p style="text-indent:1em;">今日の体重　<span style="color:red;">58.2kg</span></p>
<p>という感じで表示させたいと思います。<br/><span id="more-103"></span><br />
毎日書くので、今回はindex.phpのループの記事コンテンツ表示部分の後ろに追加します。<br />
コードはこんな感じです。</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php echo c2c_get_custom
('体重','&lt;p&gt;今日の体重　&lt;span style=&quot;color:red;&quot;&gt;','kg&lt;/span&gt;&lt;/p&gt;','サボった');
 ?&gt;
</pre>
<p>わかりにくいですが、<strong>ループ内に置くとき</strong>は</p>
<pre class="brush: php; title: ; notranslate">&lt;?php echo c2c_get_custom
('$field','$before','$after','$none','$between','$before_last');
 ?&gt;</pre>
<p>こんな感じの引数になります。</p>
<div style="margin:5px;border:1px solid #cccccc;padding:5px;">
<ul>
<li><strong>$field</strong>　表示させるカスタムフィールドの名前（ここでは体重）</li>
<li><strong>$before</strong>　値の前に表示させるテキストもしくはHTML(ここではHTMLと今日の体重というテキスト）</li>
<li><strong>$after</strong>　値の後に表示させるテキストもしくはHTML（ここではkgという単位表示とタグ閉じ）</li>
<li><strong>$none</strong>　値をが空もしくは見つからないときに表示されるテキス(ry　（ここではサボったというテキスト。空でもOK）</li>
<li><strong>$between</strong>　2つ以上値がある時、間に表示させるテキス(ry　（空に指定すると一つ目だけ表示。例としてはコンマとか）</li>
<li><strong>$before_last</strong>　2つ以上値がある時、最後と最後から2個目の間に表示させる(ry　（例としてはandとか。日本人には馴染みがない習慣）</li>
</ul>
</div>
<p><br/><br />
ちなみにループの外に置きたい時は、<strong>c2c_get_custom</strong>ではなく<strong>c2c_get_recent_custom</strong>とします。<br />
<br/></p>
]]></content:encoded>
			<wfw:commentRss>http://little.ws/200901/103.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

