Множество блоков Топ новостей в DLE

Все блоги / DLE движок для сайтов 9 июля 2010 0   
Понадобилось мне на днях в одном проекте на Datalife Engine вывести блоки Топ новостей из разных категорий. Дабы не изобретать велосипед и не тратить свое время, я решил немного погуглить в поисках быстрого решения. Нашел много всякого, но все либо платное, либо чересчур корявое и не совсем то, что мне нужно было. Буквально за две минуты я придумал очень простое и оригинальное решение: а почему бы не взять всем хорошо известный тег {custom} и его немного модифицировать? Это я собственно и сделал. Для этого нужно:
1) Открыть /engine/modules/functions.php и найти в нем функцию custom_print, которая обрабатывает custom вывод:

function custom_print($custom_category, $custom_template, $aviable, $custom_from, $custom_limit, $custom_cache, $do) {

Заеняем на:

function custom_print($custom_category, $custom_template, $aviable, $custom_from, $custom_limit, $custom_cache, $do, $top) {

Кто не заметили, здесь мы добавили $top.

2) Здесь же, в этой функции ищем:

$sql_select = "SELECT id, autor, date, short_story, full_story, xfields, title, category, alt_name, comm_num, allow_comm, allow_rate, rating, vote_num, news_read, flag, editdate, editor, reason, view_edit, tags, icon, flash_size, game_lang FROM " . PREFIX . "_post WHERE " . $stop_list . $where_category . " AND approve" . $where_date . " ORDER BY " . $fixed . $news_sort . " " . $news_msort . " LIMIT " . $custom_from . "," . $custom_limit;


Заменяем на:

if( $top == "yes") {
$sql_select = "SELECT id, autor, date, short_story, full_story, xfields, title, category, alt_name, comm_num, allow_comm, allow_rate, rating, vote_num, news_read, flag, editdate, editor, reason, view_edit, tags FROM " . PREFIX . "_post WHERE " . $stop_list . $where_category . " AND approve" . $where_date . " ORDER BY rating DESC, comm_num DESC, news_read DESC, date DESC LIMIT " . $custom_from . "," . $custom_limit;
} else {
$sql_select = "SELECT id, autor, date, short_story, full_story, xfields, title, category, alt_name, comm_num, allow_comm, allow_rate, rating, vote_num, news_read, flag, editdate, editor, reason, view_edit, tags FROM " . PREFIX . "_post WHERE " . $stop_list . $where_category . " AND approve" . $where_date . " ORDER BY " . $fixed . $news_sort . " " . $news_msort . " LIMIT " . $custom_from . "," . $custom_limit;
}


Здесь мы поставили условие - если будет указано, что в блоке выводить только Топ новости, то запрос будет немного другой, для топа новостей. Сам запрос был взят из штатного Топа новостей в DLE.

3) Открываем index.php в корне сайта и находим:

$tpl->copy_template = preg_replace ( "#\{custom category=["](.+?)["] template=["](.+?)["] aviable=["](.+?)["] from=["](.+?)["] limit=["](.+?)["] cache=["](.+?)["]\}#ies", "custom_print(\1, \2, \3, \4, \5, \6, {$dle_module})", $tpl->copy_template );


Заменяем на:

$tpl->copy_template = preg_replace ( "#\{custom category=["](.+?)["] template=["](.+?)["] aviable=["](.+?)["] from=["](.+?)["] limit=["](.+?)["] cache=["](.+?)["] top=["](.+?)["]\}#ies", "custom_print(\1, \2, \3, \4, \5, \6, {$dle_module}, \7)", $tpl->copy_template );


Здесь изменили обработку самого тега {custom}, а именно добавили один параметр - top, который может принимать значение yes или no.

На этом все прелести закончились, переходим непосредственно к самому шаблону, а точнее к месту, где будет выводить блоки Топ новостей.
Открываем main.tpl и в нужном для нас месте вставляем наш модифицированный тег {custom} следующего вида:

{custom category="1" template="custom" aviable="global" from="0" limit="10" cache="yes" top="yes"}

Надеюсь разжевывать не надо, за что отвечает каждый параметр. Внимание лишь на один - top="yes".
Догадайтесь сами, что он значит :)

 Источник:Блог о верстке Руслана Дерепко, DLE

Похожие публикации

@
  • bowtiesmilelaughingblushsmileyrelaxedsmirk
    heart_eyeskissing_heartkissing_closed_eyesflushedrelievedsatisfiedgrin
    winkstuck_out_tongue_winking_eyestuck_out_tongue_closed_eyesgrinningkissingstuck_out_tonguesleeping
    worriedfrowninganguishedopen_mouthgrimacingconfusedhushed
    expressionlessunamusedsweat_smilesweatdisappointed_relievedwearypensive
    disappointedconfoundedfearfulcold_sweatperseverecrysob
    joyastonishedscreamtired_faceangryragetriumph
    sleepyyummasksunglassesdizzy_faceimpsmiling_imp
    neutral_faceno_mouthinnocent

Архив публикаций