ウエッブサイトをWordPressに変更

AWL'sWorldのトップページをWordPressで作成

ウエッブサイトは現在4つ運営しています
■HTMLで構築して長い間運営していたAWL’sWorld
■WordPressで構築しているブログAWL Action(ブログ)、今はこれがメイン
■ブログを試すために始めた、スペースを借りているブログのAWL温泉ざんまい
■お仕事用にWoedPressで構築したシステムアップ
とてもじゃないが面倒が見きれないので、AWL温泉ざんまいは1年前からインデックスのみ更新しています
今回はAWL’sWorldAWL ActionのWordPressに統合することにしました
これでHTMLは弄ることが無くなる
AWL’sWorldのトップページはブログを投稿すれば自動で更新されます


AWL’sWorldのトップページはカテゴリー毎のページリンクが数多く掲載されている形式なので、WordPressの固定ページで作成するのはなかなか難しい
テンプレートも変更しなければならないのと、多くのカテゴリーを表示するためのプラグインを見つける必要があります
以前は適したプラグインを使っていたのですがWordPressを3.0.0にバージョンアップすると使えなくなりました
昨日、ほとんど一日中探してようやく希望するプラグインが見つかり、コードを改造して使用することにします
新しいテンプレートのページはPHPを少し理解する必要があり四苦八苦・・・何とか動くようにできました
新しくWordPressで作成したAWL’sWorldのトップページです

これからはコードと構築の備忘録

新しいトップページ用のテンプレートを、WordPressで使っているテーマのディレクトリに作成する
テンプレートが作成できればWordPressのダッユボードのページ設定画面からデフォルトのテンプレート以外が選択できる
PHPのテンプレート作成はコードの最初に以下を記入しておく必要がある

[php]
<!–?php
/*
Template Name: AWL’sWorld
*/
?–>
[/php]

今回はAWL’sWorldという名前のテンプレートを作成
使用しているテーマのindex.phpを参考にしてテンプレートを作成するがこれがなかなか難しい
四苦八苦して書いたコードを記述しておきます

[php]
<!–?php
/*
Template Name: AWL’sWorld
*/
?–>
<!–?php
/*
if index.php or another page template (copied from index.php) was not used (i.e. by a plugin such as WPG2), the global $bfa_ata would be empty
*/
global $bfa_ata, $cols, $left_col, $left_col2, $right_col, $right_col2; // if ($bfa_ata == "") include_once (TEMPLATEPATH . ‘/functions/bfa_get_options.php’); ?–>
<!–?php if ( $bfa_ata[‘css_external’] == "External" ) { ?–>

<!–?php } ?–>
<!–?php include (TEMPLATEPATH . ‘/functions/bfa_meta_tags.php’); ?–>
<!–?php if ($bfa_ata[‘favicon_file’] != "") { ?–>
<!–?php } ?–>
<!–?php if ( is_single() OR is_page() ) { ?–>
<!–?php } ?–>

<!–?php wp_enqueue_script( ‘jquery’ ); ?–>
<!–?php if ( function_exists(‘wp_list_comments’) AND is_singular() ) { wp_enqueue_script( ‘comment-reply’ ); } ?–>
<!–?php wp_head(); ?–>
<!–?php bfa_html_inserts($bfa_ata[‘html_inserts_header’]); ?–>
<!–?php if ($bfa_ata[‘pngfix_selectors’] != "") { ?–>
<!–[if IE 6]>
<mce:script type="text/javascript" mce_src="&lt;?php bloginfo(‘template_directory’); ?"><!
/js/DD_roundies.js">
// –>
<script type="text/javascript"><!–mce:0–></script>
<!–[endif] –>
<!–?php } ?–>
<!–?php if (strpos($bfa_ata[‘configure_header’],’%image’)!== FALSE AND $bfa_ata[‘header_image_javascript’] != "0" AND $bfa_ata[‘crossslide_fade’] != "0") { ?–>
<script src="&lt;?php bloginfo(‘template_directory’); ?" type="text/javascript"><!–mce:1–></script>
<!–?php } ?–>
<!–?php if ( ($bfa_ata[‘animate_page_menu_bar’] == "Yes" AND strpos($bfa_ata[‘configure_header’],’%page’)!== FALSE ) OR ( $bfa_ata[‘animate_cat_menu_bar’] == "Yes" AND strpos($bfa_ata[‘configure_header’],’%cat’)!== FALSE ) ) { ?–>
<script src="&lt;?php bloginfo(‘template_directory’); ?" type="text/javascript"><!–mce:2–></script>
<script src="&lt;?php bloginfo(‘template_directory’); ?" type="text/javascript"><!–mce:3–></script>
<script type="text/javascript"><!–mce:4–></script>
<!–?php } ?–>

<!–?php if ($bfa_ata[‘html_inserts_body_tag’] != "") { echo ‘ ‘; bfa_html_inserts($bfa_ata[‘html_inserts_body_tag’]); } ?–>&gt;
<!–?php bfa_html_inserts($bfa_ata[‘html_inserts_body_top’]); ?–>
<div id="wrapper">
<div id="container">
<object id="2008_Top" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="960" height="300" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowScriptAccess" value="sameDomain" /><param name="loop" value="false" /><param name="menu" value="false" /><param name="quality" value="high" /><param name="src" value="/Top/2008/2008_Top.swf" /><param name="name" value="2008_Top" /><embed id="2008_Top" type="application/x-shockwave-flash" width="960" height="300" src="/Top/2008/2008_Top.swf" name="2008_Top" quality="high" menu="false" loop="false" allowscriptaccess="sameDomain"></embed></object>

<!–?php if (have_posts()) : while (have_posts()) : the_post();?–>
<div>
<!–?php the_content(); ?–></div>
<!–?php endwhile; endif; ?–>
<div>
<!–?php get_footer(); ?–></div>
</div>
</div>
[/php]

これでテンプレートはできたのでカテゴリー毎に並べるプラグインの改造です
見つけたプラグインはCategory ShortcodeでPHPのコードを使わないで並べてくれます

[php 1=”[Category” number=”-1″ method=”full” order=”asc” id=”7″ orderby=”author” language=”}”]
[/php]

のようなコードをページに記入するとカテゴリーを並べてくれます
またこのシートコードはCategory Shortcodeをインストールするとダッシュボードのメニューに設定するためのユーティリティが表示されるようになります
しかし、このプラグインは表示方法がTAMのイメージに合いませんので以下のように改造しました

[php]
<!–?php
/*
Plugin Name: Category Shortcode
Plugin URI: http://creeksidesystems.com
Description: Plugin adds shortcode capability for adding posts by category to a page.
Version: 1.3
Author: Robert Drake
Author URI: http://creeksidesystems.com
*/

/*
Category Shortcode (WordPress Plugin)
Copyright (C) 2010 Robert Drake
Contact me at http://robertdrake.net or http://creeksidesystems.com or http://servusamanu.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 3 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, see <http://www.gnu.org/licenses/–>.
*/

//define plugin defaults
DEFINE(‘rd_method’, ‘full’);
DEFINE(‘rd_number_of_posts’, ‘1’);
DEFINE(‘rd_category_id’, ‘1’);
DEFINE(‘rd_orderby’, ‘post_date’);
DEFINE(‘rd_order’, ‘DESC’);

//add the shortcode category
add_shortcode("Category", "rdCatShortCode_handler");

//print all the final output to the screen
function rdCatShortCode_handler($incomingfrompost) {

$incomingfrompost=shortcode_atts(array(
‘method’ =&gt; rd_method,
‘number’ =&gt; rd_number_of_posts,
‘orderby’ =&gt; rd_orderby,
‘order’ =&gt; rd_order,
‘id’ =&gt; rd_category_id
), $incomingfrompost);

$rdcsch_output = rdrakeCategoryShortcode_function($incomingfrompost);
return $rdcsch_output ;
}

//calculate the final output
function rdrakeCategoryShortcode_function($incomingfromhandler) {

//setup the values as input from the shortcode
$rd_loop_method = wp_specialchars_decode($incomingfromhandler["method"]);
$rd_loop_postnum = wp_specialchars_decode($incomingfromhandler["number"]);
$rd_loop_orderby = wp_specialchars_decode($incomingfromhandler["orderby"]);
$rd_loop_order = wp_specialchars_decode($incomingfromhandler["order"]);
$rd_loop_catid = wp_specialchars_decode($incomingfromhandler["id"]);

//check the values for validity in the get_posts function
if ( strtolower($rd_loop_method) != ‘full’ &amp;&amp; strtolower($rd_loop_method) != ‘excerpt’ &amp;&amp; strtolower($rd_loop_method) != "title" ) {
$rd_loop_method = ‘full’;
}

if ( strtolower($rd_loop_order) != ‘asc’ &amp;&amp; strtolower($rd_loop_order) != ‘desc’ ) {
$rd_loop_order = ‘desc’;
}

if ( strtolower($rd_loop_orderby ) != ‘author’ &amp;&amp; strtolower($rd_loop_orderby ) != ‘date’ &amp;&amp; strtolower($rd_loop_orderby ) != ‘title’ &amp;&amp; strtolower($rd_loop_orderby ) != ‘modified’ &amp;&amp; strtolower($rd_loop_orderby ) != ‘parent’ &amp;&amp; strtolower($rd_loop_orderby ) != ‘id’ &amp;&amp; strtolower($rd_loop_orderby ) != ‘rand’ &amp;&amp; strtolower($rd_loop_orderby ) != ‘none’ &amp;&amp; strtolower($rd_loop_orderby ) != ‘comment_count’ ) {
$rd_loop_orderby = ‘date’;
}

global $post;

//grab the posts based on the criteria above
$rdcsc_posts = get_posts(‘numberposts=’.$rd_loop_postnum.’&amp;order=’.$rd_loop_order.’&amp;orderby=’.$rd_loop_orderby.’&amp;category=’.$rd_loop_catid);

$rdscf_output=”;

///// ——————————————————————————————-///
///// —————————— OUTPUT STYLING BELOW —————————————///
///// ——————————————————————————————-///

switch ($rd_loop_method) {
case ‘excerpt’:
foreach($rdcsc_posts as $post) :
setup_postdata($post);

$rdcsc_excerpt = get_the_excerpt();
/// strip tag filters added for 1.2 release
$rdcsc_excerpt = apply_filters( ‘the_content’, $rdcsc_excerpt );
$rdcsc_excerpt = str_replace( ‘]]&gt;’, ‘]]&gt;’, $rdcsc_excerpt );

$rdcsc_author = get_the_author();
$rdcsc_comments = get_comments();

// added in 1.3 release
$rdscf_output.=’
<div class="csc_post">
‘;

/// thumbnail added in 1.2 release
$rdscf_output.=’
<div class="csc_post_thumbnail">’ . get_the_post_thumbnail($rdcsc_posts-&gt;ID, ‘thumbnail’) . ‘</div>
‘;

$rdscf_output.=’
<div class="csc_post_title">’. the_date(”,”,”,FALSE).’ ‘;
$rdscf_output.='<a href="’ . get_permalink($rdcsc_posts -&gt;ID).’">’ . the_title("", "", false) .'</a>’.'</div>
‘;

$rdscf_output.=’
<div class="csc_post_excerpt">’ . $rdcsc_excerpt . ‘</div>
‘;
$rdscf_output.=’

‘;
$rdscf_output.='</div>
‘;
endforeach;
break;
case ‘title’:
foreach($rdcsc_posts as $post) :
setup_postdata($post);
$rdcsc_excerpt = get_the_excerpt();
$rdcsc_author = get_the_author();
$rdcsc_comments = get_comments();

// added in 1.3 release
$rdscf_output.=’
<div class="csc_post">
‘;

$rdscf_output.=’
<div class="csc_post_title">’. the_date(”,”,”,FALSE).’ ‘;
$rdscf_output.='<a href="’ . get_permalink($rdcsc_posts -&gt;ID).’">’ . the_title("", "", false) .'</a>’.'</div>
‘;
$rdscf_output.=’

‘;
$rdscf_output.='</div>
‘;
endforeach;
break;
case ‘full’:
foreach($rdcsc_posts as $post) :
setup_postdata($post);
$rdcsc_content = get_the_content();
/// strip tag filters added for 1.2 release
$rdcsc_content = apply_filters( ‘the_content’, $rdcsc_content );
$rdcsc_content = str_replace( ‘]]&gt;’, ‘]]&gt;’, $rdcsc_content );

$rdcsc_author = get_the_author();
$rdcsc_comments = get_comments();

// added in 1.3 release
$rdscf_output.=’
<div class="csc_post">
‘;

/// thumbnail added in 1.2 release

$rdscf_output.=’
<div class="csc_post_thumbnail">’ . get_the_post_thumbnail($rdcsc_posts-&gt;ID, ‘thumbnail’) . ‘</div>
‘;

$rdscf_output.=’
<div class="csc_post_title"><a href="’ . get_permalink($rdcsc_posts -&gt;ID).’">’ . the_title("", "", false) .'</a></div>
‘;
$rdscf_output.=’
<div class="csc_post_date">’ . the_date(”,”,”,FALSE) .'</div>
‘;
$rdscf_output.=’
<div class="csc_post_author">’ . $rdcsc_author . ‘</div>
‘;
foreach((get_the_category()) as $category) {
$rdscf_output.=’
<div class="csc_post_category">’ . $category-&gt;cat_name . ‘</div>
‘;
}
$rdscf_output.=’
<div class="csc_post_content">’ . $rdcsc_content . ‘</div>
‘;
$rdscf_output.=’

‘;
$rdscf_output.='</div>
‘;
endforeach;
break;
}

wp_reset_query();
$rdscf_output.=”;
return $rdscf_output;
}

//add Category Shortcode to the tools menu
add_action(‘admin_menu’, ‘rdcsc_plugin_menu’);

function rdcsc_plugin_menu() {

add_management_page(‘Category Shortcode’, ‘Category Shortcode’, ‘administrator’, ‘rdcsc’, ‘rdcsc_admin_print’);

$rdcsc_stylefile = WP_PLUGIN_URL . ‘/category-shortcode/style.css’;
wp_register_style(‘rdcsc_style’, $rdcsc_stylefile);
wp_enqueue_style( ‘rdcsc_style’);
}

?&gt;
<!–?php function rdcsc_admin_print() { ?–>

<script type="text/javascript"><!–mce:5–></script>
<div class="wrap">
<h2>Category Shortcode Generator</h2>
<form method="POST">
<div class="rdcsc_notes">Enter 0 to display the page default number of posts. Enter nothing to display the total number of matching posts.</div>
<div class="form-field">
<span class="label"><label for="rdcsc_number"><!–?php _e(‘Number of Posts (Optional)’) ?–></label></span>
<input class="numberofposts" style="width: 200px;" name="rdcsc_admin_number" type="text" /></div>
<div class="form-field">
<span class="label"><label for="rdcsc_order"><!–?php _e(‘Order’) ?–></label></span>
<select class="rdcsc_select" name="rdcsc_admin_order">
<option value="asc">Ascending</option>
<option value="desc">Descending</option>
</select></div>
<div class="form-field">
<span class="label"><label for="rdcsc_method"><!–?php _e(‘Display Method’) ?–></label></span>
<select class="rdcsc_select" name="rdcsc_admin_method">
<option value="full">Full Post</option>
<option value="excerpt">Excerpt</option>
<option value="title">Title</option>
</select></div>
<div class="form-field">
<span class="label"><label for="rdcsc_orderby"><!–?php _e(‘Order By’) ?–></label></span>
<select class="rdcsc_select" name="rdcsc_admin_orderby">
<option value="author">Author</option>
<option value="date">Date</option>
<option value="title">Title</option>
<option value="modified">Modified</option>
<option value="parent">Parent</option>
<option value="id">Id</option>
<option value="rand">Rand</option>
<option value="none">None</option>
<option value="comment_count">Comment Count</option>
</select></div>
<div class="form-field">
<span class="label"><label for="rdcsc_category"><!–?php _e(‘Category’) ?–></label></span>
<!–?php wp_dropdown_categories(array(‘hide_empty’ =–> 0, ‘name’ =&gt; ‘rdcsc_admin_category’, ‘orderby’ =&gt; ‘name’, ‘selected’ =&gt; $category-&gt;parent, ‘hierarchical’ =&gt; true)); ?&gt;</div>
<input class="calculate_button" onclick="calcShortcode(this.form)" name="button" type="button" value="Calculate Short Code" />
</form></div>
<!–?php } ?–>
[/php]

ブックマークする パーマリンク.

1件のコメント

  1. 「これ なんじゃろうかいの、文字化けしとるのかい?」と
    言いたくなるような・・・・
    あ~ぁ 見とうないのお 頭がパァになりそう
    ありゃ もうパァになってしもおた

    • 週末はWordPressの変更で久しぶりのプログラム漬け・・・もう頭が回らない
      すぐ忘れそうなのでとりあえず詳細をアップしています
      PHPのプログラムソースは読むのは何とか理解できるが、書くことは無理ですね

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です