Вывод тегов для отдельной страницы — различия между версиями
Материал из Umicms
Gordeev (обсуждение | вклад) (Новая страница: «Ниже приведен сам скрипт который мы вставляем в classes/modules/custom.php <pre> public function tags_out($id=NULL) { …») |
Gordeev (обсуждение | вклад) |
||
| Строка 1: | Строка 1: | ||
Ниже приведен сам скрипт который мы вставляем в classes/modules/custom.php | Ниже приведен сам скрипт который мы вставляем в classes/modules/custom.php | ||
<pre> | <pre> | ||
| − | public function tags_out($id=NULL) { | + | public function tags_out($id=NULL,$template= |
| + | NULL) { | ||
if(!$id) return; | if(!$id) return; | ||
| − | + | $hierarchy = umiHierarchy::getInstance(); | |
| − | + | $element = $hierarchy->getElement($id); | |
| − | + | if(!$element) return; | |
| − | + | if(!$template) $template="tags"; | |
| − | + | list($tpl_tags, $tpl_tag, $tpl_tag_sep, $tpl_tags_empty) = def_module::loadTemplates("tpls/content/".$template.".tpl","cloud_tags","cloud_tag","cloud_tagseparator","cloud_tags_empty"); | |
| − | + | $mas=array(); | |
| − | + | $resou=''; | |
| + | $s_prefix='Account'; | ||
| + | $mas=$element->getValue("tags"); | ||
| + | $sz=sizeof($mas); | ||
| + | if($sz>0){ | ||
| + | $arrTagsTplteds = array(); | ||
for($i=0;$i<$sz;$i++){ | for($i=0;$i<$sz;$i++){ | ||
| − | $ | + | $params = array( |
| − | + | 'tag'=>$mas[$i], | |
| − | + | 'tag_urlencoded'=>rawurlencode($mas[$i]), | |
| + | 'attribute:weight' => '', | ||
| + | 'attribute:font' => '', | ||
| + | 'attribute:context' => $s_prefix | ||
| + | ); | ||
| + | $arrTagsTplteds[] = def_module::parseTemplate($tpl_tag, $params); | ||
} | } | ||
| − | + | if (isset($arrTagsTplteds[0]) && is_array($arrTagsTplteds[0])) { // udata | |
| − | if($ | + | $arrForTags = array('subnodes:items'=>$arrTagsTplteds); |
| − | + | } else { | |
| − | return $ | + | $arrForTags = array('items'=>implode($tpl_tag_sep, $arrTagsTplteds)); |
| − | + | } | |
| + | $arrForTags['attribute:summ_weight'] = ''; | ||
| + | $arrForTags['attribute:context'] = $s_prefix; | ||
| + | return def_module::parseTemplate($tpl_tags, $arrForTags); | ||
| + | }else { | ||
| + | $arrForTags = array(); | ||
| + | return def_module::parseTemplate($tpl_tags_empty, $arrForTags); | ||
| + | } | ||
| + | } | ||
</pre> | </pre> | ||
А затем в нужном на месте выводим теги вставляя в шаблон %custom tags_out(%id%)%. | А затем в нужном на месте выводим теги вставляя в шаблон %custom tags_out(%id%)%. | ||
Следует также помнить, что у вас должны быть шаблон для макроса %content pagesByAccountTags()%, так как именно через него ссылка открывает вам список страниц, содержащих такой тег. | Следует также помнить, что у вас должны быть шаблон для макроса %content pagesByAccountTags()%, так как именно через него ссылка открывает вам список страниц, содержащих такой тег. | ||
В случае если вы используете tpl шаблонизатор, то это файл tpls/content/tags.tpl | В случае если вы используете tpl шаблонизатор, то это файл tpls/content/tags.tpl | ||
Версия 07:34, 4 апреля 2011
Ниже приведен сам скрипт который мы вставляем в classes/modules/custom.php
public function tags_out($id=NULL,$template=
NULL) {
if(!$id) return;
$hierarchy = umiHierarchy::getInstance();
$element = $hierarchy->getElement($id);
if(!$element) return;
if(!$template) $template="tags";
list($tpl_tags, $tpl_tag, $tpl_tag_sep, $tpl_tags_empty) = def_module::loadTemplates("tpls/content/".$template.".tpl","cloud_tags","cloud_tag","cloud_tagseparator","cloud_tags_empty");
$mas=array();
$resou='';
$s_prefix='Account';
$mas=$element->getValue("tags");
$sz=sizeof($mas);
if($sz>0){
$arrTagsTplteds = array();
for($i=0;$i<$sz;$i++){
$params = array(
'tag'=>$mas[$i],
'tag_urlencoded'=>rawurlencode($mas[$i]),
'attribute:weight' => '',
'attribute:font' => '',
'attribute:context' => $s_prefix
);
$arrTagsTplteds[] = def_module::parseTemplate($tpl_tag, $params);
}
if (isset($arrTagsTplteds[0]) && is_array($arrTagsTplteds[0])) { // udata
$arrForTags = array('subnodes:items'=>$arrTagsTplteds);
} else {
$arrForTags = array('items'=>implode($tpl_tag_sep, $arrTagsTplteds));
}
$arrForTags['attribute:summ_weight'] = '';
$arrForTags['attribute:context'] = $s_prefix;
return def_module::parseTemplate($tpl_tags, $arrForTags);
}else {
$arrForTags = array();
return def_module::parseTemplate($tpl_tags_empty, $arrForTags);
}
}
А затем в нужном на месте выводим теги вставляя в шаблон %custom tags_out(%id%)%. Следует также помнить, что у вас должны быть шаблон для макроса %content pagesByAccountTags()%, так как именно через него ссылка открывает вам список страниц, содержащих такой тег. В случае если вы используете tpl шаблонизатор, то это файл tpls/content/tags.tpl