0 Пользователей и 1 Гость просматривают эту тему.
  • 11 Ответов
  • 911 Просмотров
*

R31rus

  • Давно я тут
  • 632
  • 4 / 0
Сам модуль такой-же как и mod_latest_news. Пробовал ничего не помогает.....
Код
<?php

defined('_JEXEC') or die;
?>
<?php if (!empty($list)) :?>
<ul class="jcomments-most-commented<?php echo $params->get('moduleclass_sfx'); ?>">
<?php foreach ($list as $item) : ?>
<li>
<a href="<?php echo $item->link; ?>#comments">
<?php if ($params->get('showCommentsCount')) :?>
<?php echo $item->title; ?>&nbsp;(+<?php echo $item->commentsCount; ?>)
<?php else : ?>
<?php echo $item->title; ?>
<?php endif; ?>
</a>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
*

sivers

  • Живу я здесь
  • 2450
  • 333 / 0
Сделать
Код
<pre><?php print_r($list[0]); ?></pre>
Это можно перед <ul>.
Посмотреть что там есть в этом объекте, найти в каком свойстве путь к картинке и построить <img>.
На связи в telegram @sivers
sivers @ inbox . ru
https://sivers.su/
*

R31rus

  • Давно я тут
  • 632
  • 4 / 0
<pre><?php print_r($list[0]); ?></pre>

Код
stdClass Object
(
    [id] => 1
    [title] => Тест Материал
    [link] => /test-menu-item/2-test-mat
    [commentsCount] => 2
    [commentdate] => 2020-08-04 13:18:29
)

Нет img(
*

sivers

  • Живу я здесь
  • 2450
  • 333 / 0
Нет img(
Тогда смотреть внимательно код модуля mod_latest_news. Цель - найти запрос, который вытаскивает новости из БД и посмотреть - есть ли там какое-то условие для включения изображения в результаты запроса. Если такое есть, то, возможно, в настройках модуля можно включить что-то. Если такого нет, то создать копию модуля и подправить запрос, чтоб вытаскивал изображения. Модуль нестандартный (у меня вот его нет), поэтому ничего конкретней не скажу.
На связи в telegram @sivers
sivers @ inbox . ru
https://sivers.su/
*

R31rus

  • Давно я тут
  • 632
  • 4 / 0
Все так и делал. Получилось. Половину helper(а) скопировал из latest_news оттуда сюда. Единственное данный модуль выводит материалы с наибольшим количеством комментариев, это уже ломается.... в общем ерунда, нехватает знаний... Одно вроде сделаешь другое ломается
« Последнее редактирование: 06.08.2020, 16:25:24 от R31rus »
*

sivers

  • Живу я здесь
  • 2450
  • 333 / 0
Все так и делал. Получилось. Половину helper(а) скопировал из latest_news оттуда сюда. Единственное данный модуль выводит материалы с наибольшим количеством комментариев, это уже ломается.... в общем ерунда, нехватает знаний... Одно вроде сделаешь другое ломается
Покажите какой был запрос и какой теперь
На связи в telegram @sivers
sivers @ inbox . ru
https://sivers.su/
*

R31rus

  • Давно я тут
  • 632
  • 4 / 0
Покажите какой был запрос и какой теперь


Стандартный Helper most_commented:
Код
<?php
// no direct access
defined('_JEXEC') or die;

class modJCommentsMostCommentedHelper
{
static function getList( &$params )
{
$db = JFactory::getDBO();
$user = JFactory::getUser();

$source = $params->get('source', 'com_content');
if (!is_array($source)) {
$source = explode(',', $source);
}

$date = JFactory::getDate();

if (version_compare(JVERSION,'1.6.0','ge')) {
$now = $date->toSQL();
$access = array_unique(JAccess::getAuthorisedViewLevels($user->get('id')));
$access[] = 0; // for backward compability
} else {
$now = $date->toMySQL();
$access = $user->get('aid', 0);
}

$where = array();

$interval = $params->get('interval', '');
if (!empty($interval)) {

$timestamp = $date->toUnix();

switch($interval) {
case '1-day':
$timestamp = strtotime('-1 day', $timestamp);
break;

case '1-week':
$timestamp = strtotime('-1 week', $timestamp);
break;

case '2-week':
$timestamp = strtotime('-2 week', $timestamp);
break;

case '1-month':
$timestamp = strtotime('-1 month', $timestamp);
break;

case '3-month':
$timestamp = strtotime('-3 month', $timestamp);
break;

case '6-month':
$timestamp = strtotime('-6 month', $timestamp);
break;

case '1-year':
$timestamp = strtotime('-1 year', $timestamp);
break;
default:
$timestamp = NULL;
break;
}

if ($timestamp !== NULL) {
$dateFrom = JFactory::getDate($timestamp);
$dateTo = $date;

if (version_compare(JVERSION,'1.6.0','ge')) {
$where[] = 'c.date BETWEEN ' . $db->Quote($dateFrom->toSQL()). ' AND ' . $db->Quote($dateTo->toSQL());
} else {
$where[] = 'c.date BETWEEN ' . $db->Quote($dateFrom->toMySQL()). ' AND ' . $db->Quote($dateTo->toMySQL());
}
}
}

$where[] = 'c.published = 1';
$where[] = 'c.deleted = 0';
$where[] = "o.link <> ''";
$where[] = (is_array($access)? "o.access IN (" . implode(',', $access). ")" : " o.access <= " . (int) $access);

if (JCommentsMultilingual::isEnabled()) {
$where[] = 'o.lang = ' . $db->Quote(JCommentsMultilingual::getLanguage());
}

$joins = array();

if (count($source) == 1 && $source[0] == 'com_content') {
$joins[] = 'JOIN #__content AS cc ON cc.id = o.object_id';
$joins[] = 'LEFT JOIN #__categories AS ct ON ct.id = cc.catid';

$where[] = "c.object_group = " . $db->Quote($source[0]);
$where[] = "(cc.publish_up = '0000-00-00 00:00:00' OR cc.publish_up <= '$now')";
$where[] = "(cc.publish_down = '0000-00-00 00:00:00' OR cc.publish_down >= '$now')";

$categories = $params->get('catid', array());
if (!is_array($categories)) {
$categories = explode(',', $categories);
}

JArrayHelper::toInteger($categories);

$categories = implode(',', $categories);
if (!empty($categories)) {
$where[] = "cc.catid IN (" . $categories . ")";
}
} else if (count($source)) {
$where[] = "c.object_group in ('" . implode("','", $source). "')";
}

$query = "SELECT o.id, o.title, o.link"
. ", COUNT(c.id) AS commentsCount, MAX(c.date) AS commentdate"
. " FROM #__jcomments_objects AS o"
. " JOIN #__jcomments AS c ON c.object_id = o.object_id AND c.object_group = o.object_group AND c.lang = o.lang"
. (count($joins)? ' ' . implode(' ', $joins) : '')
. (count($where)? ' WHERE  ' . implode(' AND ', $where) : '')
. " GROUP BY o.id, o.title, o.link"
. " ORDER BY commentsCount DESC, c.date DESC"
;

$db->setQuery($query, 0, $params->get('count'));
$list = $db->loadObjectList();

return $list;
}
}


Измененный Helper most_commented (частично взятый из latest_news):
Код
<?php
// no direct access
defined('_JEXEC') or die;

class modJCommentsMostCommentedHelper
{
static function getList( &$params )
{
$db = JFactory::getDBO();
$user = JFactory::getUser();
$model = JModelLegacy::getInstance('Articles', 'ContentModel', array('ignore_request' => true));
$app = JFactory::getApplication();
$appParams = $app->getParams();
$model->setState('params', $appParams);


$model->setState('list.limit', (int) $params->get('count', 5));



// Category filter
$model->setState('filter.category_id', $params->get('catid', array()));

// User filter
$userId = JFactory::getUser()->get('id');

$source = $params->get('source', 'com_content');
if (!is_array($source)) {
$source = explode(',', $source);
}

$date = JFactory::getDate();

if (version_compare(JVERSION,'1.6.0','ge')) {
$now = $date->toSQL();
$access = array_unique(JAccess::getAuthorisedViewLevels($user->get('id')));
$access[] = 0; // for backward compability
} else {
$now = $date->toMySQL();
$access = $user->get('aid', 0);
}

$where = array();

$interval = $params->get('interval', '');
if (!empty($interval)) {

$timestamp = $date->toUnix();

switch($interval) {
case '1-day':
$timestamp = strtotime('-1 day', $timestamp);
break;

case '1-week':
$timestamp = strtotime('-1 week', $timestamp);
break;

case '2-week':
$timestamp = strtotime('-2 week', $timestamp);
break;

case '1-month':
$timestamp = strtotime('-1 month', $timestamp);
break;

case '3-month':
$timestamp = strtotime('-3 month', $timestamp);
break;

case '6-month':
$timestamp = strtotime('-6 month', $timestamp);
break;

case '1-year':
$timestamp = strtotime('-1 year', $timestamp);
break;
default:
$timestamp = NULL;
break;
}

if ($timestamp !== NULL) {
$dateFrom = JFactory::getDate($timestamp);
$dateTo = $date;

if (version_compare(JVERSION,'1.6.0','ge')) {
$where[] = 'c.date BETWEEN ' . $db->Quote($dateFrom->toSQL()). ' AND ' . $db->Quote($dateTo->toSQL());
} else {
$where[] = 'c.date BETWEEN ' . $db->Quote($dateFrom->toMySQL()). ' AND ' . $db->Quote($dateTo->toMySQL());
}
}
}

$where[] = 'c.published = 1';
$where[] = 'c.deleted = 0';
$where[] = "o.link <> ''";
$where[] = (is_array($access)? "o.access IN (" . implode(',', $access). ")" : " o.access <= " . (int) $access);

if (JCommentsMultilingual::isEnabled()) {
$where[] = 'o.lang = ' . $db->Quote(JCommentsMultilingual::getLanguage());
}

$joins = array();

if (count($source) == 1 && $source[0] == 'com_content') {
$joins[] = 'JOIN #__content AS cc ON cc.id = o.object_id';
$joins[] = 'LEFT JOIN #__categories AS ct ON ct.id = cc.catid';

$where[] = "c.object_group = " . $db->Quote($source[0]);
$where[] = "(cc.publish_up = '0000-00-00 00:00:00' OR cc.publish_up <= '$now')";
$where[] = "(cc.publish_down = '0000-00-00 00:00:00' OR cc.publish_down >= '$now')";

$categories = $params->get('catid', array());
if (!is_array($categories)) {
$categories = explode(',', $categories);
}

JArrayHelper::toInteger($categories);

$categories = implode(',', $categories);
if (!empty($categories)) {
$where[] = "cc.catid IN (" . $categories . ")";
}
} else if (count($source)) {
$where[] = "c.object_group in ('" . implode("','", $source). "')";
}


$list = $model->getItems();

foreach ($list as &$item)
{
$item->slug    = $item->id . ':' . $item->alias;

/** @deprecated Catslug is deprecated, use catid instead. 4.0 */
$item->catslug = $item->catid . ':' . $item->category_alias;


}

return $list;


}
}



Таким образом теперь работают строки в шаблоне:
Код
<?php $images = json_decode($item->images); ?>
<img src="<?php echo htmlspecialchars($images->image_intro); ?>"/>

Остальное ничего теперь не работает. Вывод самых комментируемых материалов обрубается. Выводятся просто по умолчанию, но с картинками.
« Последнее редактирование: 06.08.2020, 17:28:59 от R31rus »
*

sivers

  • Живу я здесь
  • 2450
  • 333 / 0
Возьмите слегка правленный стандартный:
Код
<?php
// no direct access
defined('_JEXEC') or die;

class modJCommentsMostCommentedHelper
{
static function getList( &$params )
{
$db = JFactory::getDBO();
$user = JFactory::getUser();

$source = $params->get('source', 'com_content');
if (!is_array($source)) {
$source = explode(',', $source);
}

$date = JFactory::getDate();

if (version_compare(JVERSION,'1.6.0','ge')) {
$now = $date->toSQL();
$access = array_unique(JAccess::getAuthorisedViewLevels($user->get('id')));
$access[] = 0; // for backward compability
} else {
$now = $date->toMySQL();
$access = $user->get('aid', 0);
}

$where = array();

$interval = $params->get('interval', '');
if (!empty($interval)) {

$timestamp = $date->toUnix();

switch($interval) {
case '1-day':
$timestamp = strtotime('-1 day', $timestamp);
break;

case '1-week':
$timestamp = strtotime('-1 week', $timestamp);
break;

case '2-week':
$timestamp = strtotime('-2 week', $timestamp);
break;

case '1-month':
$timestamp = strtotime('-1 month', $timestamp);
break;

case '3-month':
$timestamp = strtotime('-3 month', $timestamp);
break;

case '6-month':
$timestamp = strtotime('-6 month', $timestamp);
break;

case '1-year':
$timestamp = strtotime('-1 year', $timestamp);
break;
default:
$timestamp = NULL;
break;
}

if ($timestamp !== NULL) {
$dateFrom = JFactory::getDate($timestamp);
$dateTo = $date;

if (version_compare(JVERSION,'1.6.0','ge')) {
$where[] = 'c.date BETWEEN ' . $db->Quote($dateFrom->toSQL()). ' AND ' . $db->Quote($dateTo->toSQL());
} else {
$where[] = 'c.date BETWEEN ' . $db->Quote($dateFrom->toMySQL()). ' AND ' . $db->Quote($dateTo->toMySQL());
}
}
}

$where[] = 'c.published = 1';
$where[] = 'c.deleted = 0';
$where[] = "o.link <> ''";
$where[] = (is_array($access)? "o.access IN (" . implode(',', $access). ")" : " o.access <= " . (int) $access);

if (JCommentsMultilingual::isEnabled()) {
$where[] = 'o.lang = ' . $db->Quote(JCommentsMultilingual::getLanguage());
}

$joins = array();
$select = '';

if (count($source) == 1 && $source[0] == 'com_content') {
$joins[] = 'JOIN #__content AS cc ON cc.id = o.object_id';
$joins[] = 'LEFT JOIN #__categories AS ct ON ct.id = cc.catid';
$select .= "cc.*, ";

$where[] = "c.object_group = " . $db->Quote($source[0]);
$where[] = "(cc.publish_up = '0000-00-00 00:00:00' OR cc.publish_up <= '$now')";
$where[] = "(cc.publish_down = '0000-00-00 00:00:00' OR cc.publish_down >= '$now')";

$categories = $params->get('catid', array());
if (!is_array($categories)) {
$categories = explode(',', $categories);
}

JArrayHelper::toInteger($categories);

$categories = implode(',', $categories);
if (!empty($categories)) {
$where[] = "cc.catid IN (" . $categories . ")";
}
} else if (count($source)) {
$where[] = "c.object_group in ('" . implode("','", $source). "')";
}

$select .= "o.id, o.title, o.link";
$query = "SELECT ".$select
. ", COUNT(c.id) AS commentsCount, MAX(c.date) AS commentdate"
. " FROM #__jcomments_objects AS o"
. " JOIN #__jcomments AS c ON c.object_id = o.object_id AND c.object_group = o.object_group AND c.lang = o.lang"
. (count($joins)? ' ' . implode(' ', $joins) : '')
. (count($where)? ' WHERE  ' . implode(' AND ', $where) : '')
. " GROUP BY o.id, o.title, o.link"
. " ORDER BY commentsCount DESC, c.date DESC"
;

$db->setQuery($query, 0, $params->get('count'));
$list = $db->loadObjectList();

return $list;
}
}
Добавлены/изменены строки: 90, 95, 116, 117.
На связи в telegram @sivers
sivers @ inbox . ru
https://sivers.su/
*

R31rus

  • Давно я тут
  • 632
  • 4 / 0
Вроде работает, единственное теперь ссылки 404, пример:

Прежняя ссылка: test-mat-2
Текущая ссылка после изменений: 3-test-mat-2

В общих настройках движка включен роутер убрать ID из ссылок. Поэтому они сейчас 404
*

sivers

  • Живу я здесь
  • 2450
  • 333 / 0
Прежняя ссылка: test-mat-2
Текущая ссылка после изменений: 3-test-mat-2
Непонятно почему так, но попробуйте заменить строку:
Код
$select .= "cc.*, ";
вот на эту:
Код
$select .= "cc.images, ";
Это добавит в выборку только изображения без всех остальных полей материалов.
На связи в telegram @sivers
sivers @ inbox . ru
https://sivers.su/
*

R31rus

  • Давно я тут
  • 632
  • 4 / 0
Не не помогает(
Но в целом спасибо большое, это уже другой вопрос, если интересно пишите. Так-то сам попробую.
Задача решена!
*

sivers

  • Живу я здесь
  • 2450
  • 333 / 0
На здоровье.
Но эта правка не должна была изменить работу роутера. Где-то у вас еще что-то изменилось. Пробуйте )
На связи в telegram @sivers
sivers @ inbox . ru
https://sivers.su/
Чтобы оставить сообщение,
Вам необходимо Войти или Зарегистрироваться
 

Вывод даты материала в списке тегов

Автор androv77

Ответов: 2
Просмотров: 870
Последний ответ 09.11.2023, 16:33:08
от denxio
Вывод дополнительного поля материала в модуле

Автор timofe

Ответов: 10
Просмотров: 1470
Последний ответ 06.10.2023, 14:02:24
от Mitriy
Как сделать отображение времени создания материала?

Автор Pzhigalov

Ответов: 0
Просмотров: 308
Последний ответ 27.09.2023, 22:45:29
от Pzhigalov
[Решено] Получить список тегов каждого материала в блоге категории

Автор goga_pgasovav

Ответов: 1
Просмотров: 390
Последний ответ 02.03.2023, 14:20:21
от goga_pgasovav
ajax загрузка компонента на странице материала К2

Автор Divn

Ответов: 0
Просмотров: 515
Последний ответ 13.01.2023, 15:05:52
от Divn