Web Лавка
Content Manager System
SEO
![TopNews из определенной категории DLE [v.2] TopNews из определенной категории DLE [v.2]](/uploads/posts/2010-04/1270295175_topnews.jpg)
Проверено на версии 8.3 -8.5
Установка:
в index.php перед:
$config['http_home_url'] = explode ( "index.php", strtolower ( $_SERVER['PHP_SELF'] ) );
добавляем:
if ( stristr( $tpl->copy_template, "{topnews" ) ) {
$tpl->copy_template = preg_replace( "#\\{topnews category=['\"](.+?)['\"]\\}#ies", "topnews_print('\\1')", $tpl->copy_template );
}
$tpl->copy_template = preg_replace( "#\\{topnews category=['\"](.+?)['\"]\\}#ies", "topnews_print('\\1')", $tpl->copy_template );
}
в файле engine/modules/functions.php перед:
function langdate($format, $stamp) {
добавляем функцию:
function topnews_print ($custom_category){
global $db;
$custom_category = $db->safesql(str_replace(',', '|', $custom_category));
if(!defined('DATALIFEENGINE'))
{
die("Hacking attempt!");
}
$topnews = dle_cache("topnews", $config['skin']);
if (!$topnews) {
$this_month = date ('Y-m-d', time()-(3600*24*27));
$db->query("SELECT id, title, short_story, date, alt_name FROM " . PREFIX . "_post WHERE approve='1' AND category regexp '[[:<:]]($custom_category)[[:>:]]' AND date >= '$this_month'AND date < '$this_month' + INTERVAL 1 MONTH ORDER BY rating DESC, comm_num DESC, news_read DESC, date DESC LIMIT 0,10");
while($row = $db->get_row()){
$row['date'] = strtotime($row['date']);
if (strlen($row['title']) > 55)
$title = substr ($row['title'], 0, 55)." ...";
else
$title = $row['title'];
$go_page = ($config['ajax']) ? "onclick=\"DlePage('newsid=".$row['id']."'); return false;\" " : "";
if ($config['allow_alt_url'] == "yes")
$link = "<a {$go_page}href=\"".$config['http_home_url'].date('Y/m/d/', $row['date']).$row['alt_name'].".html\">".stripslashes($title)."</a>";
else
$link = "<a {$go_page}href=\"\?newsid=".$row['id']."\">".stripslashes($title)."</a>";
$topnews .= "» ".$link."<br />";
$row['short_story'] = preg_replace("/\[attachment=[[:digit:]]*\]/si","",stripslashes($row['short_story']));
$row['short_story'] = preg_replace("/<!--*-->/si","",$row['short_story']);
$row['short_story'] = strip_tags($row['short_story']);
if( strlen( $row['short_story'] ) > 106 ) $row['short_story'] = substr( $row['short_story'], 0,106 ) . " ... <a {$go_page}href=\"\?newsid=".$row['id']."\" title=\"$titla\" style=\"font-size:12px\">Читать далее »</a>";
$topnews .= '<table width="98%" border="0" style="border-bottom: 1px dotted #E1E1E1;">
<td width="91%" valign="top" style="padding-left: 7px; padding-bottom: 7px; font-size:13px">
'.stripslashes($row['short_story']).'</td>
</tr>
</table>';
}
$db->free();
create_cache ("topnews", $topnews, $config['skin']);
}
return $topnews;
}
global $db;
$custom_category = $db->safesql(str_replace(',', '|', $custom_category));
if(!defined('DATALIFEENGINE'))
{
die("Hacking attempt!");
}
$topnews = dle_cache("topnews", $config['skin']);
if (!$topnews) {
$this_month = date ('Y-m-d', time()-(3600*24*27));
$db->query("SELECT id, title, short_story, date, alt_name FROM " . PREFIX . "_post WHERE approve='1' AND category regexp '[[:<:]]($custom_category)[[:>:]]' AND date >= '$this_month'AND date < '$this_month' + INTERVAL 1 MONTH ORDER BY rating DESC, comm_num DESC, news_read DESC, date DESC LIMIT 0,10");
while($row = $db->get_row()){
$row['date'] = strtotime($row['date']);
if (strlen($row['title']) > 55)
$title = substr ($row['title'], 0, 55)." ...";
else
$title = $row['title'];
$go_page = ($config['ajax']) ? "onclick=\"DlePage('newsid=".$row['id']."'); return false;\" " : "";
if ($config['allow_alt_url'] == "yes")
$link = "<a {$go_page}href=\"".$config['http_home_url'].date('Y/m/d/', $row['date']).$row['alt_name'].".html\">".stripslashes($title)."</a>";
else
$link = "<a {$go_page}href=\"\?newsid=".$row['id']."\">".stripslashes($title)."</a>";
$topnews .= "» ".$link."<br />";
$row['short_story'] = preg_replace("/\[attachment=[[:digit:]]*\]/si","",stripslashes($row['short_story']));
$row['short_story'] = preg_replace("/<!--*-->/si","",$row['short_story']);
$row['short_story'] = strip_tags($row['short_story']);
if( strlen( $row['short_story'] ) > 106 ) $row['short_story'] = substr( $row['short_story'], 0,106 ) . " ... <a {$go_page}href=\"\?newsid=".$row['id']."\" title=\"$titla\" style=\"font-size:12px\">Читать далее »</a>";
$topnews .= '<table width="98%" border="0" style="border-bottom: 1px dotted #E1E1E1;">
<td width="91%" valign="top" style="padding-left: 7px; padding-bottom: 7px; font-size:13px">
'.stripslashes($row['short_story']).'</td>
</tr>
</table>';
}
$db->free();
create_cache ("topnews", $topnews, $config['skin']);
}
return $topnews;
}
Популярные новости выводим тегом {topnews category="ID категории"}
Пример: {topnews category="1,2,3"}
Комментарии (0)
Просмотров: 2007
Информация
Посетители, находящиеся в группе Гости, не могут оставлять комментарии к данной публикации.
