Joomla Tipsมีเพื่อนหลายคนถามเข้ามาเรื่องการเขียน 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

0
Sweet spell
05 มกราคม, 2010
Votes: +0
comment
...
ขอบคุณมากครับ อยากใช้ Joomla! ทำเวบแต่ติดตรงที่ template นี่ล่ะ
จะรอติดตามตอนต่อไปครับ

0
Souknilundon from Laos
05 มกราคม, 2010
Votes: -1
comment
...
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

0
Souknilundon from Laos
05 มกราคม, 2010
Votes: +0
comment
...
my email อีเมลนี้จะถูกป้องกันจากสแปมบอท แต่คุณต้องเปิดการใช้งานจาวาสคริปก่อน

pencil
pencil
06 มกราคม, 2010
Votes: +0
comment
...
มาอธิบายไวๆนะครับ

NutsCrub
NutsCrub
06 มกราคม, 2010
Votes: -1
comment
...
โค๊ดแยกมาแบบนี้ยังพออ่านออก คงจะงงตอนรวมนี่แหละครับผมว่านะ

##รอเหมือนกันนะครับผม##

silent
silent
06 มกราคม, 2010
Votes: +0
comment
...
ขอบคุณคับ..
ผมแนะนำให้เพื่อนลองโหลด Firebug เป็น Add-On ของ บราวเซอร์ Firefox มาแล้วลองใช้ดู แก้ได้เหมือนกัน ครับ >

khanomm
khanomm
09 มกราคม, 2010
Votes: +0
comment
...
รอเหมือนกัน *-*

0
NatZ
11 มกราคม, 2010
Votes: +0
comment
...
รอด้วยคน
เรื่องการสร้าง template บน CMS
ผมว่ามีประโยชน์มากครับ เพราะ CMS ส่วนใหญ่ระบบหลังบ้านจะดีมากๆอยู่แล้ว
ติดที่ตรงหน้าตาที่เราจะทำให้แตกต่างกับคนอื่นๆยาก เพราะเราแก้มันไม่เป็น
แล้วถึงไปซื้อ template มาบางทีก็ไม่โดนใจ

0
จูมลาหัดขับ
16 มกราคม, 2010
Votes: +0
comment
...
รอเหมือนกันครับ

ozinepank
kulachat
26 มกราคม, 2010
Votes: +0
comment
...
สวัสดีครับท่านสมาชิกทุกคน..ผมไม่ได้จบด้านนี้เลยครับ
แต่..ดันอยากทำเว็บ..โชคดีที่เจอ เว็บดีๆแบบนี้มาแชร์กันครับ
--**มือใหม่ Joomla ครับ..สามารถแชว์อีกทาง Twitter.com /ozinepank ครับ
ขอบคุณพี่ๆ Admin ด้วยครับ

ozinepank
kulachat
26 มกราคม, 2010
Votes: +0
comment
...
ถ้าเราจะรู้ละเอียดของ Code แต่ละตัวควรดูที่เว็บไหนหรือหนังสือไหนที่ดีๆบ้างครับ??

Slotpro
Slotpro
26 มกราคม, 2010
Votes: -1
comment
...
@kulachat เอาละเอียดก็ที่ doc.joomla.org

sathaporn
sathaporn
26 มกราคม, 2010
Votes: +0
comment
...
เวปนี้แนะนำดีมากครับ
ผมเด็กใหม่ครับกำลังศึกษาและลองตัวนี้เป็นตัวแรก
ช่วยแนะนำเยอะๆเลยน่ะครับ
ขอบคุนล่วงหน้า

ozinepank
ozinepank
27 มกราคม, 2010
Votes: +0
comment
...
+---ขอบคุณคุณ Slotpro มากน่ะครับ กำลังเพี่งเรี่ม joomla! ต้องให้เวลากับมันอีกเยอะครับ..
ผมยังต้องอยู่กับเว็บนี้อีกหลายปีครับ..(Admin เห็นแล้วใจชื้นเลยน่ะเนี้ย..ฮ่า ฮ่า)

kknd2006
kknd2006
01 กุมภาพันธ์, 2010
Votes: +0
comment

weerachat
weerachat
05 กุมภาพันธ์, 2010
Votes: +0
comment
...
ติดตามด้วยคน

Servicecolour
Servicecolour
20 กุมภาพันธ์, 2010
Votes: +0
comment
...
เพิ่งเริ่มค่ะ อ่านๆแล้วลองมั่วๆ เพราะไม่เป็นมาก่อนเลยยยย

ศิริรัตน์    ถมยา
ศิริรัตน์ ถมยา
22 กุมภาพันธ์, 2010
Votes: +0
comment
...
จะรอนะค่ะ

Write comment
smaller | bigger

security image
Write the displayed characters


busy