Joomlaのテンプレート作成用のシンプルな土台 その2
Joomlaのテンプレート作成用のシンプルな土台の続きで、index.phpの中身。
実際に表示されるテンプレートは、これ1枚で済みます。
<?php defined( '_JEXEC' ) or die( 'Restricted access' );?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xml:lang="<?php echo $this->language; ?>" lang="<?php echo $this->language; ?>" >
<head>
<jdoc:include type="head" />
<link rel="stylesheet" href="<?php echo $this->baseurl ?>/templates/system/css/system.css" type="text/css" />
<link rel="stylesheet" href="<?php echo $this->baseurl ?>/templates/system/css/general.css" type="text/css" />
<link rel="stylesheet" href="<?php echo $this->baseurl ?>/templates/<?php echo $this->template?>/css/template.css" type="text/css" />
</head>
<body>
<div id="wrap">
<div id="header"> <!-- ヘッダーー -->
<h1><a href="./"<?php echo $mainframe->getCfg('sitename');?></a></h1>
<jdoc:include type="modules" name="top" style="xhtml" />
</div>
<?php if( $this->countModules('left') ) : ?> <!-- 左サイドバー -->
<div id="sidebar-left">
<jdoc:include type="modules" name="left" style="xhtml" />
</div>
<?php endif; ?>
<div id="content" > <!-- パン屑リストとコンテンツ領域 -->
<jdoc:include type="module" name="breadcrumbs" />
<jdoc:include type="component" style="none" />
</div>
<?php if( $this->countModules('right') ) : ?> <!-- 右サイドバー -->
<div id="sidebar-right">
<jdoc:include type="modules" name="right" style="xhtml" />
</div>
<?php endif; ?>
<?php if( $this->countModules('footer') ) : ?> <!-- フッター -->
<div id="footer">
<jdoc:include type="modules" name="footer" style="xhtml" />
</div>
<?php endif; ?>
</div> <!-- end of wrap-->
</body>
</html>
1行目の<?php defined( ‘_JEXEC’ ) or die( ‘Restricted access’ );?>は、PHPファイルの中身を直接表示しないためのお約束。その後に続くのは、xml宣言と言語の設定。言語については、Joomlaの設定を読み込んで表示する。日本語のサイトなら、utf-8が入るはずです。
<head>タグの中は、<jdoc:include type=”head” />で、Joomlaが必要なタグを生成してくれる。これに続くのは、cssファイル(スタイルシート)の読み込み。テンプレート独自のJavaScriptを読み込ませる時もここに書いておきます。
<body>タグの中は、htmlのコメントを入れている通りのポジションの読み込み。ほとんどが1行だけの読み込みで済みます。左サイドバー、右サイドバー、フッターの部分には、PHPのif文がついていて、表示する項目があれば、jdoc:includeが実行されます。項目が無ければ、htmlには表示されないので、2カラム構成にできるわけです。