WordPress maaguu (^^; com 北海道札幌でホームページ制作を楽しむ

WordPress, WordPress MU(μ) についての話題、プラグイン作成、カスタマイズ。

カテゴリー「plugins」の記事

WordPress MUのフッタを共用化したい[Permanent Link]

このサイトはWordPress MUで構築していますが、各ブログによってスタイルを変えています。とは言うものの、色違いの同スタイルといった形になっていて、HTMLはほぼ同一でCSSが違うだけです。ですので、今後のメンテナンスを考えると、共用部分は一カ所に纏めておきたいと思うのです。

そこで、試しにフッタ部分をプラグインでひとつにすることにしました。プラグインを使わずに効率のいい方法が他にあるかもしれませんが、それはさておき、プラグイン作成の練習を兼ねて、フッタ表示のプラグインを作ってみます。

<?php
/*
Plugin Name: maaguu_footer.php
Plugin URI:
Description:
Version: 1.0
Author: maaguu
Author URI: http://maaguu.com/
*/

/*  Copyright 2008 maaguu (email : info@mx.maaguu.com)

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/

class maaguu_footer
{
    public function __construct()
    {
        add_action('get_footer', array($this, 'echo_footer'));
    }
    public function echo_footer()
    {
        global $admin_email, $footer_html;
        $admin_email = get_bloginfo('admin_email');
        $footer_html = "

    <div id=\"ft\" class=\"c\">

        <div id=\"link\">
            <h2>link</h2>
            <ul>
                <li><a href=\"http://d.hatena.ne.jp/maa\">maaguu (^^; memo</a></li>
            </ul>
        </div>
        <!-- #link -->

        <address>
            Email to maaguu:<a href=\"mailto:" . $admin_email . "\">" . $admin_email . "</a>
            Powered by <a href=\"http://mu.wordpress.org/\">WordPress MU</a>
        </address>

    </div>
    <!-- #ft -->

</div>
<!-- #wp -->

<script type=\"text/javascript\">
var gaJsHost = ((\"https:\" == document.location.protocol) ? \"https://ssl.\" : \"http://www.\");
document.write(unescape(\"%3Cscript src='\" + gaJsHost + \"google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E\"));
</script>
<script type=\"text/javascript\">
try {
var pageTracker = _gat._getTracker(\"UA-200597-8\");
pageTracker._trackPageview();
} catch(err) {}
</script>
</body>
</html>

        ";

        echo $footer_html;

    }
}

new maaguu_footer();

/* End of file maaguu_footer.php */

こんなんでいいんでしょうか……。なんか全然スマートではないですね(^^ゞ(クラスのコードがなんか変?) プラグインフォルダにアップロードして有効化して既存のfooter.phpを空にすると動きましたので、差し当たってはよしとさせてください。

HTMLのテンプレート部分をデータベースに保存して、管理画面から入力できるようにするともっと便利でしょうが、それは今後の課題にします(つか、そういうプラグイン、ありそうですね。あんま調べてないんで……)。

ポイントを現金でキャッシュバック
Email to maaguu:info@mx.maaguu.com Powered by WordPress MU Clicky Web Analytics