Back to vBulletin 4 Articles

vBulletin 4 Template Syntax: Links
by Marco van Herwaarden 23 Aug 2009

This article was created by http://www.vbulletin.com/forum/member.php?u=224 on vB.com and reposted here with his permission:

In vBulletin 4.0, we will support friendly URL for SEO and readability purposes. At the present, we support member, thread, and forum links. I expect that this list will grow to include albums, etc before the release date. You need to be aware of the new format for outputting these urls.

TEMPLATES

When you wish to use a url in a template the format is as follows:
Code:
{vb:link string, array[, array][, string, string]}
{vb:link [thread|member|forum], $threadinfo[, $pageinfo][, id, title]}
link never changes

The second argument is a string that notifies the system which type of URL is to be output. The valid types are thread, forum, and member

The third argument is an array that contains the id and title, at minimum, of the link to be generated. For thread, this would be threadid and title. For forum this would be forumid and title. For member this would be userid and username.

The fourth argument is an optional array that contains any arguments that are required to be sent along, such as perpage (pp), page (pagenumber), order, and so on.

The simplest forms are:
Code:
{vb:link thread, {vb:raw threadinfo}}
{vb:link forum, {vb:raw foruminfo}}
{vb:link member, {vb:raw userinfo}}
If you have an array containing the id and title but they do not follow the conventional naming conventions, then you may specify their names with the fifth and sixth options. Both must be specified for them to be recognized. For example, you have $post[threadid] and $post[threadtitle] and wish to output a thread url. You would use:
Code:
{vb:link thread, {vb:raw post}, null, 'threadid', 'threadtitle'}
null was specified for the $pageinfo argument array since this example had no arguments.

If you wish to output a url that uses & instead of & for arguments, for javascript, append "|js" to your type argument so that thread becomes thread|js, member becomes member|js. If you wish to not output a sessionhash, in any instance, say for a url in an email, append nosession to the type argument, so that thread becomes thread|nosession

EXAMPLES

To output a link to a post, you could use
HTML Code:
<a href="{vb:link thread, $threadinfo, $pageinfo_lastpost}#post$lastpostinfo[lastpostid]">$threadinfo[title]</a>
$pageinfo_lastpost would appear like:
PHP Code:
$pageinfo_lastpost = array('p' => 1234); 
PHP

When creating a link in the code, use the fetch_seo_url function, which accepts the same arguments.

function fetch_seo_url(string, array, array, string, string)

In fact the {vb:link thread, $threadinfo, $pageinfo} syntax is just replaced with fetch_seo_url() when a template is compiled.

EXAMPLES

Infractions tab of a user's profile
PHP Code:
$linkinfo = array('postuserid' => 123'postusername' => 'freddie');
$pageinfo = array('tab' => 'infractions');
$memberurl fetch_seo_url('member'$linkinfo$pageinfo'postuserid''postusername'); 
Using the mod rewrite output, $memberurl would be /members/123-freddie?tab=infractions

Please be aware of this change and use it as needed in 4.0. Please refer to the code for exact examples if I have just confused you.

vblts.ru supports vBulletin®, 2022-2024