Login     Sign up
Show Latest Photos, Videos and Music on Home Page
jacky loon (@jack41)
Join date: Nov 9th 2010
Community posts: 87
View Profile
Send Message

With the help of this link "[url]http://www.jcow.net/docs/?s=custom_home"[/url] it is discovered that now you can also show recent Music files on your site home page. To show latest photo albums, latest videos and latest music add this code to your home.tpl.php in the end in blue theme.

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

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

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

function get_list($app, $type = '') {
    global $apps;
    if ($type == 'thumb') {
        $num = 4;
    }
    else {
        $num = 10;
    }
    // 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.id 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>
            <span class="sub">'.get_date($row['created']).', by '.url('u/'.$row['username'],$row['username']).'</span><br />
            <span class="sub">'.$row['content'].'</span></li>';
        }
        $content .= '</ul>';
    }
    return $content;
} 
164 months ago
kingmagi (@king10magi)
Join date: Sep 6th 2010
Community posts: 97
View Profile
Send Message

em.. how about on facebook theme??

164 months ago
izhanjafry (@izhanjafry)
Join date: Dec 14th 2010
Community posts: 16
View Profile
Send Message

put on /page.tpl.php

but make sure put the function first before the content..

164 months ago
kingmagi (@king10magi)
Join date: Sep 6th 2010
Community posts: 97
View Profile
Send Message

em.. which one is function??

can u give me in separated code??

Thank You,

164 months ago
izhanjafry (@izhanjafry)
Join date: Dec 14th 2010
Community posts: 16
View Profile
Send Message

[quote=king10magi]em.. which one is function??

can u give me in separated code??

Thank You, [/quote]

function get_list($app, $type = '') {
global $apps;
if ($type == 'thumb') {
$num = 4;
}
else {
$num = 10;
}
// 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.id 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>
<span class="sub">'.get_date($row['created']).', by '.url('u/'.$row['username'],$row['username']).'</span><br />
<span class="sub">'.$row['content'].'</span></li>';
}
$content .= '</ul>';
}
return $content;
}

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

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

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

or you can make above code a custom .php file and then include on /page.tpl.php
put like this example :

include_once ('yourlocation/customfile.php');

im also learning.. :-)

164 months ago
kingmagi (@king10magi)
Join date: Sep 6th 2010
Community posts: 97
View Profile
Send Message

emm..thank you anyway...how about u give me ur page.tpl??

i mean the code?? then i will paste into mine its more easy

Thank You,

164 months ago
izhanjafry (@izhanjafry)
Join date: Dec 14th 2010
Community posts: 16
View Profile
Send Message

[quote=king10magi]emm..thank you anyway...how about u give me ur page.tpl??

i mean the code?? then i will paste into mine its more easy

Thank You, [/quote]

i had send you a message. you can look at my page.tpl.php but maybe you not all work on your website. tq

164 months ago
kingmagi (@king10magi)
Join date: Sep 6th 2010
Community posts: 97
View Profile
Send Message

ohh..okay i will make backup first then i will try..

Thank you very much!

164 months ago
elvin (@elvinson)
Join date: Aug 23rd 2010
Community posts: 12
View Profile
Send Message

thanks it is working in my site, but how to make it small size. [url]http://speakasiaonlinemoney.com/penalist[/url]

159 months ago