» » » [Блок] Последние Объявления/Новости на главной

[Блок] Последние Объявления/Новости на главной

Я так сделал чисто под свой сайт, ну если кому нужен тому выкладываю. Для начала давайте посмотрим как это всё выглядит к примеру возьмем плагин Объявлений!

[Блок] Последние Объявления/Новости на главной


заходим в user_home.php

и перед строчкой
// ASSIGN SMARTY VARIABLES AND INCLUDE FOOTER


Ставим это:
// PARSE GET/POST
if(isset($_POST['p'])) { $p = $_POST['p']; } elseif(isset($_GET['p'])) { $p = $_GET['p']; } else { $p = 1; }
if(isset($_POST['s'])) { $s = $_POST['s']; } elseif(isset($_GET['s'])) { $s = $_GET['s']; } else { $s = "classified_datecreated DESC"; }
if(isset($_POST['v'])) { $v = $_POST['v']; } elseif(isset($_GET['v'])) { $v = $_GET['v']; } else { $v = 0; }
if(isset($_POST['classifiedcat_id'])) { $classifiedcat_id = $_POST['classifiedcat_id']; } elseif(isset($_GET['classifiedcat_id'])) { $classifiedcat_id = $_GET['classifiedcat_id']; } else { $classifiedcat_id = 0; }
if(isset($_POST['classified_search'])) { $classified_search = $_POST['classified_search']; } elseif(isset($_GET['classified_search'])) { $classified_search = $_GET['classified_search']; } else { $classified_search = NULL; }

// ENSURE SORT/VIEW ARE VALID
if($s != "classified_date DESC" && $s != "classified_dateupdated DESC" && $s != "classified_views DESC" && $s != "total_comments DESC") { $s = "classified_date DESC"; }
if($v != "0" && $v != "1") { $v = 0; }


// SET WHERE CLAUSE
$where = "CASE
WHEN se_classifieds.classified_user_id='{$user->user_info['user_id']}'
THEN TRUE
WHEN ((se_classifieds.classified_privacy & @SE_PRIVACY_REGISTERED) AND '{$user->user_exists}'<>0)
THEN TRUE
WHEN ((se_classifieds.classified_privacy & @SE_PRIVACY_ANONYMOUS) AND '{$user->user_exists}'=0)
THEN TRUE
WHEN ((se_classifieds.classified_privacy & @SE_PRIVACY_FRIEND) AND '{$user->user_exists}'<>0 AND (SELECT TRUE FROM se_friends WHERE friend_user_id1=se_classifieds.classified_user_id AND friend_user_id2='{$user->user_info['user_id']}' AND friend_status='1' LIMIT 1))
THEN TRUE
WHEN ((se_classifieds.classified_privacy & @SE_PRIVACY_SUBNET) AND '{$user->user_exists}'<>0 AND (SELECT TRUE FROM se_users WHERE user_id=se_classifieds.classified_user_id AND user_subnet_id='{$user->user_info['user_subnet_id']}' LIMIT 1))
THEN TRUE
WHEN ((se_classifieds.classified_privacy & @SE_PRIVACY_FRIEND2) AND '{$user->user_exists}'<>0 AND (SELECT TRUE FROM se_friends AS friends_primary LEFT JOIN se_users ON friends_primary.friend_user_id1=se_users.user_id LEFT JOIN se_friends AS friends_secondary ON friends_primary.friend_user_id2=friends_secondary. friend_user_id1 WHERE friends_primary.friend_user_id1=se_classifieds.cla ssified_user_id AND friends_secondary.friend_user_id2='{$user->user_info['user_id']}' AND se_users.user_subnet_id='{$user->user_info['user_subnet_id']}' LIMIT 1))
THEN TRUE
ELSE FALSE
END";



// ONLY MY FRIENDS' CLASSIFIEDS
if( $v=="1" && $user->user_exists )
{
// SET WHERE CLAUSE
$where .= " AND (SELECT TRUE FROM se_friends WHERE friend_user_id1='{$user->user_info['user_id']}' AND friend_user_id2=se_classifieds.classified_user_id AND friend_status=1)";
}



// SPECIFIC CLASSIFIED CATEGORY
if( $classifiedcat_id )
{
$sql = "SELECT classifiedcat_id, classifiedcat_title, classifiedcat_dependency FROM se_classifiedcats WHERE classifiedcat_id={$classifiedcat_id} LIMIT 1";
$resource = $database->database_query($sql) or die("тут должна была быть бага )");

if( $database->database_num_rows($resource) )
{
$classifiedcat = $database->database_fetch_assoc($resource);

if( !$classifiedcat['classifiedcat_dependency'] )
{
$cat_ids[] = $classifiedcat['classifiedcat_id'];
$depcats = $database->database_query("SELECT classifiedcat_id FROM se_classifiedcats WHERE classifiedcat_id='{$classifiedcat['classifiedcat_id']}' OR classifiedcat_dependency='{$classifiedcat['classifiedcat_id']}'");
while($depcat_info = $database->database_fetch_assoc($depcats)) { $cat_ids[] = $depcat_info['classifiedcat_id']; }
$where .= " AND se_classifieds.classified_classifiedcat_id IN('".implode("', '", $cat_ids)."')";
}
else
{
$where .= " AND se_classifieds.classified_classifiedcat_id='{$clas sifiedcat['classifiedcat_id']}'";
$classifiedsubcat = $classifiedcat;
$classifiedcat = $database->database_fetch_assoc($database->database_query("SELECT classifiedcat_id, classifiedcat_title FROM se_classifiedcats WHERE classifiedcat_id='{$classifiedcat['classifiedcat_dependency']}'"));
}
}
}


// GET CATS
$field = new se_field("classified");
$field->cat_list(0, 0, 0, "", "", "");
$cat_menu_array = $field->cats;

//$field->cat_list(0, 0, 1, "classifiedcat_id='{$classifiedcat['classifiedcat_id']}'", "", "");
$field->field_list(0, 0, 1, "classifiedfield_classifiedcat_id='{$classifie dcat['classifiedcat_id']}' && classifiedfield_search<>'0'");


// BEGIN CONSTRUCTING SEARCH QUERY
//echo $field->field_query;
if( $field->field_query )
$where .= " && ".$field->field_query;

if( !empty($classified_search) )
{
$where .= " && MATCH(classified_title, classified_body) AGAINST ('{$classified_search}' IN BOOLEAN MODE) ";
}


// CREATE CLASSIFIED OBJECT, GET TOTAL CLASSIFIEDS, MAKE ENTRY PAGES, GET CLASSIFIED ARRAY
$classified = new se_classified();

$total_classifieds = $classified->classified_total($where, TRUE);
$classifieds_per_page = 10;
$page_vars = make_page($total_classifieds, $classifieds_per_page, $p);

$classified_array = $classified->classified_list($page_vars[0], $classifieds_per_page, $s, $where, TRUE);


Дальше там же после строчки
// ASSIGN SMARTY VARIABLES AND INCLUDE FOOTER


ставим
$smarty->assign('classifiedcat_id', $classifiedcat_id);
$smarty->assign('classifiedcat', $classifiedcat);
$smarty->assign('classifiedsubcat', $classifiedsubcat);
$smarty->assign('classified_search', $classified_search);

$smarty->assign_by_ref('cats_menu', $cat_menu_array);
$smarty->assign_by_ref('cats', $field->cats);
$smarty->assign_by_ref('fields', $field->fields);
$smarty->assign_by_ref('url_string', $field->url_string);

$smarty->assign('classifieds', $classified_array);
$smarty->assign('total_classifieds', $total_classifieds);
$smarty->assign('p', $page_vars[1]);
$smarty->assign('maxpage', $page_vars[2]);
$smarty->assign('p_start', $page_vars[0]+1);
$smarty->assign('p_end', $page_vars[0]+count($classified_array));
$smarty->assign('s', $s);
$smarty->assign('v', $v);


Всё, сохраняем, закрываем!

Дальше открываем файл user_home.tpl
там пишем (Вставляйте его куда угодно, всё зависит от шаблоны и от вашего контента сайта):
Дальше всё зависит от вашего шаблона и самого сайта! Я пишу как именно у меня

{* Последние новости *}
<div class="headerblue">Последние Объявления</div>
<div style="border-right:1px solid #93B6D5; border-left:1px solid #93B6D5; width:248px;

padding:10px;">

{section name=classified_loop loop=$classifieds max=2}
<table cellpadding='0' cellspacing='0'>
<tr>
<td>
<a href='{$url->url_create("classified",

$classifieds[classified_loop].classified_author->user_info.user_username,

$classifieds[classified_loop].classified->classified_info.classified_id)}'>
<img

src='{$classifieds[classified_loop].classified->classified_photo("./images/nophoto.gif", TRUE)}'

border='0' width='60' height='60' />
</a>
</td>
<td style='vertical-align: top; padding-left: 10px;'>
<div style='font-weight: bold; font-size: 8pt;'>
<a href='{$url->url_create("classified",

$classifieds[classified_loop].classified_author->user_info.user_username,

$classifieds[classified_loop].classified->classified_info.classified_id)}'>
{$classifieds[classified_loop].classified->classified_info.classified_title}
</a>
</div>
<div style='color: #777777; font-size: 7pt; margin-bottom: 0px;'>
{assign var='classified_datecreated'

value=$datetime->time_since($classifieds[classified_loop].classified->classified_info.classified_

date)}
{capture assign="created"}{lang_sprintf id=$classified_datecreated[0]

1=$classified_datecreated[1]}{/capture}
{assign var='classified_dateupdated'

value=$datetime->time_since($classifieds[classified_loop].classified->classified_info.classified_

dateupdated)}
{capture assign="updated"}{lang_sprintf id=$classified_dateupdated[0]

1=$classified_dateupdated[1]}{/capture}



</div>
<div>


{$classifieds[classified_loop].classified->classified_info.classified_body|strip_tags|trunca te:10

0:"..."} <a href='{$url->url_create("classified",

$classifieds[classified_loop].classified_author->user_info.user_username,

$classifieds[classified_loop].classified->classified_info.classified_id)}'><font

style='font-size:9px; color:#000000;'>подробнее</font></a>
</div>
</td>
</tr>
</table>
{if $smarty.section.classified_loop.last == false}<br>---------------------------------<br><br>{/if}
{/section}
<div style="float:right;"><a href='browse_classifieds.php' class='top_menu_item'>Bce &raquo;</a></div>
</div>
<div class="headerblue_footer"></div>
<div class="portal_spacer"></div>


Всё, сохраняем, закрываем. Очищаем всё здесь "\include\smarty\templates_c" Обновляем страницу!

Поделиться

Другие публикации по теме:

Комментарии