ยินดีต้อนรับคุณ, บุคคลทั่วไป กรุณา เข้าสู่ระบบ หรือ ลงทะเบียน

เข้าสู่ระบบด้วยชื่อผู้ใช้ รหัสผ่าน และระยะเวลาในเซสชั่น

ThaiSEOBoard.comพัฒนาเว็บไซต์CMS & Free Scriptโม component category ของ Joomla 1.5.23
หน้า: [1]   ลงล่าง
พิมพ์
ผู้เขียน หัวข้อ: โม component category ของ Joomla 1.5.23  (อ่าน 646 ครั้ง)
0 สมาชิก และ 1 บุคคลทั่วไป กำลังดูหัวข้อนี้
SpiderManKing
คนรักเสียว
*

พลังน้ำใจ: 24
ออฟไลน์ ออฟไลน์

กระทู้: 102



ดูรายละเอียด
« เมื่อ: 12 สิงหาคม 2011, 02:08:47 »

สมมุติว่ามี section อยู่ 3 section ชื่อ section1,section2,section3
แล้วแต่ละ section มี category อยู่ section ละ 10 category รวมเป็นทั้งสินเป็น 30 category คิดดูว่าจะใช้ แล้วสร้างนานขนาดใหน
ผมเลย มี idea สร้าง Quick Create Category ขึ้นมา

ก่อนอื่น เิปิดไฟล์ administrator\components\com_categories\admin.categories.php ขึ้นมาด้วย editor ที่มีการแสดงหมายเลขบรรทัด เช่น text   หรือ edit plus

แล้วแทก code เหล่านี้ลงไปที่บรรทัด 113

โค๊ด:
//------------------------------------------Add quickCreate------------------------------------------------------------
function quickCreate(){
global $mainframe;

$categories=JRequest::getVar('categories');


if (!$categories) {
            $error='กรุณาป้อนชื่อ Category';

        }
if(JRequest::getVar('section')=="com_content"){
if(JRequest::getCmd('sectionid_m')=="-1"){
$error="กรุณาเลือก Section ";
}
$section="com_content";
}else{
$section=JRequest::getVar('section');
}

        if (preg_match('/^,/', $categories)) {
            $error='ห้ามมีเครื่องหมาย , นำหน้า';

        }


if($error){
JRequest::setVar('categories',$categories);
JRequest::setVar('sectionid_m',$sectionid_m);
$mainframe->redirect('index.php?option=com_categories&section='.$section.'&showQuick=block',$error, 'notice');
return false;
}
        if (strpos($categories, ',')) {
            $categories = explode(',', $categories);
        } else {
            $categories = (Array) $categories;
        }

$insertValue = array();
$access= JRequest::getVar('access');
$published_m= JRequest::getVar('published_m');
$sectionid_m= JRequest::getCmd('sectionid_m');

        foreach ($categories as $value) {
            if ($value && $value != ',') {
               $insertValue[] = '('.sprintf("'%s','%s','%s','%d','%d','%s'", $value, $value,$value,$published_m,$access,$sectionid_m) .')';
            }
        }
$query='INSERT INTO #__categories(title,alias,description,published,access,section)';
$query.=' VALUES '.implode(',',$insertValue);

$db = JFactory::getDbo();
$db->setQuery($query);

try {
            if (!$db->query()) {
                throw new Exception($db->getErrorMsg());
            }
        } catch (Exception $e) {
            $error=$e->getMessage();
        }

if($error){
$mainframe->redirect('index.php?option=com_categories&section='.$section.'&showQuick=block',$error, 'notice');
}else{
JRequest::setVar('categories','');
JRequest::setVar('access','');
JRequest::setVar('published_m','1');
if(JRequest::getVar('section')=="com_content"){
JRequest::setVar('sectionid_m','-1');
}

$message='บันทึกข้อมูลเรียบร้อยแล้ว '. count($insertValue).' รายการ';
$mainframe->redirect('index.php?option=com_categories&section='.$section.'&showQuick=block',$message);
}

}

//------------------------------------------End quickCreate------------------------------------------------------------

แล้วทำการบันทึก

ต่อมาเปิดไฟล์  administrator\components\com_categories\admin.categories.html.php
ทำการแทก code ข้างล่าง ที่บรรทัด 224

โค๊ด:
<?php //--------------------------------------------------Add---------------------------------------------------------?>
<style type="text/css">


#quick_create div label:first-child{
margin-top:5px;
margin-bottom:10px;
float:left;
width:100px;;
}

#quick_create div label *,#quick_create div label{
margin-top:5px;
margin-bottom:10px;
float:left;
}

#quick_create div div{
clear:left
}

#quick_create legend a:first-child{
margin-right:40px;
}
#quick_create a{
cursor: pointer;
text-decoration:none;
}



</style>

<div id="quick_create">
<form id="form_quick" name="quickBatch" action="index.php?option=com_categories&amp;section=<?php echo $section?>" method="post" >
<fieldset>

<legend>
<a onclick="return switchDisplayQuickForm();">Quick Create Category</a>

</legend>
<div id="quick_content">
<div>
<?php if(JRequest::getVar(&#39;section&#39;)=="com_content"):?>
<label>Select Section </label><?php echo JHTML::_(&#39;list.section&#39;,  &#39;sectionid_m&#39;,$lists[&#39;sectionid_m&#39;]); ?>
<?php else:?>
<label>Select Section </label>
<input   type="text" name="sectionid_m" size="30" readonly value="<?php echo JRequest::getVar(&#39;section&#39;)?>"/>

<?php endif;?>
</div>
<div>
<label><?php echo JText::_( &#39;Published&#39; ); ?></label>
<?php echo $lists[&#39;published_m&#39;]; ?>

</div>
<div>
<label><?php echo JText::_( &#39;Access&#39; ); ?></label>
<?php echo $lists[&#39;access&#39;]; ?>

</div>
<div>
<label><span class="editlinktip hasTip" title="Category::ป้อนชื่อ Category ที่ต้องการสร้างโดยแต่ละตัวมีเครื่องหมาย , คั่น">Category</span></label>
<input id="categories" type="text" name="categories" size="90" value="<?php echo $lists[&#39;categories&#39;];?>"/>
<button type="submit" style="margin:5px 3px;">Create</button>
<button type="button" style="margin-top:5px" onclick="$('categories').value=''; $('categories').focus();">Reset</button>
</div>
</div>
</fieldset>
<input type="hidden"  name="task" value="quick_create" />
<input type="hidden" name="showQuick" id="showQuick"  />
</form>
<script type="text/javascript">
$('quick_content').style.display="<?php echo JRequest::getVar(&#39;showQuick&#39;,&#39;none&#39;); ?>";
if($('quick_content').style.display=="none"){
$('close_quick').style.display='none';
}
function switchDisplayQuickForm(){
var display;
display=$('quick_content').style.display;
if(display=='' || display=='block'){
display="none";
$('showQuick').value='none';

}else{
display='block';
$('showQuick').value='block';
}

$('quick_content').style.display=display;
if(display=='block'){
$('categories').focus();
}
return false;
}
</script>

</div>

<?php //--------------------------------------------------End Add---------------------------------------------------------?>

แล้วทำการบันทึก

จากนั้นให้ไปที่ Content -> Category Manager

จะมีคำว่า Quick Create Category ดังรูป
ibcbet

จากนั้นกดคลิกที่ Quick Create Category จะแสดง
ibcbet

สมมุติว่ามีการสร้าง section1 แล้ว ให้ทำการสร้าง category ใหม่ให้ section1 ดังรูป
ibcbet

กด Create จะมี Category ใหม่ใน section1 ดังรูป
ibcbet


จากนั้นไปที่ Components -> Contatcs -> Categories สร้าง Categories ใหม่ ดังนี้
ibcbet


กด Create จะมี Category ใหม่ ดังรูป

ibcbet



ไม่เฉพาะกับ Contacs เท่านั้นที่ใช้ Quick Create Category ได้   News fees กับ Web links ก็สามารถใช้ได้ ลองทดลองใช้ดู

ถ้ามี bug ตรงใหนก็บอกมาด้วยละกัน ลืมบอกไปแต่ละ Category ที่สร้างให้คั่นด้วยเครื่องหมาย ,





« แก้ไขครั้งสุดท้าย: 12 สิงหาคม 2011, 02:30:03 โดย SpiderManKing » บันทึกการเข้า
Hirsizlar
ก๊วนเสียว
*

พลังน้ำใจ: 8
ออฟไลน์ ออฟไลน์

กระทู้: 224



ดูรายละเอียด
« ตอบ #1 เมื่อ: 12 สิงหาคม 2011, 02:26:04 »

ยังใช้งานไม่เป็นแต่เก็บไปก่อน อิอิ  Embarrassed
บันทึกการเข้า

...เรื่องผมไว้ใจหวี เพราะเป็นคน ดีไม่ห่างเหิน...
SpiderManKing
คนรักเสียว
*

พลังน้ำใจ: 24
ออฟไลน์ ออฟไลน์

กระทู้: 102



ดูรายละเอียด
« ตอบ #2 เมื่อ: 12 สิงหาคม 2011, 12:36:43 »

เคยเพิ่ม Category สูงสุดแค่หลัก 10 ในแต่ละครั้ง ไม่รู้ว่าถ้าเพิ่มทีละเป็นพัน Category จะเป็นอะไรหรือปล่าว แต่คงไม่มีใครเขียนเพิ่มเป็น พัน Category ใน Section เดียวหลอก

ผมทดลองแต่ละครั้งก็ทำงานได้ดี แต่ไม่รู้ว่ามันจะมี bug ซ่อนอยู่หรือปล่าวอยากให้ช่วยรายงานผลด้วยครับ
« แก้ไขครั้งสุดท้าย: 12 สิงหาคม 2011, 12:42:44 โดย SpiderManKing » บันทึกการเข้า
หน้า: [1]   ขึ้นบน
พิมพ์