Хорошо, я заработал так, как хотел.
Я хотел заменить вступление/полный текст дополнительным полем, которое я назвал «Accroche». Это дополнительное поле имеет идентификатор 132 (полезно знать идентификатор, который будет использоваться в коде ниже).
Мы будем редактировать 2 файла:
/modules/mod_bt_contentslider/classes/content.php и /modules/mod_bt_contentslider/classes/k2.php
Первое, что нужно сделать, это получить информацию о дополнительных полях из базы данных:
в /modules/mod_bt_contentslider/classes/content.php (около строки 77) я добавил [b]a.extra_fields,[/b] следующим образом
$model->setState('list.select', 'a.urls, a.images, a.fulltext, a.id, a.title, a.alias, a.introtext, a.extra_fields, a.state, a.catid, a.created, a.created_by, a.created_by_alias,' . ' a.modified, a.modified_by,a.publish_up, a.publish_down, a.attribs, a.metadata, a.metakey, a.metadesc, a.access,' . ' a.hits, a.featured,' . ' LENGTH(a.fulltext) AS readmore');
Сохранить файл и закрыть
Теперь давайте перейдем к /modules/mod_bt_contentslider/classes/k2.php (около строки 234),
Замените этот исходный код
// cut introtext
if ($limitDescriptionBy == 'word') {
$item->description = self::substrword($item->introtext, $maxDesciption, $replacer, $isStrips, $stringtags);
$item->description = self::substring($item->introtext, $maxDesciption, $replacer, $isStrips, $stringtags);
}
$item->categoryLink = urldecode(JRoute::_(K2HelperRoute::getCategoryRoute($item->catid . ':' . urlencode($item->categoryalias))));
// get author name & link
С этим кодом, который я прокомментировал, чтобы сделать вещи понятными для таких нубов, как я;)
// REPLACE intro/full text With extra-field info
$extras = json_decode($item->extra_fields); // JSON Array we'll call extras (note final 's' : not to confuse with below variable)
foreach ($extras as $key=>$extraField): //Get values from array
if($extraField->value != ''): //If not empty
if($extraField->id == '132'): // This is ID value for extrafield I want to show --- Search your K2 extrafield's id in Joomla backoffice ->K2 ->extrafields ---
if($extraField->value != ''): // If there's content in the extrafield of that ID
$extra = $extraField->value; //Give $extra that value so we can hand it down below
endif;
endif;
endif;
endforeach;
// cut introtext
if ($limitDescriptionBy == 'word') {
// $item->description = self::substrword($item->introtext, $maxDesciption, $replacer, $isStrips, $stringtags);
$item->description = self::substrword($extra, $maxDesciption, $replacer, $isStrips, $stringtags);
} else {
// $item->description = self::substring($item->introtext, $maxDesciption, $replacer, $isStrips, $stringtags);
$item->description = self::substring($extra, $maxDesciption, $replacer, $isStrips, $stringtags) ;
}
$item->categoryLink = urldecode(JRoute::_(K2HelperRoute::getCategoryRoute($item->catid . ':' . urlencode($item->categoryalias))));
// get author name & link
Как видите, я закомментировал вводные тексты, так как они мне не нужны. Вы можете изменить это, если вам нужны как вступительный текст, так и дополнительное поле.
Я бы никогда не понял этого без подсказки JSON, приведенной выше. Спасибо всем :)
Надеюсь это поможет.
Ваше здоровье !
person
Enzo24
schedule
19.02.2014