Новости Joomla

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

Elimelech

  • Захожу иногда
  • 261
  • 2 / 0
Хочу добавить код дял подсчёта времени чтения статьи, да вот не могу найти файл отвечающий за вывод данной инфомрации в статьях Joomla.
См. внизу, где я указал место где я хочу вставить код.
Спасибо за помощь!

« Последнее редактирование: 24.12.2019, 16:30:15 от Elimelech »
*

beliyadm

  • Легенда
  • 9758
  • 1664 / 66
  • Севастополь, Россия
Ну в нормальном шаблоне это templates\шаблон\html\com_content\article\default.php
Все истины, которые я хочу вам изложить, — бесстыдная ложь. Сделать всё хорошо
TLG: @Beliyadm
*

Elimelech

  • Захожу иногда
  • 261
  • 2 / 0
Спасибо нашел, а вот такой код по этой статье- https://wordpressmania.ru/dobavljaem-vremja-chtenija-stati-na-sajte-wordpress/  можно добавить в файл  functions.php

Код
// подключаем расчет чтения
if ( ! function_exists( 'gp_read_time' ) ) {
function gp_read_time() {
$text = get_the_content( '' );
$words = str_word_count( strip_tags( $text ), 0, 'абвгдеёжзийклмнопрстуфхцчшщъыьэюяАБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ' );
if ( !empty( $words ) ) {
$time_in_minutes = ceil( $words / 200 );
return $time_in_minutes;
}
return false;
}
}
*

beliyadm

  • Легенда
  • 9758
  • 1664 / 66
  • Севастополь, Россия
В этом же файле пишите в начале
Код
	$words = str_word_count( strip_tags( $this->item->text ), 0, 'абвгдеёжзийклмнопрстуфхцчшщъыьэюяАБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ' );
if ( !empty( $words ) ) {
$time_in_minutes = ceil( $words / 50 );
echo $time_in_minutes .'';
}
И увидите количество минут в зависимости от скорости чтения (в данном случае 50), работает
Все истины, которые я хочу вам изложить, — бесстыдная ложь. Сделать всё хорошо
TLG: @Beliyadm
*

Elimelech

  • Захожу иногда
  • 261
  • 2 / 0
не совсем понял.
А как же шаблон?  templates\шаблон\html\com_content\article\default.php

Там нужно вставить код вывода функции:
Код
 <?php _e( 'На чтение', ' ' ); ?>: <?php echo gp_read_time(); ?> <?php _e( 'мин', ' ' ); ?>

А в файле functions.php только код, который вы подправили и рекомендуют в конце этого фала, а не в начале?
*

beliyadm

  • Легенда
  • 9758
  • 1664 / 66
  • Севастополь, Россия
Ну сделайте в вашем functions.php нужную функцию, сделайте в этом шаблоне include_once этого файла functions.php и используйте функцию.
Либо просто вставьте мой код в этом файле шаблона и посмотрите на результат
Просто вы путаете API вордпресса и joomla, есть же отличия, пробуйте мой вариант напрямую в коде файла шаблона и все будет хорошо
Все истины, которые я хочу вам изложить, — бесстыдная ложь. Сделать всё хорошо
TLG: @Beliyadm
*

Elimelech

  • Захожу иногда
  • 261
  • 2 / 0
Спасибо, я понял уже. А куда вставлять то ваш код в шаблоне, чтобы он показывался после даты статьи?

Код
<?php // no direct access
defined('_JEXEC') or die('Restricted access');

$canEdit = ($this->user->authorize('com_content', 'edit', 'content', 'all') || $this->user->authorize('com_content', 'edit', 'content', 'own'));
?>
<?php if ($this->params->get('show_page_title', 1) && $this->params->get('page_title')!= $this->article->title) : ?>
<div class="componentheading<?php echo $this->escape($this->params->get('pageclass_sfx')); ?>">
<?php echo $this->escape($this->params->get('page_title')); ?>
</div>
<?php endif; ?>
<?php if ($canEdit || $this->params->get('show_title') || $this->params->get('show_pdf_icon') || $this->params->get('show_print_icon') || $this->params->get('show_email_icon')) : ?>
<table class="contentpaneopen<?php echo $this->escape($this->params->get('pageclass_sfx')); ?>">
<tr>
<?php if ($this->params->get('show_title')) : ?>
<td class="contentheading<?php echo $this->escape($this->params->get('pageclass_sfx')); ?>" width="100%">
<?php if ($this->params->get('link_titles') && $this->article->readmore_link != '') : ?>
<a href="<?php echo $this->article->readmore_link; ?>" class="contentpagetitle<?php echo $this->escape($this->params->get('pageclass_sfx')); ?>">
<?php echo $this->escape($this->article->title); ?></a>
<?php else : ?>
<?php echo $this->escape($this->article->title); ?>
<?php endif; ?>
</td>
<?php endif; ?>
<?php if (!$this->print) : ?>
<?php if ($this->params->get('show_pdf_icon')) : ?>
<td align="right" width="100%" class="buttonheading">
<?php echo JHTML::_('icon.pdf',  $this->article, $this->params, $this->access); ?>
</td>
<?php endif; ?>

<?php if ( $this->params->get( 'show_print_icon' )) : ?>
<td align="right" width="100%" class="buttonheading">
<?php echo JHTML::_('icon.print_popup',  $this->article, $this->params, $this->access); ?>
</td>
<?php endif; ?>

<?php if ($this->params->get('show_email_icon')) : ?>
<td align="right" width="100%" class="single.phpbuttonheading">
<?php echo JHTML::_('icon.email',  $this->article, $this->params, $this->access); ?>
</td>
<?php endif; ?>
<?php if ($canEdit) : ?>
<td align="right" width="100%" class="buttonheading">
<?php echo JHTML::_('icon.edit', $this->article, $this->params, $this->access); ?>
</td>
<?php endif; ?>
<?php else : ?>
<td align="right" width="100%" class="buttonheading">
<?php echo JHTML::_('icon.print_screen',  $this->article, $this->params, $this->access); ?>
</td>
<?php endif; ?>
</tr>
</table>
<?php endif; ?>

<?php  if (!$this->params->get('show_intro')) :
echo $this->article->event->afterDisplayTitle;
endif; ?>
<?php echo $this->article->event->beforeDisplayContent; ?>
<table class="contentpaneopen<?php echo $this->escape($this->params->get('pageclass_sfx')); ?>">
<?php if (($this->params->get('show_section') && $this->article->sectionid) || ($this->params->get('show_category') && $this->article->catid)) : ?>
<tr>
<td>
<?php if ($this->params->get('show_section') && $this->article->sectionid && isset($this->article->section)) : ?>
<span>
<?php if ($this->params->get('link_section')) : ?>
<?php echo '<a href="'.JRoute::_(ContentHelperRoute::getSectionRoute($this->article->sectionid)).'">'; ?>
<?php endif; ?>
<?php echo $this->escape($this->article->section); ?>
<?php if ($this->params->get('link_section')) : ?>
<?php echo '</a>'; ?>
<?php endif; ?>
<?php if ($this->params->get('show_category')) : ?>
<?php echo ' - '; ?>
<?php endif; ?>
</span>
<?php endif; ?>
<?php if ($this->params->get('show_category') && $this->article->catid) : ?>
<span>
<?php if ($this->params->get('link_category')) : ?>
<?php echo '<a href="'.JRoute::_(ContentHelperRoute::getCategoryRoute($this->article->catslug, $this->article->sectionid)).'">'; ?>
<?php endif; ?>
<?php echo $this->escape($this->article->category); ?>
<?php if ($this->params->get('link_category')) : ?>
<?php echo '</a>'; ?>
<?php endif; ?>
</span>
<?php endif; ?>
</td>
</tr>
<?php endif; ?>
<?php if (($this->params->get('show_author')) && ($this->article->author != "")) : ?>
<tr>
<td valign="top">
<span class="small">
<?php JText::printf( 'Written by', ($this->escape($this->article->created_by_alias)? $this->escape($this->article->created_by_alias) : $this->escape($this->article->author)) ); ?>
</span>
&nbsp;&nbsp;
</td>
</tr>
<?php endif; ?>

<?php if ($this->params->get('show_create_date')) : ?>
<tr>
<td valign="top" class="createdate">
<?php echo JHTML::_('date', $this->article->created, JText::_('DATE_FORMAT_LC2'))?>
</td>
</tr>
<?php endif; ?>

<?php if ($this->params->get('show_url') && $this->article->urls) : ?>
<tr>
<td valign="top">
<a href="http://<?php echo $this->article->urls ; ?>" target="_blank">
<?php echo $this->escape($this->article->urls); ?></a>
</td>
</tr>
<?php endif; ?>

<tr>
<td valign="top">
<?php if (isset ($this->article->toc)) : ?>
<?php echo $this->article->toc; ?>
<?php endif; ?>
<?php echo $this->article->text; ?>
</td>
</tr>

<?php if ( intval($this->article->modified)!=0 && $this->params->get('show_modify_date')) : ?>
<tr>
<td class="modifydate">
<?php echo JText::sprintf('LAST_UPDATED2', JHTML::_('date', $this->article->modified, JText::_('DATE_FORMAT_LC2'))); ?>
</td>
</tr>
<?php endif; ?>
</table>
<span class="article_separator">&nbsp;</span>
<?php echo $this->article->event->afterDisplayContent; ?>
*

beliyadm

  • Легенда
  • 9758
  • 1664 / 66
  • Севастополь, Россия
Ну после блока <?php if ($this->params->get('show_create_date')) : ?>
Все остальное - это ваша верстка
Все истины, которые я хочу вам изложить, — бесстыдная ложь. Сделать всё хорошо
TLG: @Beliyadm
*

Elimelech

  • Захожу иногда
  • 261
  • 2 / 0
Что-то чистое вставляние кода в шаблон не работает!  Я так понял его нужно во что-то "обернуть"?
*

beliyadm

  • Легенда
  • 9758
  • 1664 / 66
  • Севастополь, Россия
Что-то чистое вставляние кода в шаблон не работает!  Я так понял его нужно во что-то "обернуть"?
В PHP теги
Код
<?php
 // код тут
?>
Все истины, которые я хочу вам изложить, — бесстыдная ложь. Сделать всё хорошо
TLG: @Beliyadm
*

Elimelech

  • Захожу иногда
  • 261
  • 2 / 0
пробовал - ничео не выводит!
что-то меня мучает сомнение, тут случайно точка не лишняя?  - echo $time_in_minutes .'';
Хотя и без точки не работает. :(
*

Elimelech

  • Захожу иногда
  • 261
  • 2 / 0
Короче там одна ошибочка не $this->item->text, а $this->article->text

Код
- <span> 
<?php
$words = str_word_count(strip_tags( $this->article->text),0, 'абвгдеёжзийклмнопрстуфхцчшщъыьэюяАБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ');
if (!empty( $words)) {
$time_in_minutes = ceil($words / 260);
echo $time_in_minutes .'';
}
?>мин. чтения</span>
Чтобы оставить сообщение,
Вам необходимо Войти или Зарегистрироваться
 

Не найти страницу

Автор Алексей2019

Ответов: 2
Просмотров: 2407
Последний ответ 07.02.2020, 11:42:09
от draff
Не могу найти в админке баннер/картинку

Автор yemejayox

Ответов: 2
Просмотров: 3929
Последний ответ 10.05.2019, 08:56:44
от alexey711
Как найти в админке по url с сайта нужный раздел?

Автор tegowamila

Ответов: 6
Просмотров: 2523
Последний ответ 22.06.2018, 17:51:13
от draff
Не могу найти где поменять контакты

Автор mad-actions

Ответов: 4
Просмотров: 1254
Последний ответ 28.04.2018, 15:56:47
от mad-actions
Вывод title для ссылок в меню

Автор Baraka

Ответов: 6
Просмотров: 44279
Последний ответ 09.11.2009, 21:53:10
от Sulpher