Back to vBulletin 3 Articles

Create "Latest Threads" Custom Page
by Princeton 23 Feb 2006

A simple [HOWTO] to display latest threads on a custom page.

If you don't have http://www.vbulletin.org/forum/showthread.php?threadid=108583 installed .. go download and upload product via Plugin Manager. You need GTCUSTOM PAGES to follow this article.

LETS GET STARTED

INSTRUCTIONS:
  1. create 2 templates
  2. add 1 phrase
  3. add function to functions_gtcustom.php
  4. edit goto.php
  5. visit page at $vboptions[bburl]/goto.php?section=newthreads

1)__ CREATE 2 TEMPLATES
Create "custom_thread" template:

HTML Code:
<table class="tborder" cellpadding="$stylevar[cellpadding]" cellspacing="$stylevar[cellspacing]" border="0" width="100%">
  <tbody>
    <tr>
      <td class="tcat" colspan="5"><a style="float:$stylevar[right]" href="#top" onclick="return toggle_collapse('gtcthreads')"><img id="collapseimg_gtcthreads" src="$stylevar[imgdir_button]/collapse_tcat$vbcollapse[collapseimg_gtcthreads].gif" alt="" border="0" /></a>$vbphrase[header_title]</td>
    </tr>
    <tr class="thead">
      <td>&nbsp;</td>
      <td class="smallfont" align="$stylevar[left]" width="100%">$vbphrase[thread] / $vbphrase[thread_starter]</td>
      <td class="smallfont" align="center" style="white-space:nowrap">$vbphrase[last_post]</td>
      <td class="smallfont" align="center">$vbphrase[replies]</td>
      <td class="smallfont" align="center">$vbphrase[views]</td>
    </tr>
  </tbody>
  <tbody id="collapseobj_gtcthreads" style="$vbcollapse[collapseobj_gtcthreads]">  
  $threadrows
  </tbody>  
</table>
<br />
Create "custom_threadrow" template:
HTML Code:
<tr>
	<td class="alt2" align="center"><if condition="$show['threadicon']"><img class="inlineimg" src="$thread[iconpath]" alt="" border="0" title="" /> <else />&nbsp;</if></td>
	<td class="alt1"><a href="showthread.php?t=$thread[threadid]"><strong>$thread[title]</strong></a>
		<div class="smallfont"> - by $thread[postusername]</div></td>
	<td class="alt2" align="center"><div class="smallfont time" style="white-space:nowrap">$thread[lastpostdate] $thread[lastposttime]<br />by $thread[lastposter]</div></td>
	<td class="alt1" align="center">$thread[replycount]</td>
	<td class="alt2" align="center">$thread[views]</td>
</tr>
2)__ CREATE 1 PHRASE
Phrase Type: GTCustom Pages
Product: GTCustom Pages
Varname: gtcustom_newthreads_header
Text: Latest Threads

3)__ ADD FUNCTION TO functions_gtcustom.php
Copy the following function to functions_gtcustom.php (functions_gtcustom.php is included in GTCUSTOM PAGES product)
PHP Code:
/* ==========[ PRINT LATEST THREAD ]===================================== */
/* ====================================================================== */
function print_gtcustom_newthreads()
{
    global 
$vbulletin$vbphrase$threadrows;
    
    
$threadarray $vbulletin->db->query_read("
        SELECT thread.*, icon.title AS icontitle, icon.iconpath
        FROM " 
TABLE_PREFIX "thread AS thread
        LEFT JOIN " 
TABLE_PREFIX "icon AS icon ON(icon.iconid = thread.iconid)
        WHERE 
            thread.visible = 1
        ORDER BY dateline DESC 
        LIMIT 15"
);
    
    while(
$thread $vbulletin->db->fetch_array($threadarray))
    {
        if (
$thread['iconid'])
        {
            
// get icon from icon cache
            
$thread['iconpath'] = $vbulletin->iconcache["$thread[iconid]"]['iconpath'];
            
$thread['icontitle'] = $vbulletin->iconcache["$thread[iconid]"]['title'];
        }

        if (
$thread['pollid'] != 0)
        {
            
// show poll icon
            
$show['threadicon'] = true;
            
$thread['iconpath'] = "$stylevar[imgdir_misc]/poll_posticon.gif";
            
$thread['icontitle'] = $vbphrase['poll'];
        }
        else if (
$thread['iconpath'])
        {
            
// show specified icon
            
$show['threadicon'] = true;
        }
        else if (!empty(
$vbulletin->options['showdeficon']))
        {
            
// show default icon
            
$show['threadicon'] = true;
            
$thread['iconpath'] = $vbulletin->options['showdeficon'];
            
$thread['icontitle'] = '';
        }
        else
        {
            
// do not show icon
            
$show['threadicon'] = false;
            
$thread['iconpath'] = '';
            
$thread['icontitle'] = '';
        }
        
        
$thread['lastpostdate'] = vbdate($vbulletin->options['dateformat'], $thread['lastpost'], 1);
        
$thread['lastposttime'] = vbdate($vbulletin->options['timeformat'], $thread['lastpost']);
        eval(
'$threadrows .= "' fetch_template('custom_threadrow') . '";');
    }
    unset(
$threadarray);
    return 
$threadrows;

4)__ EDIT goto.php
FIND IN goto.php:
PHP Code:
        default;            
            eval(
'$HTML = "' fetch_template('custom_mypage') . '";'); 
REPLACE WITH:
PHP Code:
        case 'newthreads';
            
$threadrows print_gtcustom_newthreads();            
            eval(
'$HTML = "' fetch_template('custom_thread') . '";');            
            break;
        default;            
            eval(
'$HTML = "' fetch_template('custom_mypage') . '";'); 
FIND:
PHP Code:
if ($_REQUEST['section']=='sitemap')
{
    
$globaltemplates[] = 'custom_sitemap';

REPLACE WITH:
PHP Code:
switch($_REQUEST['section'])
{
    case 
'sitemap';
        
$globaltemplates[] = 'custom_sitemap';
        break;
    case 
'newthreads';
        
$specialtemplates[] = 'iconcache';
        
$globaltemplates array_merge($globaltemplates, array('custom_thread''custom_threadrow'));
        break;

5)__ DONE!
Now, go visit the page that you just created:
$vboptions[bburl]/goto.php?section=newthreads

Need any help? Contact me personally via private message.

NOTE:
  1. All html code is valid XHTML.
  2. This query will display all thread titles regardless of permission settings.
Attached Thumbnails
Click image for larger version
Name:	newthreads.jpg
Views:	2026
Size:	38.1 KB
ID:	43349  
Attached Files
File Type: txt latest_threads_function-1.txt (5.7 KB, 156 views)

vblts.ru supports vBulletin®, 2022-2024