<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="wordpress/2.3" -->
<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/"
	>

<channel>
	<title>WordPress Hacks</title>
	<link>http://bluedb.org/wordpress</link>
	<description>WordPressを使い倒すためのサイト</description>
	<pubDate>Thu, 25 Oct 2007 20:41:02 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.3</generator>
	<language>en</language>
			<item>
		<title>get_settings - WordPress</title>
		<link>http://bluedb.org/wordpress/archives/61</link>
		<comments>http://bluedb.org/wordpress/archives/61#comments</comments>
		<pubDate>Thu, 25 Oct 2007 20:29:39 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[関数リファレンス]]></category>

		<guid isPermaLink="false">http://bluedb.org/wordpress/archives/61</guid>
		<description><![CDATA[get_settingsはWordPressの設定を取得するための関数です。get_settingsはdeprecated、つまり非推奨になっています。今後はget_optionを使うのを推奨しています。
場所
wp-includes/deprecated.php
書式
function get_settings($option);
説明
get_settingsはWordPressのオプションを取得するための関数です。データベースのwp_optionsから対応する値を読み取ってきます。

string $option
取得するオプションの名前

サンプルコード

&#60;?php

echo get_settings('home');

?&#62;

homeという名前を持つオプションを呼び出しています。
実行結果

http://bluedb.org/wordpress

取得可能なオプション

admin_email
管理者のメールアドレス
blogname
ブログのタイトル
blogdescription
ブログのサブタイトル
blog_charset
ブログの文字コード。UTF-8とか
date_format
日付のフォーマット
default_cateogry
記事を投稿するときのデフォルトのカテゴリー
home
ブログのURL
siteurl
WordPressのサイトのURL
template
現在のテーマの名前
start_of_week
週始めをいつからにするか。日曜日か月曜日か。
upload_path
ファイルをアップロードするときの場所。任意指定可能。
posts_per_page
トップページやカテゴリーやアーカイブなどの1画面に表示する投稿の最大値。
posts_per_rss
rssに出力する投稿の最大値

]]></description>
			<content:encoded><![CDATA[<p>get_settingsはWordPressの設定を取得するための関数です。get_settingsはdeprecated、つまり非推奨になっています。今後はget_optionを使うのを推奨しています。</p>
<h3>場所</h3>
<p>wp-includes/deprecated.php</p>
<h3>書式</h3>
<p>function get_settings($option);</p>
<h3>説明</h3>
<p>get_settingsはWordPressのオプションを取得するための関数です。データベースのwp_optionsから対応する値を読み取ってきます。</p>
<dl>
<dt>string $option</p>
<dd>取得するオプションの名前
</dl>
<h3>サンプルコード</h3>
<pre><code>
&lt;?php

echo get_settings('home');

?&gt;
</code></pre>
<p>homeという名前を持つオプションを呼び出しています。</p>
<h3>実行結果</h3>
<pre><code>
http://bluedb.org/wordpress
</code></pre>
<h3>取得可能なオプション</h3>
<dl>
<dt>admin_email</dt>
<dd>管理者のメールアドレス</dd>
<dt>blogname</dt>
<dd>ブログのタイトル</dd>
<dt>blogdescription</dt>
<dd>ブログのサブタイトル</dd>
<dt>blog_charset</dt>
<dd>ブログの文字コード。UTF-8とか</dd>
<dt>date_format</dt>
<dd>日付のフォーマット</dd>
<dt>default_cateogry</dt>
<dd>記事を投稿するときのデフォルトのカテゴリー</dd>
<dt>home</dt>
<dd>ブログのURL</dd>
<dt>siteurl</dt>
<dd>WordPressのサイトのURL</dd>
<dt>template</dt>
<dd>現在のテーマの名前</dd>
<dt>start_of_week</dt>
<dd>週始めをいつからにするか。日曜日か月曜日か。</dd>
<dt>upload_path</dt>
<dd>ファイルをアップロードするときの場所。任意指定可能。</dd>
<dt>posts_per_page</dt>
<dd>トップページやカテゴリーやアーカイブなどの1画面に表示する投稿の最大値。</dd>
<dt>posts_per_rss</dt>
<dd>rssに出力する投稿の最大値</dd>
</dl>
]]></content:encoded>
			<wfw:commentRss>http://bluedb.org/wordpress/archives/61/feed</wfw:commentRss>
		</item>
		<item>
		<title>wp_title - WordPress</title>
		<link>http://bluedb.org/wordpress/archives/60</link>
		<comments>http://bluedb.org/wordpress/archives/60#comments</comments>
		<pubDate>Thu, 25 Oct 2007 02:47:51 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[関数リファレンス]]></category>

		<guid isPermaLink="false">http://bluedb.org/wordpress/archives/60</guid>
		<description><![CDATA[コンテンツのタイトルを出力する関数です。投稿を表示するときには投稿のタイトル、ページを表示するときはページのタイトル、カテゴリーを表示するときはカテゴリーのタイトルを出力します。トップページの場合には何も表示しません。
場所
wp-includes/general-template.php
書式
function wp_title($sep = &#8216;&#38;raquo;&#8217;, $display = true);
説明

string $sep
セパレーター。タイトルの前につく印。初期値は「&rqauo;」
string $display
trueでタイトルを出力。falseで出力を抑制します。

サンプルコード

&#60;?php
wp_title("[セパレータ]", true);
?&#62;

実行結果

[セパレータ] WordPress Hacks

]]></description>
			<content:encoded><![CDATA[<p>コンテンツのタイトルを出力する関数です。投稿を表示するときには投稿のタイトル、ページを表示するときはページのタイトル、カテゴリーを表示するときはカテゴリーのタイトルを出力します。トップページの場合には何も表示しません。</p>
<h3>場所</h3>
<p>wp-includes/general-template.php</p>
<h3>書式</h3>
<p>function wp_title($sep = &#8216;&amp;raquo;&#8217;, $display = true);</p>
<h3>説明</h3>
<dl>
<dt>string $sep</p>
<dd>セパレーター。タイトルの前につく印。初期値は「&rqauo;」</p>
<dt>string $display</p>
<dd>trueでタイトルを出力。falseで出力を抑制します。
</dl>
<h3>サンプルコード</h3>
<pre><code>
&lt;?php
wp_title("[セパレータ]", true);
?&gt;
</code></pre>
<p>実行結果</p>
<blockquote><p>
[セパレータ] WordPress Hacks
</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://bluedb.org/wordpress/archives/60/feed</wfw:commentRss>
		</item>
		<item>
		<title>投稿の数を数えるphpコード</title>
		<link>http://bluedb.org/wordpress/archives/59</link>
		<comments>http://bluedb.org/wordpress/archives/59#comments</comments>
		<pubDate>Fri, 19 Oct 2007 01:56:34 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[MISC]]></category>

		<guid isPermaLink="false">http://bluedb.org/wordpress/archives/59</guid>
		<description><![CDATA[アクセスと投稿の相関を調べるコードを書きたくてとりあえず投稿の数を数えるphpスクリプトを書いてみました。

&#60;?php
$username = "データベースへのログイン名";
$password = "データベースへのログインパスワード";
$dbname = "データベースの名前";

$con = mysql_connect("localhost" , $username , $password);

if (empty($con))
    die("connection failed");

mysql_select_db($dbname);

$sql = "select count(*) from wp_posts where post_type='post'";

$result = mysql_query($sql,$con);

$rows = mysql_fetch_array($result);

echo $dbname . ": " . $rows[0] . "&#60;br&#62;";

mysql_close($con);
?&#62;

テーブルにwp_postsを指定し、whereでpost_typeにpostを指定します。
]]></description>
			<content:encoded><![CDATA[<p>アクセスと投稿の相関を調べるコードを書きたくてとりあえず投稿の数を数えるphpスクリプトを書いてみました。</p>
<pre><code>
&lt;?php
$username = "データベースへのログイン名";
$password = "データベースへのログインパスワード";
$dbname = "データベースの名前";

$con = mysql_connect("localhost" , $username , $password);

if (empty($con))
    die("connection failed");

mysql_select_db($dbname);

$sql = "select count(*) from wp_posts where post_type='post'";

$result = mysql_query($sql,$con);

$rows = mysql_fetch_array($result);

echo $dbname . ": " . $rows[0] . "&lt;br&gt;";

mysql_close($con);
?&gt;
</code></pre>
<p>テーブルにwp_postsを指定し、whereでpost_typeにpostを指定します。</p>
]]></content:encoded>
			<wfw:commentRss>http://bluedb.org/wordpress/archives/59/feed</wfw:commentRss>
		</item>
		<item>
		<title>add_action - WordPress</title>
		<link>http://bluedb.org/wordpress/archives/58</link>
		<comments>http://bluedb.org/wordpress/archives/58#comments</comments>
		<pubDate>Wed, 17 Oct 2007 12:11:02 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[関数リファレンス]]></category>

		<guid isPermaLink="false">http://bluedb.org/wordpress/archives/58</guid>
		<description><![CDATA[場所
wp-includes/plugin.php
書式
function add_action($tag, $function_to_add, $priority = 10, $accepted_args = 1) ;
説明
add_action()は任意の関数をactionに登録するための関数です。add_action()のAPIは

string $tag
$function_to_addの関連付け先の名前
callback $function_to_add
フィルター関数の名前
int $priority
フィルターの優先度。どのフィルターを先に実行するかを指定する。
int $accepted_args
フィルター関数が受け取り可能な引数の数
返り値
フィルターの登録が成功したらture、失敗したらfalseを返します。

サンプルコード

&#60;?php

function test1($arg)
{
    print("[" . $arg . "]\r\n");
}

function test2($arg)
{
    print("+" . $arg . "+\r\n");
}

add_action("bluedb_demo", test1);
add_action("bluedb_demo", test2);

do_action("bluedb_demo", "Hello World");

?&#62;

bluedb_demoという名前のタグに関数test1と関数test2を追加し、do_action()で実行しています。
実行結果

[Hello World]
+Hello World+

]]></description>
			<content:encoded><![CDATA[<h3>場所</h3>
<p>wp-includes/plugin.php</p>
<h3>書式</h3>
<p>function add_action($tag, $function_to_add, $priority = 10, $accepted_args = 1) ;</p>
<h3>説明</h3>
<p>add_action()は任意の関数をactionに登録するための関数です。add_action()のAPIは</p>
<dl>
<dt>string $tag</p>
<dd>$function_to_addの関連付け先の名前</p>
<dt>callback $function_to_add</p>
<dd>フィルター関数の名前</p>
<dt>int $priority</p>
<dd>フィルターの優先度。どのフィルターを先に実行するかを指定する。</p>
<dt>int $accepted_args</p>
<dd>フィルター関数が受け取り可能な引数の数</p>
<dt>返り値</p>
<dd>フィルターの登録が成功したらture、失敗したらfalseを返します。
</dl>
<h3>サンプルコード</h3>
<pre><code>
&lt;?php

function test1($arg)
{
    print("[" . $arg . "]\r\n");
}

function test2($arg)
{
    print("+" . $arg . "+\r\n");
}

add_action("bluedb_demo", test1);
add_action("bluedb_demo", test2);

do_action("bluedb_demo", "Hello World");

?&gt;
</code></pre>
<p>bluedb_demoという名前のタグに関数test1と関数test2を追加し、do_action()で実行しています。</p>
<h3>実行結果</h3>
<pre><code>
[Hello World]
+Hello World+
</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://bluedb.org/wordpress/archives/58/feed</wfw:commentRss>
		</item>
		<item>
		<title>do_action - WordPress</title>
		<link>http://bluedb.org/wordpress/archives/57</link>
		<comments>http://bluedb.org/wordpress/archives/57#comments</comments>
		<pubDate>Wed, 17 Oct 2007 12:09:08 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[関数リファレンス]]></category>

		<guid isPermaLink="false">http://bluedb.org/wordpress/archives/57</guid>
		<description><![CDATA[場所
wp-includes/plugin.php
書式
function do_action($tag, $arg = &#8221;);
説明
$tagに関連付けられたactionを実行します。$argはactionを実行する際のの引数です。1つのactionには1つのtag、複数の関数が登録されています。

string $tag
$function_to_addの関連付け先の名前
 array $arg
引数の配列

サンプルコード

&#60;?php

function test1($arg)
{
    print("[" . $arg . "]\r\n");
}

function test2($arg)
{
    print("+" . $arg . "+\r\n");
}

add_action("bluedb_demo", test1);
add_action("bluedb_demo", test2);

do_action("bluedb_demo", "Hello World");

?&#62;

bluedb_demoという名前のタグに関数test1と関数test2を追加し、do_action()で実行しています。
実行結果

[Hello World]
+Hello World+

]]></description>
			<content:encoded><![CDATA[<h3>場所</h3>
<p>wp-includes/plugin.php</p>
<h3>書式</h3>
<p>function do_action($tag, $arg = &#8221;);</p>
<h3>説明</h3>
<p>$tagに関連付けられたactionを実行します。$argはactionを実行する際のの引数です。1つのactionには1つのtag、複数の関数が登録されています。</p>
<dl>
<dt>string $tag</p>
<dd>$function_to_addの関連付け先の名前</p>
<dt> array $arg</p>
<dd>引数の配列
</dl>
<h3>サンプルコード</h3>
<pre><code>
&lt;?php

function test1($arg)
{
    print("[" . $arg . "]\r\n");
}

function test2($arg)
{
    print("+" . $arg . "+\r\n");
}

add_action("bluedb_demo", test1);
add_action("bluedb_demo", test2);

do_action("bluedb_demo", "Hello World");

?&gt;
</code></pre>
<p>bluedb_demoという名前のタグに関数test1と関数test2を追加し、do_action()で実行しています。</p>
<h3>実行結果</h3>
<pre><code>
[Hello World]
+Hello World+
</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://bluedb.org/wordpress/archives/57/feed</wfw:commentRss>
		</item>
		<item>
		<title>[Hook] do_action()</title>
		<link>http://bluedb.org/wordpress/archives/54</link>
		<comments>http://bluedb.org/wordpress/archives/54#comments</comments>
		<pubDate>Wed, 17 Oct 2007 08:42:47 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[ソースコード解読]]></category>

		<guid isPermaLink="false">http://bluedb.org/wordpress/archives/54</guid>
		<description><![CDATA[do_actionは任意の$tagに関連付けられている全ての関数を実行します。$tagと関数の関連付けは前回説明したadd_action()で行われます。APIは

$tag
任意のアクションに関連付けられたtag。文字列。
$arg
引数。可変長。

という感じです。返り値は持たないみたいです。ソースコードを以下に示します。

function do_action($tag, $arg = '') {
    global $wp_filter, $wp_actions;

    if ( is_array($wp_actions) )
        $wp_actions[] = $tag;
    else
        $wp_actions = array($tag);

    $args = array();
    if ( is_array($arg) [...]]]></description>
			<content:encoded><![CDATA[<p>do_actionは任意の$tagに関連付けられている全ての関数を実行します。$tagと関数の関連付けは前回説明した<a href="http://bluedb.org/wordpress/archives/55">add_action()</a>で行われます。APIは</p>
<dl>
<dt>$tag</p>
<dd>任意のアクションに関連付けられたtag。文字列。</p>
<dt>$arg</p>
<dd>引数。可変長。
</dl>
<p>という感じです。返り値は持たないみたいです。ソースコードを以下に示します。</p>
<pre><code>
function do_action($tag, $arg = '') {
    global $wp_filter, $wp_actions;

    if ( is_array($wp_actions) )
        $wp_actions[] = $tag;
    else
        $wp_actions = array($tag);

    $args = array();
    if ( is_array($arg) &amp;&amp; 1 == count($arg) &amp;&amp; is_object($arg[0]) ) // array(&amp;$this)
        $args[] =&amp; $arg[0];
    else
        $args[] = $arg;
    for ( $a = 2; $a &lt; func_num_args(); $a++ )
        $args[] = func_get_arg($a);

    merge_filters($tag);

    if ( !isset($wp_filter[$tag]) )
        return;

    do{
        foreach( (array) current($wp_filter[$tag]) as $the_ )
            if ( !is_null($the_['function']) )
                call_user_func_array($the_['function'], array_slice($args, 0, (int) $the_['accepted_args']));

    } while ( next($wp_filter[$tag]) !== false );

}
</code></pre>
<p>処理をざっくりと説明すると、</p>
<ol>
<li>$argを配列に展開
<li>$wp_filter[$tag]に登録されている関数名をpriority順に読み出す
<li>読み出した関数名と展開した$argをphp関数であるcall_user_func_array()で関数を呼ぶ
</ol>
<p>という感じになっています。</p>
<h3>サンプルコード</h3>
<pre><code>
do_action('init');
</code></pre>
<p>これはwp-settings.phpの一番最後に記述されているコードです。initというactionを呼び出しています。init tagに対する登録は<a href="http://bluedb.org/wordpress/archives/55">前回のサンプルコード</a>で示した通りです。このdo_action(&#8217;init&#8217;)でWordPressが使用するさまざまなライブラリの初期化関数を一度に呼び出しています。</p>
]]></content:encoded>
			<wfw:commentRss>http://bluedb.org/wordpress/archives/54/feed</wfw:commentRss>
		</item>
		<item>
		<title>[Hook] add_action()</title>
		<link>http://bluedb.org/wordpress/archives/55</link>
		<comments>http://bluedb.org/wordpress/archives/55#comments</comments>
		<pubDate>Wed, 17 Oct 2007 08:23:39 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[ソースコード解読]]></category>

		<guid isPermaLink="false">http://bluedb.org/wordpress/archives/55</guid>
		<description><![CDATA[add_action()は任意の関数をactionに登録するための関数です。add_action()のAPIは

string $tag
$function_to_addの関連付け先の名前
callback $function_to_add
フィルター関数の名前
int $priority
フィルターの優先度。どのフィルターを先に実行するかを指定する。
int $accepted_args
フィルター関数が受け取り可能な引数の数
返り値
フィルターの登録が成功したらture、失敗したらfalseを返します。

となっています。これを見て分かるとおり、add_action()と前回述べたadd_filter()は全く同じです。

function add_action($tag, $function_to_add, $priority = 10, $accepted_args = 1) {
    add_filter($tag, $function_to_add, $priority, $accepted_args);
}

サンプル

add_action('init', 'kses_init');

これはwp-includes/kses.phpに記述されている処理です。kses.phpはコメントのタグをチェックするためのライブラリです。ここではinitというtagにkses_initという関数を登録しています。このように、initというtagにはさまざまなライブラリの初期化関数が登録されています。
]]></description>
			<content:encoded><![CDATA[<p>add_action()は任意の関数をactionに登録するための関数です。add_action()のAPIは</p>
<dl>
<dt>string $tag</p>
<dd>$function_to_addの関連付け先の名前</p>
<dt>callback $function_to_add</p>
<dd>フィルター関数の名前</p>
<dt>int $priority</p>
<dd>フィルターの優先度。どのフィルターを先に実行するかを指定する。</p>
<dt>int $accepted_args</p>
<dd>フィルター関数が受け取り可能な引数の数</p>
<dt>返り値</p>
<dd>フィルターの登録が成功したらture、失敗したらfalseを返します。
</dl>
<p>となっています。これを見て分かるとおり、add_action()と前回述べた<a href="http://bluedb.org/wordpress/archives/50">add_filter()</a>は全く同じです。</p>
<pre><code>
function add_action($tag, $function_to_add, $priority = 10, $accepted_args = 1) {
    add_filter($tag, $function_to_add, $priority, $accepted_args);
}
</code></pre>
<h3>サンプル</h3>
<pre><code>
add_action('init', 'kses_init');
</code></pre>
<p>これはwp-includes/kses.phpに記述されている処理です。kses.phpはコメントのタグをチェックするためのライブラリです。ここではinitというtagにkses_initという関数を登録しています。このように、initというtagにはさまざまなライブラリの初期化関数が登録されています。</p>
]]></content:encoded>
			<wfw:commentRss>http://bluedb.org/wordpress/archives/55/feed</wfw:commentRss>
		</item>
		<item>
		<title>検索にGoogleを利用する方法</title>
		<link>http://bluedb.org/wordpress/archives/53</link>
		<comments>http://bluedb.org/wordpress/archives/53#comments</comments>
		<pubDate>Tue, 16 Oct 2007 18:42:18 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[テーマHacks]]></category>

		<guid isPermaLink="false">http://bluedb.org/wordpress/archives/53</guid>
		<description><![CDATA[WordPressの検索にGoogleを使う方法です。
「Googleで自分のホームページ内を検索」を利用してフォームのHTMLを取得します。



















&#60;form method="get" action="http://www.google.co.jp/custom" target="_top"a&#62;
&#60;table width="100%"&#62;
&#60;tr&#62;&#60;td&#62;
&#60;a href="http://www.google.com/"&#62;
&#60;img src="http://www.google.com/logos/Logo_25wht.gif" alt="Google" align="middle" style="border:none;"&#62;&#60;/img&#62;&#60;/a&#62;
&#60;input type="text" name="q" size="40" maxlength="255" value="" id="sbi"&#62;&#60;/input&#62;
&#60;input type="submit" name="sa" value="サイト内を検索" id="sbb"&#62;&#60;/input&#62;
&#60;input type="hidden" name="domains" value="bluedb.org"&#62;&#60;/input&#62;
&#60;input type="hidden" name="sitesearch" value="bluedb.org" id="ss1"&#62;&#60;/input&#62;
&#60;input type="hidden" name="client" value="pub-5778690733142083"&#62;&#60;/input&#62;
&#60;input type="hidden" name="forid" value="1"&#62;&#60;/input&#62;
&#60;input type="hidden" name="ie" value="UTF-8"&#62;&#60;/input&#62;
&#60;input type="hidden" name="oe" value="UTF-8"&#62;&#60;/input&#62;
&#60;input type="hidden" name="hl" value="ja"&#62;&#60;/input&#62;
&#60;/td&#62;
&#60;/tr&#62;
&#60;/table&#62;
&#60;/form&#62;

このソースコードを自分好みに整形してテーマのheader.phpやsidebar.phpに貼り付ければ自分のサイトだけを検索してくれるGoogle検索フォームの完成です。
























&#60;center&#62;
&#60;form method="get" action="http://www.google.co.jp/custom" target="_top"a&#62;
&#60;table&#62;
&#60;tr&#62;&#60;td&#62;
&#60;input type="text" name="q" size="25" maxlength="255" value="" id="sbi"&#62;&#60;/input&#62;
&#60;input type="hidden" name="domains" value="bluedb.org/wordpress"&#62;&#60;/input&#62;
&#60;input type="hidden" [...]]]></description>
			<content:encoded><![CDATA[<p>WordPressの検索にGoogleを使う方法です。</p>
<p>「<a href="http://bluedb.org/ajax/archives/10">Googleで自分のホームページ内を検索</a>」を利用してフォームのHTMLを取得します。</p>
<form method="get" action="http://www.google.co.jp/custom" target="_top"a>
<table width="100%">
<tr>
<td>
<a href="http://www.google.com/"><img src="http://www.google.com/logos/Logo_25wht.gif" alt="Google" align="middle" style="border:none;"></img></a><br />
<input type="text" name="q" size="40" maxlength="255" value="" id="sbi"></input>
<input type="submit" name="sa" value="サイト内を検索" id="sbb"></input>
<input type="hidden" name="domains" value="bluedb.org/wordpress"></input>
<input type="hidden" name="sitesearch" value="bluedb.org/wordpress" id="ss1"></input>
<input type="hidden" name="client" value="pub-5778690733142083"></input>
<input type="hidden" name="forid" value="1"></input>
<input type="hidden" name="ie" value="UTF-8"></input>
<input type="hidden" name="oe" value="UTF-8"></input>
<input type="hidden" name="hl" value="ja"></input>
</td>
</tr>
</table>
</form>
<pre><code>
&lt;form method="get" action="http://www.google.co.jp/custom" target="_top"a&gt;
&lt;table width="100%"&gt;
&lt;tr&gt;&lt;td&gt;
&lt;a href="http://www.google.com/"&gt;
&lt;img src="http://www.google.com/logos/Logo_25wht.gif" alt="Google" align="middle" style="border:none;"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;input type="text" name="q" size="40" maxlength="255" value="" id="sbi"&gt;&lt;/input&gt;
&lt;input type="submit" name="sa" value="サイト内を検索" id="sbb"&gt;&lt;/input&gt;
&lt;input type="hidden" name="domains" value="bluedb.org"&gt;&lt;/input&gt;
&lt;input type="hidden" name="sitesearch" value="bluedb.org" id="ss1"&gt;&lt;/input&gt;
&lt;input type="hidden" name="client" value="pub-5778690733142083"&gt;&lt;/input&gt;
&lt;input type="hidden" name="forid" value="1"&gt;&lt;/input&gt;
&lt;input type="hidden" name="ie" value="UTF-8"&gt;&lt;/input&gt;
&lt;input type="hidden" name="oe" value="UTF-8"&gt;&lt;/input&gt;
&lt;input type="hidden" name="hl" value="ja"&gt;&lt;/input&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/form&gt;
</code></pre>
<p>このソースコードを自分好みに整形してテーマのheader.phpやsidebar.phpに貼り付ければ自分のサイトだけを検索してくれるGoogle検索フォームの完成です。</p>
<p><center></p>
<form method="get" action="http://www.google.co.jp/custom" target="_top"a>
<table>
<tr>
<td>
<input type="text" name="q" size="25" maxlength="255" value="" id="sbi"></input>
<input type="hidden" name="domains" value="bluedb.org/wordpress"></input>
<input type="hidden" name="sitesearch" value="bluedb.org/wordpress" id="ss1"></input>
<input type="hidden" name="client" value="pub-5778690733142083"></input>
<input type="hidden" name="forid" value="1"></input>
<input type="hidden" name="ie" value="UTF-8"></input>
<input type="hidden" name="oe" value="UTF-8"></input>
<input type="hidden" name="hl" value="ja"></input>
</td>
</tr>
<tr>
<td>
<input type="submit" name="sa" value="サイト内を検索" id="sbb"></input>
</td>
</tr>
</table>
</form>
<p></center></p>
<pre><code>
&lt;center&gt;
&lt;form method="get" action="http://www.google.co.jp/custom" target="_top"a&gt;
&lt;table&gt;
&lt;tr&gt;&lt;td&gt;
&lt;input type="text" name="q" size="25" maxlength="255" value="" id="sbi"&gt;&lt;/input&gt;
&lt;input type="hidden" name="domains" value="bluedb.org/wordpress"&gt;&lt;/input&gt;
&lt;input type="hidden" name="sitesearch" value="bluedb.org/wordpress" id="ss1"&gt;&lt;/input&gt;
&lt;input type="hidden" name="client" value="pub-5778690733142083"&gt;&lt;/input&gt;
&lt;input type="hidden" name="forid" value="1"&gt;&lt;/input&gt;
&lt;input type="hidden" name="ie" value="UTF-8"&gt;&lt;/input&gt;
&lt;input type="hidden" name="oe" value="UTF-8"&gt;&lt;/input&gt;
&lt;input type="hidden" name="hl" value="ja"&gt;&lt;/input&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;input type="submit" name="sa" value="サイト内を検索" id="sbb"&gt;&lt;/input&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/form&gt;
&lt;/center&gt;
</code></pre>
<p></p>
<h3>メリット</h3>
<p>WordPressの検索はMySQLの機能を使っているだけなのでデータの量が増えれば増えるほど検索が遅くなります。それに対してGoogleの検索エンジンを利用することでデータの量が増えても高速に検索ができ、WordPressが動作しているサーバーへの負担もかけません。</p>
<h3>デメリット</h3>
<p>データベースの更新にはGoogleのSpiderが見に来る時間に依存します。つまり結構遅いです。また、検索結果がGoogleのページになってしまうという問題点もあります。ただ、フレームを利用したりすることであたかもWordPressで検索したかのように表示することもできなくはありません。</p>
]]></content:encoded>
			<wfw:commentRss>http://bluedb.org/wordpress/archives/53/feed</wfw:commentRss>
		</item>
		<item>
		<title>サイドバーにページを埋め込む</title>
		<link>http://bluedb.org/wordpress/archives/52</link>
		<comments>http://bluedb.org/wordpress/archives/52#comments</comments>
		<pubDate>Tue, 16 Oct 2007 12:14:49 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[テーマHacks]]></category>

		<guid isPermaLink="false">http://bluedb.org/wordpress/archives/52</guid>
		<description><![CDATA[サイドバーにページを埋め込む、といってもちょっと分かり辛いかもしれません。やりたいことはサイドバーにGoogleの検索窓を作ることです。ただ、sidebar.phpに直接HTMLを書き込むのはダサいのでなんとかサイドバーにページを埋め込んで管理画面で微調整ができるようにしたいと思いました。
やり方は簡単です。サイドバーに次のようなコードを書き込みます。

&#60;?php query_posts('&#38;pagename=sitesearch'); ?&#62;
&#60;?php the_post(); ?&#62;
&#60;?php the_content(); ?&#62;

query_posts(&#8217;&#38;pagename=sitesearch&#8217;)はどういう意味かというと、Post Slugがsitesearchであるデータに対してクエリをするというものです。つまり、ページを作成するときにPost Slugにsitesearchを指定しておけばここで読み込むことができます。
the_post()はデータを呼び出すための関数です。これは必ず呼ばなければなりません。
the_content()はページのテキストデータです。
以上でページの埋め込みは終了です。
注意
sidebarがコンテンツよりも前にある場合にquery_posts()関数がコンテンツのthe_post()を壊してしまう可能性があります。なのでこのテクニックはサイドバーはコンテンツを読み込んだ後に用いることをお勧めします。
]]></description>
			<content:encoded><![CDATA[<p>サイドバーにページを埋め込む、といってもちょっと分かり辛いかもしれません。やりたいことはサイドバーにGoogleの検索窓を作ることです。ただ、sidebar.phpに直接HTMLを書き込むのはダサいのでなんとかサイドバーにページを埋め込んで管理画面で微調整ができるようにしたいと思いました。</p>
<p>やり方は簡単です。サイドバーに次のようなコードを書き込みます。</p>
<pre><code>
&lt;?php query_posts('&amp;pagename=sitesearch'); ?&gt;
&lt;?php the_post(); ?&gt;
&lt;?php the_content(); ?&gt;
</code></pre>
<p>query_posts(&#8217;&amp;pagename=sitesearch&#8217;)はどういう意味かというと、Post Slugがsitesearchであるデータに対してクエリをするというものです。つまり、ページを作成するときにPost Slugにsitesearchを指定しておけばここで読み込むことができます。</p>
<p>the_post()はデータを呼び出すための関数です。これは必ず呼ばなければなりません。</p>
<p>the_content()はページのテキストデータです。</p>
<p>以上でページの埋め込みは終了です。</p>
<h3>注意</h3>
<p>sidebarがコンテンツよりも前にある場合にquery_posts()関数がコンテンツのthe_post()を壊してしまう可能性があります。なのでこのテクニックはサイドバーはコンテンツを読み込んだ後に用いることをお勧めします。</p>
]]></content:encoded>
			<wfw:commentRss>http://bluedb.org/wordpress/archives/52/feed</wfw:commentRss>
		</item>
		<item>
		<title>[Hooks] add_filter()</title>
		<link>http://bluedb.org/wordpress/archives/50</link>
		<comments>http://bluedb.org/wordpress/archives/50#comments</comments>
		<pubDate>Tue, 16 Oct 2007 04:53:47 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[ソースコード解読]]></category>

		<guid isPermaLink="false">http://bluedb.org/wordpress/archives/50</guid>
		<description><![CDATA[WordPressのHookは$wp_filterを中心に行われます。なので$wp_filterが各APIによってどのように扱われているかを見ればWordPressのHookの本質が見えてくるでしょう。Hookするための関数はwp-includes/plugin.phpに記述されています。
まずはfilterを追加するための関数であるadd_filter()関数から読みたいと思います。
フィルターはデータベースとブラウザの間に入り、テキストを変換するための機構です。例えばデータベースから読み込んだデータをフィルターで加工してブラウザーに表示したり、ブラウザーから入力されたデータを加工してデータベースに突っ込んだりします。PHPの関数に関連付けられたプラグインはフィルターAPIを用いてテキストデータを加工します。add_filterのAPIは

string $tag
$function_to_addの関連付け先の名前
callback $function_to_add
フィルター関数の名前
int $priority
フィルターの優先度。どのフィルターを先に実行するかを指定する。
int $accepted_args
フィルター関数が受け取り可能な引数の数
返り値
フィルターの登録が成功したらture、失敗したらfalseを返します。

add_filter()関数のソースコードは以下の通りです。

function add_filter($tag, $function_to_add, $priority = 10, $accepted_args = 1) {
    global $wp_filter, $merged_filters;

    $idx = _wp_filter_build_unique_id($tag, $function_to_add, $priority);
    $wp_filter[$tag][$priority][$idx] = array('function' =&#62; $function_to_add, 'accepted_args' =&#62; $accepted_args);
    unset( $merged_filters[ $tag ] );
    return true;
}

まず、_wp_filter_build_unique_id()関数で追加するフィルター関数へのユニークIDを作成します。$function_to_addが関数名の場合には$function_to_addがそのままユニークIDになります。
$wp_filterは3次元配列に成っており,$tag、$priority、$idx（ユニークID）を添え字としてフィルター関数へのポインタを保持します。
サンプルコード

add_filter('the_content', 'wptexturize');

the_content()関数にwptexturize()関数をフィルターとして登録しています。wptexturize()関数はwp-includes/formatting.phpに記述されており、コンテンツを整形する機能を持っています。
]]></description>
			<content:encoded><![CDATA[<p>WordPressのHookは$wp_filterを中心に行われます。なので$wp_filterが各APIによってどのように扱われているかを見ればWordPressのHookの本質が見えてくるでしょう。Hookするための関数はwp-includes/plugin.phpに記述されています。</p>
<p>まずはfilterを追加するための関数であるadd_filter()関数から読みたいと思います。</p>
<p>フィルターはデータベースとブラウザの間に入り、テキストを変換するための機構です。例えばデータベースから読み込んだデータをフィルターで加工してブラウザーに表示したり、ブラウザーから入力されたデータを加工してデータベースに突っ込んだりします。PHPの関数に関連付けられたプラグインはフィルターAPIを用いてテキストデータを加工します。add_filterのAPIは</p>
<dl>
<dt>string $tag</p>
<dd>$function_to_addの関連付け先の名前</p>
<dt>callback $function_to_add</p>
<dd>フィルター関数の名前</p>
<dt>int $priority</p>
<dd>フィルターの優先度。どのフィルターを先に実行するかを指定する。</p>
<dt>int $accepted_args</p>
<dd>フィルター関数が受け取り可能な引数の数</p>
<dt>返り値</p>
<dd>フィルターの登録が成功したらture、失敗したらfalseを返します。
</dl>
<p>add_filter()関数のソースコードは以下の通りです。</p>
<pre><code>
function add_filter($tag, $function_to_add, $priority = 10, $accepted_args = 1) {
    global $wp_filter, $merged_filters;

    $idx = _wp_filter_build_unique_id($tag, $function_to_add, $priority);
    $wp_filter[$tag][$priority][$idx] = array('function' =&gt; $function_to_add, 'accepted_args' =&gt; $accepted_args);
    unset( $merged_filters[ $tag ] );
    return true;
}
</code></pre>
<p>まず、_wp_filter_build_unique_id()関数で追加するフィルター関数へのユニークIDを作成します。$function_to_addが関数名の場合には$function_to_addがそのままユニークIDになります。</p>
<p>$wp_filterは3次元配列に成っており,$tag、$priority、$idx（ユニークID）を添え字としてフィルター関数へのポインタを保持します。</p>
<h3>サンプルコード</h3>
<pre><code>
add_filter('the_content', 'wptexturize');
</code></pre>
<p>the_content()関数にwptexturize()関数をフィルターとして登録しています。wptexturize()関数はwp-includes/formatting.phpに記述されており、コンテンツを整形する機能を持っています。</p>
]]></content:encoded>
			<wfw:commentRss>http://bluedb.org/wordpress/archives/50/feed</wfw:commentRss>
		</item>
	</channel>
</rss>
