มีเพื่อนหลายคนถามเข้ามาเรื่องการเขียน Joomla Template นะครับ วันนี้ผมเลยขอแนะนำโค๊ดพื้นฐานที่จำเป็นสำหรับการเขียนมาฝากครับซึ่งจะสามารถช่วยได้มากเลยเวลาเขียน Template เราไปดูกันเลยครับว่าโค๊ดต่างๆนั้นมีอะไรกันมั่ง
Detecting Logged In State
<?php $userattr = JFactory::getUser(); $thisuser = $userattr ->get('guest'); if($thisuser == 0) { ?> // is this a guest user? //yes. do guest user stuff <?php } else { ?> //no. do logged-in user stuff <?php } ?>
Load component / Error
<?php if ($this->getBuffer('message')) : ?>
<div class="error">
<h2> Message </h2>
<jdoc:include type="message" />
</div>
<?php endif; ?>
<jdoc:include type="component" />
Load One module Position
<?php if ($this->countModules('user1')) : ?>
<div id="user1">
<jdoc:include type="modules" name="user1" style="xhtml" />
</div>
<?php endif; ?>
Load Four Module Positions
<?php if ($this->countModules('user1 or user2 or user3 or user4')) : ?>
<div id="userModules">
<?php if ($this->countModules('user1')) : ?>
<div id="user1">
<jdoc:include type="modules" name="user1" style="xhtml" />
</div><!-- end user1 -->
<?php endif; ?>
<?php if ($this->countModules('user2')) : ?>
<div id="user2">
<jdoc:include type="modules" name="user2" style="xhtml" />
</div><!-- end user2 -->
<?php endif; ?>
<?php if ($this->countModules('user3')) : ?>
<div id="user3">
<jdoc:include type="modules" name="user3" style="xhtml" />
</div><!-- end user4 -->
<?php endif; ?>
<?php if ($this->countModules('user4')) : ?>
<div id="user4">
<jdoc:include type="modules" name="user4" style="xhtml" />
</div><!-- end user5 -->
<?php endif; ?>
</div>
<?php endif; ?>
3-Column Class Conditionals
//Put in Head section
<?php
if($this->countModules('left and right') == 0) $contentwidth = "full";
if($this->countModules('left or right') == 1) $contentwidth = "single";
if($this->countModules('left and right') == 1) $contentwidth = "both";
?>
//Then put in Body
<div id="middleCol" class="<?php echo $contentwidth ?>">
//Then put in CSS
#middleCol.full {width: 100%;}
#middleCol.both {float: left; width: 50%;}
#middleCol.single {float: left; width: 75%;}
Blank Index.html
<html><body bgcolor="#FFFFFF"></body></html>
No Direct Access
// no direct access
defined('_JEXEC') or die('Restricted access');
Basic HEAD Tag
<?php echo '<?xml version="1.0" encoding="utf-8"?' .'>'; ?>
<!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; ?>" dir="<?php echo $this->direction; ?>" >
<head>
<jdoc:include type="head" />
<?php JHTML::_('behavior.mootools'); ?>
<link rel="shortcut icon" href="<?php echo $this->baseurl ?>/templates/<?php echo $this->template ?>/favicon.ico" type="image/x-icon" />
<link href="<?php echo $this->baseurl ?>/templates/<?php echo $this->template ?>/css/template.css" rel="stylesheet" type="text/css" media="screen" />
<script src="<?php echo $this->baseurl ?>/templates/<?php echo $this->template ?>/js/template.js" type="text/javascript">
<!--[if lte IE 6]>
<link rel="stylesheet" type="text/css" href="<?php echo $this->baseurl ?>/templates/<?php echo $this->template ?>/css/ie6.css" media="screen, projection" />
<![endif]-->
<!--[if IE 7]>
<link rel="stylesheet" type="text/css" href="<?php echo $this->baseurl ?>/templates/<?php echo $this->template ?>/css/ie7.css" media="screen, projection" />
<![endif]-->
</head>
Breadcrumbs Module
<div id="breadcrumbs"> <jdoc:include type="modules" name="breadcrumb" style="raw" /> </div>
สำหรับเพื่อนๆที่ยังไม่เข้าใจโค๊ดนั้นในตอนหน้าผมจะมาอธิบายอย่างละเอียดแล้วกันนะครับ
Related Articles
Check out some more great tutorials and articles that you might like
05 มกราคม, 2010
Votes: -1
|
... Hi Joomla Developer I am a Lao people who want to develop website but i don't know anything about how to use joomla but once I used to design website in html by dreamweaver so any suggestion on basic knowledge about CMS. If the suggestion in Thai language will be good. Hope you guy can help me thanks cheers Tai |
05 มกราคม, 2010
Votes: +0
|
... my email อีเมลนี้จะถูกป้องกันจากสแปมบอท แต่คุณต้องเปิดการใช้งานจาวาสคริปก่อน |
|
... ขอบคุณคับ.. ผมแนะนำให้เพื่อนลองโหลด Firebug เป็น Add-On ของ บราวเซอร์ Firefox มาแล้วลองใช้ดู แก้ได้เหมือนกัน ครับ > |
|
... รอด้วยคน เรื่องการสร้าง template บน CMS ผมว่ามีประโยชน์มากครับ เพราะ CMS ส่วนใหญ่ระบบหลังบ้านจะดีมากๆอยู่แล้ว ติดที่ตรงหน้าตาที่เราจะทำให้แตกต่างกับคนอื่นๆยาก เพราะเราแก้มันไม่เป็น แล้วถึงไปซื้อ template มาบางทีก็ไม่โดนใจ |
|
... สวัสดีครับท่านสมาชิกทุกคน..ผมไม่ได้จบด้านนี้เลยครับ แต่..ดันอยากทำเว็บ..โชคดีที่เจอ เว็บดีๆแบบนี้มาแชร์กันครับ --**มือใหม่ Joomla ครับ..สามารถแชว์อีกทาง Twitter.com /ozinepank ครับ ขอบคุณพี่ๆ Admin ด้วยครับ |
|
... เวปนี้แนะนำดีมากครับ ผมเด็กใหม่ครับกำลังศึกษาและลองตัวนี้เป็นตัวแรก ช่วยแนะนำเยอะๆเลยน่ะครับ ขอบคุนล่วงหน้า |
|
... +---ขอบคุณคุณ Slotpro มากน่ะครับ กำลังเพี่งเรี่ม joomla! ต้องให้เวลากับมันอีกเยอะครับ.. ผมยังต้องอยู่กับเว็บนี้อีกหลายปีครับ..(Admin เห็นแล้วใจชื้นเลยน่ะเนี้ย..ฮ่า ฮ่า) |
Write comment
