PDA

View Full Version : Create "Latest Threads" Custom Page


Princeton
23 Feb 2006, 20:57
A simple [HOWTO] to display latest threads on a custom page.

If you don't have GTCUSTOM PAGES (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:
create 2 templates
add 1 phrase
add function to functions_gtcustom.php
edit goto.php
visit page at $vboptions/goto.php?section=newthreads

[B]1)__ CREATE 2 TEMPLATES
Create "custom_thread" template:

<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:
<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)
/* ==========[ 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:
default;
eval('$HTML = "' . fetch_template('custom_mypage') . '";');

REPLACE WITH:
case 'newthreads';
$threadrows = print_gtcustom_newthreads();
eval('$HTML = "' . fetch_template('custom_thread') . '";');
break;
default;
eval('$HTML = "' . fetch_template('custom_mypage') . '";');

FIND:
if ($_REQUEST['section']=='sitemap')
{
$globaltemplates[] = 'custom_sitemap';
}
REPLACE WITH:
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:
All html code is valid XHTML.
This query will display all thread titles regardless of permission settings.

hiiped
24 Feb 2006, 00:51
nice work

thanks

Princeton
24 Feb 2006, 02:26
thanks for the feedback :up:

Clayton
27 Feb 2006, 20:07
hi princeton

some great work going on here

i would like to the latest threads from one website[domain] and display it on another domain, would it be possible to do it with this hack, please?

thank you

C

Princeton
27 Feb 2006, 23:31
try xml/rss/javascript syndication:
http://www.vbulletin.com/docs/html/vboptions_group_external

justindwhite
03 Mar 2006, 00:18
Whats the best way to put the:
"$vboptions[bburl]/goto.php?section=newthreads" on your non vb page?

I've tried using iframe as you can see on http://www.h2survivor.com, but when you click on a link it loads in the iframe. Anyone know a better way to do this or fix the iframe problem?

Also, I notice on the preview image that all the posts say 7:00PM. On my site, it also has every post as being posted at 7:00PM. I can't seem to figure this out on my own.

Princeton
03 Mar 2006, 03:27
I made some changes..

IN gtcustom_threadrow replace
$thread[lastpost]
with
$thread[lastpostdate]

in the print_gtcustom_newthreads() replace
$thread['lastpost'] = vbdate($vbulletin->options['dateformat'], $thread['lastpost'], 1);
with
$thread['lastpostdate'] = vbdate($vbulletin->options['dateformat'], $thread['lastpost'], 1);

regarding the iframe ...
add a target attribute to your link ie. target="new"

Clayton
03 Mar 2006, 08:13
thanks princeton

will wait a little longer to see the different changes and then attempt to create the page with the forum threads on

Thank you

C

theguywhoknowz
14 Mar 2006, 23:24
Ok so i was sucessful add the latest thread into a custom php page, but i resize the table, and the thread title is too long, it wrap down, is there a way that it only show the first 10 characters and the rest is "..." without wraping the text to the next line?

Princeton
15 Mar 2006, 13:57
try fetch_word_wrapped_string($title, $limit) (http://members.vbulletin.com/api/vBulletin/_includes_functions_php.html#functionfetch_word_wrapped_string)

theguywhoknowz
18 Mar 2006, 00:11
K thanks but what if I want to show only 3,4 thread on the lastest thread, not 15 of them, how do i reduce the number of thread shown?

Princeton
18 Mar 2006, 16:19
edit this line
LIMIT 15to
LIMIT 4

theguywhoknowz
20 Mar 2006, 18:17
thank you, princton, it works liek a champ, now the problem is, what if i want to change the font and style on that custom thread page, cause it use the forum css and it is bigger than my custom page font and size, is there a way?

theguywhoknowz
21 Mar 2006, 22:13
Nvm, i got this.

ChrisBaktis
26 Mar 2006, 16:38
Im looking to use something like this but instead of threads I would like to list members in order of the highest number in a custom profile field....I run a trading site and each time a member makes a trade we add 1 point to a custom profile field...I want to start from highest to lowest and list the member and how many trades they have. Would this work and if so what would I need to change?

Princeton
01 May 2006, 16:40
Im looking to use something like this but instead of threads I would like to list members in order of the highest number in a custom profile field....I run a trading site and each time a member makes a trade we add 1 point to a custom profile field...I want to start from highest to lowest and list the member and how many trades they have. Would this work and if so what would I need to change?
hi ChrisBaktis,
You will need to create the function and queries to do this ... once you have that you can add it to the GTCUSTOM PAGE product.

Kriminal
23 May 2006, 23:44
Thanks!
Could you help me to add a column with the forum name where the threads belongs?

theguywhoknowz
30 May 2006, 21:26
How do I have the hot topic thread to show or most active usersname instead of recent threads?

Angeleyes
05 Jun 2006, 00:31
I have a "back room" on my pet forum where we discuss board/moderator issues. This will show those threads? Is there anyway to eliminate that?

Princeton
05 Jun 2006, 00:35
you will have to edit the script to fetch rows based on permissions

Coach_Guru
09 Aug 2006, 23:27
Any method to show threads from x to y and for a specific forum?

i.e for an hypothetical "test forum" show threads from 1 to 50 and so on.

Thanks a lot.

Princeton
12 Aug 2006, 16:26
you can query the specific forum ...

WHERE thread.visible = 1 AND thread.forumid = 50
LIMIT 0, 50

valdet
27 Dec 2007, 20:10
Sorry to bump this old article, but this is a perfect find. I will look into this more..

Powerofdreams
01 Mar 2008, 21:33
Hi

Very good hack.But how can I add lastest 5 thread under similar thead? Thank you :)

cowcowcow
25 Sep 2011, 23:39
Hey Princeton!

I know you wrote this like 5 years ago so i know its a longshot anyway but im hoping you will reply :)

Basically im wondering if you know of a way i could create forums for my custom page page area which im currently using for clans.


I've worked out the custom page part, now i just want to give clans hosted on the site their own forums integrated with that page. Ideally on the right side i want to use something like $displayclanfourmX and the forum just gets displayed and the layout is retained. Sounds overly simplistic in idea, is that possible? haha

Let me know! Thanks :)

bond010007
21 Jan 2012, 23:39
I was looking for that thanks :)

Pcwolfx
12 Mar 2012, 12:43
didn't seem icons. :(