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

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

「2008年12月」の記事

WordPress MUのトップページに各ブログの新着記事を表示する[Permanent Link]

WPMUのテンプレートに各ブログの最新記事を表示するコードがなかったので、作ってみました。

<h2>新着</h2>

<div id="new-entries">

<?php
for ($i = 0; $i < get_blog_count(); $i++) :

    $blog_list = get_blog_list();
    $blog_list = $blog_list[$i]['blog_id'];

    if ($blog_list != 1) :

        $output_blogs = '<h3><a href="' .
            get_blog_option($blog_list,'siteurl') . '">' .
            get_blog_option($blog_list,'blogname') .
            '</a></h3>';
        $output_blogs .= '<p class="blog-description">' .
            get_blog_option($blog_list,'blogdescription') .
            '</p>';
        echo $output_blogs;

        $wpdb->set_blog_id($blog_list);
        query_posts("showposts=3&post_status=publish");
?>

<?php if (have_posts()) : while(have_posts()) : the_post();?>

    <div class="new-entry-bd">

        <h4><a href="<?=$post->guid;?>"><?=$post->post_title;?></a></h4>

<?php if (trim(strip_tags($post->post_content)) != '') :? >
        <p><?php echo mb_substr(strip_tags($post->post_content), 0, 100);?> [...]</p>
<?php endif;?>

        <p class="update"><?php echo date('Y年n月j日', strtotime($post->post_date));?></p>

    </div>

<?php endwhile; endif; endif; endfor;?>

</div>
for ($i = 0; $i < get_blog_count(); $i++) : [...] endfor;

get_blog_count()でブログ数を取得します。ブログの数だけループさせます。

$blog_list = get_blog_list();

get_blog_list()で各ブログの情報を取得します。

if ($blog_list != 1) : [...] endif;

ホームページのブログを除きます。

get_blog_option($blog_list,'siteurl')

get_blog_option()で各ブログの設定を返します。第2引数にsiteurlを指定してブログのURLを返します。

get_blog_option($blog_list,'blogname')

ブログ名を返します。

get_blog_option($blog_list,'blogdescription')

ブログの説明を返します。

$wpdb->set_blog_id($blog_list);

ブログを指定してデータベースに接続します。

query_posts("showposts=3&post_status=publish");

公開記事3件を取得します。

以下のように表示されます。

maaguu.com 20081218

ポイントを現金でキャッシュバック

ユーザエージェント(User Agent、Webブラウザなど)を判別し、別ページを表示する[Permanent Link]

Internet Explorer 6を判別して別ページを表示するプラグインのサンプル。

IE6ハックとかやりたくないので作ってみました。「IE6には対応してないよ、ごめんなさい」というページを表示するだけ。

<?php
/*
Plugin Name: maaguu_replace_page.php
Plugin URI: http://wp.maaguu.com/2008/12/15/replace-page/
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_replacePage
{

    private $userAgent;
    private $pattern_ie6;

    public function __construct()
    {
        $this->userAgent = $_SERVER['HTTP_USER_AGENT'];
        $this->pattern_ie6 = '/MSIE 6/';
        add_action('template_redirect', array($this, 'replace_page'));
    }

    public function replace_page()
    {
        if (preg_match($this->pattern_ie6, $this->userAgent))
        {
            include(TEMPLATEPATH . '/ie6.php');
            exit;
        }
    }

}

new maaguu_replacePage();

/* End of file maaguu_replace_page.php */

プラグインを有効にして、テンプレートディレクトリにie6.phpを置きます。

ポイントを現金でキャッシュバック

プリント(印刷)用CSSを作る[Permanent Link]

このサイトのプリント用CSSを考えてみる。

  • このサイトのデザイン(Webブラウザに表示された見た目の部分限定)を印刷する人はいないだろう(「それはわからない」「あなたの思いこみです」と誰かが指摘する)。
  • このサイトのコンテンツを見に来る人はWordPressについて知りたい人だ(「デザインを見たい人かもしれないし」と誰かが指摘する)。
  • このサイトのソースコードなどを印刷して手元で見たい人がいるかもしれない(「そもそも印刷する人は画面に映ったモノそのままを見たいと思うもんだよ。他の誰かに見せる場合もあるしね」と誰かが指摘する)。

ご指摘は有り難いのですが、このサイトの場合は見送りいたします(^^)

コンテンツを印刷できれば十分。それが見やすい読みやすい。それ以外を求める場合はスクリーンショットを撮って印刷すればよろしい(「見た目そのままを印刷したいと思う人はそんなスキルないし、そんなことしたら文字読めないよ」と誰かが指摘する)。

じゃあ、印刷ボタンを押すと、スクリーンショットを撮ってPDFにして印刷するプログラム書けばいいかも。買ってくれる人いるかもしれんし、流行るかもしれんです。

さて、参考までにprint.cssのソースコードを。

@media print
{
    *
    {
        font-style: normal;
    }
    body
    {
        font-family: serif;
        font-size: 12pt;
    }
    #hd
    {
        border: dashed 2pt #000;
        border-left: none;
        border-right: none;
        text-align: center;
    }
    #hd-link
    {
        display: none;
    }

        #bd .entry-hd
        {
            border: dashed 1pt #000;
            border-left: none;
            border-right: none;
            margin-top: 1em;
        }
                #bd .entry-hd h2 span
                {
                    display: none;
                }
        #bd .entry-nv
        {
            display: none;
        }

    #sd
    {
        display: none;
    }
    #ft
    {
        border-top: dashed 2pt #000;
        margin-top: 2em;
        padding-top: 1em;
    }
        #ft address
        {
            font-family: sans-serif;
            text-align: center;
        }
        #ft #link
        {
            display: none;
        }

    code
    {
        font-family: "Courier New", "Ludica Console", monospace;
    }
    a
    {
        color: #000;
        text-decoration: none;
    }
    a:after
    {
        content: "[URI: "attr(href)"]";
        color: #000;
        font-family: sans-serif;
        font-size: 80%;
    }
    ins
    {
        text-decoration: none;
        border-bottom: dotted .5pt #000;
    }
    ins:before
    {
        content: "[PostScript]: ";
    }
    ins:after
    {
        content: "("attr(datetime)")";
        font-size: 80%;
    }
}

ここで問題発見。insのdatetimeが00になってしまっているなあ。

あれれ、sampがエスケープされる。これってどこで設定するのかな?

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