Login     Sign up
Show Popular Post (blog, Videos, Music, Photos etc) on homepage
emjhie Bahrink (@emjhie)
Join date: Sep 27th 2010
Community posts: 91
View Profile
Send Message

Popular post in homepage.

step 1. function code.. for simple add this code above [code]</head> page.tpl.php of themes[/code]
function code:
[code]
<?
function get_list_popular($app, $type = '') {
global $apps;
if ($type == 'thumb') {
$num = 3;
}
else {
$num = 5;
}
// total
$res = sql_query("select count() as total from ".tb()."stories where app='$app'");
$row = sql_fetch_array($res);
$total = $row['total'];
$res = sql_query("SELECT s.
,u.username FROM ".tb()."stories as s LEFT JOIN ".tb()."accounts as u ON u.id=s.uid where s.app='$app' order by s.views DESC limit $num");
if ($type == 'thumb') {
$content .= '<table width="100%"><tr>';
while ($row = sql_fetch_array($res)) {
if (!$row['thumbnail']) {
if ($app == 'music') {
$row['thumbnail'] = 'uploads/userfiles/undefined_song.gif';
}
else {
$row['thumbnail'] = 'uploads/userfiles/undefined.jpg';
}
}
$content .= '<td align="center">'.url($row['app'].'/viewstory/'.$row['id'],htmlspecialchars(utf8_substr($row['title'],20))).'<br />
<a href="'.url($row['app'].'/viewstory/'.$row['id']).'"><img class="thumb" src="'.uhome().'/'.$row['thumbnail'].'" /></a></td>';
}
$content .= '</tr></table>';
}
else {
$content .= '<ul class="simple_list">';
while ($row = sql_fetch_array($res)) {
$row['content'] = preg_replace("/[\w+](.*)[\/\w+]/isU","\1",$row['content']);
$row['content'] = strip_tags(utf8_substr($row['content'],90));
$content .= '<li><strong>'.url($row['app'].'/viewstory/'.$row['id'],htmlspecialchars(utf8_substr($row['title'],60))).'</strong><br /></li>';
}
$content .= '</ul>';
}
return $content;
}

?>
[/code]

step 2. Element code. Add this code to elemen body where you went.

[code]
echo '<div class="block">
<div class="block_title">'.t('Photo albums').'</div>
<div class="block_content">'.get_list_popular('photos','thumb').'</div>
</div>';

echo '<div class="block">
<div class="block_title">'.t('Music').'</div>
<div class="block_content">'.get_list_popular('music','thumb').'</div>
</div>';

echo '<div class="block">
<div class="block_title">'.t('Videos').'</div>
<div class="block_content">'.get_list_popular('videos','thumb').'</div>
</div>';

echo '<div class="block">
<div class="block_title">'.t('Blogs').'</div>
<div class="block_content">'.get_list_popular('blogs').'</div>
</div>';
[/code]

finish:

option: see code function above
change Variable Number=3 for to show item for videos, photos n music
change variable Number 5 for blogs

demo [url]http://bulkum.com[/url]

161 months ago