View Full Version : vBulletin 4 Template Syntax: Links

Marco van Herwaarden
23 Aug 2009, 16:35
This article was created by Freddie Bingham (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.


When you wish to use a url in a template the format is as follows:
{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:
{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:
{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


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

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.


Infractions tab of a user's profile
$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.

23 Aug 2009, 16:40
Thanks. I remember having that seen before, but I did not remember where.

The mod I have converted mainly has links to groups. In the quote linked by Dismounted Freddie hints that he expects that other forms of content would be added as development progresses. I'll ask over at .com whether that is indeed the case (or has anyone already done so?).

Ok, I just tried coming to grips with the linking function trying with the one link (to a members profile) that is eligible in this mod. So I totally failed with that. Looking at the code did'nt help me here, either. Perhaps anyone would be willing to enlighten me?

What I have is the username and the userid in an array that contains more data.
$example['usernane'] and $example['userid']. What would the code have to look like if I wanted to that users profile?

23 Aug 2009, 18:28
$url = fetch_seo_url('member', $example);

Easy, eh? ;)

23 Aug 2009, 19:19
Ah - just not as easy :o

What messed me up so badly was the mixup of the new link method and the new way to pass variables to phrases, although thats pretty straightforward - once one sees through it.

What I needed was:
{vb:rawphrase by_x {vb:link member, {vb:raw example}, null, 'lastposterid', 'lastposter'}, {vb:var example.lastposter}}

04 Sep 2012, 22:11
Hello, I'm having a trouble.

I'm currently using vBulletin 4.2, and I want to generate a template link to a generic post (it depends on the post)...

So, I use this code (that I get from postbit template):

{vb:link thread, {vb:raw thread}, {vb:raw pageinfo_post}}#post{vb:raw post.postid}

However, the generated link is:


Where X is the thread id and YYY is the post id, but, the link should be something like:


Anyone knows what could it be?

Thanks in advance =D...

04 Sep 2012, 22:55
What template are you adding that to? If it's not a postbit template, then probably the issue us that pageinfo_post is not available there.

05 Sep 2012, 13:15
Is a plugin that is added to the user info... Is for giving Like / Dislikes to posts...

That must be it... Is there another way to get the post link then?..

Thank You for your time by the way =D...

05 Sep 2012, 13:59
Well, if you have a plugin I think you can just create your own array and register it to your template, like:
$pageinfo_post = array(
'p' => $postid

Of course I don't know if $postbit is the right variable, but you can change that to whatever you need.

Then if your plugin is rendering the template, call register('pageinfo_post', $pageinfo_post) before the call to render(). If you're putting that in an exitsing template, then you need ti call preRegister instead, like
vB_Template::preRegister('template_name', array('pageinfo_post' => $pageinfo_post));

18 Nov 2012, 22:36
Do someone knows how to get the link to someones user's profile picture?? I am trying to do a widget that shows the picture of the logged in user with a hello message... but cannot find how to display the user's avatar or profile picture.