Linked Post Numbering in Phpbb3
Posted March 15th 2012, 3:30am
It was brought up in this topic: viewtopic.php?p=12106#p12106
About Numbered posts, with reference links.

This is actually a very easy modification to make, because it requires no working out of the post number, as the viewtopic.php file already does the hard work. We just need to make it a link and put it to use. ;)

To make the modification open up the file 'viewtopic.php' which you should find within your PHPBB root path.

Find this line (round about line 1580):
'POST_NUMBER' => $i + $start + 1,

This is the line in which the post number is calculated and set in the template class.

Now simply change that line to this:
'POST_NUMBER' => '<a href="'.$viewtopic_url.'#p'.$row['post_id'].'">#'.($i + $start + 1).'</a>',

*The comma at the end is very important

That has now added the HTML for the post number to be a link. It contains an anchor, that when that link is visited, the user will be taken down the page to the post.

Your not quite finished though, it needs to be included in the templagte in order to be displayed on the page.

So visit your style path, and look in the templates directory for the file 'viewtopic_body.html' and open it up.

Round about line 170 you'll see this:
<dl class="postprofile" id="profile{postrow.POST_ID}">
<dt>

Underneath the '<dt>' line add this:
<div class="postnumber">{postrow.POST_NUMBER}</div>

(add it anywhere in the post if you know what your doing)

Save the two files, and upload them.

You'll now have a linked post number on every post. If it doesn't show up, clear the cache directory.

You can/should style it in the CSS with the classname of 'postnumber'.
I'd strongly recommend adding 'float:right' to it, unless it will just look out of place.

AKA:
.postnumber {
float: right;
}
φ
Posts: 509
Joined: July 9th 2011, 11:00pm
Location: England
Likes Given: 15
Likes Received: 26
Linked Post Numbering in Phpbb3
Posted March 15th 2012, 12:43pm
Adding the following to the viewtopic_body.html template will also work:

<div class="postnumber">
<a href="{ROOT_PATH}viewtopic.php?p={postrow.POST_ID}#p{postrow.POST_ID}">#{postrow.POST_NUMBER}</a>
</div>

This has the advantage of not requiring changes to the [ic]viewtopic.php[/ic] file.

Hmm...this gives me an idea for another topic!
φ
Posts: 1600
Joined: March 12th 2009, 11:00pm
Location: Uncertain due to momentum
Likes Given: 26
Likes Received: 357
Linked Post Numbering in Phpbb3
Posted April 12th 2015, 9:41pm
Does this work for the subsilver2 style I cant find the code in the viewtopic_body.html file.

<dl class="postprofile" id="profile{postrow.POST_ID}">
<dt>
φ
Posts: 8
Joined: April 11th 2015, 8:31pm
Linked Post Numbering in Phpbb3
Posted April 12th 2015, 10:41pm
For subsilver2, I would find this in viewtopic_body.html:

<th>{L_MESSAGE}</th>

and change it to:

<th><a style="float:right" href="{ROOT_PATH}viewtopic.php?p={postrow.POST_ID}#p{postrow.POST_ID}">#{postrow.POST_NUMBER}</a>{L_MESSAGE}</th>
φ
Posts: 1600
Joined: March 12th 2009, 11:00pm
Location: Uncertain due to momentum
Likes Given: 26
Likes Received: 357
Linked Post Numbering in Phpbb3
Posted April 13th 2015, 1:06pm
Dion said:
For subsilver2, I would find this in viewtopic_body.html:

<th>{L_MESSAGE}</th>

and change it to:

<th><a style="float:right" href="{ROOT_PATH}viewtopic.php?p={postrow.POST_ID}#p{postrow.POST_ID}">#{postrow.POST_NUMBER}</a>{L_MESSAGE}</th>


That added a # to the left of the word "Message" in in the center of the top bar of the first post in the thread, it was a link then when I clicked on it, it then took me to what appeared to be a random post in the same thread no other post in the same thread had any # or numbers.

Does my description make sense?

I restored the original files then Purged the cache, awaiting further instructions.

Thanks again.
φ
Posts: 8
Joined: April 11th 2015, 8:31pm
Linked Post Numbering in Phpbb3
Posted April 13th 2015, 4:06pm
Sorry, since I neither use nor recommend subsilver2 to anyone, this was the first time I had looked at that style in more than two years. I'll try again. Find the following:

<b>{L_POSTED}:</b> {postrow.POST_DATE}nbsp;

Change it to:

<b>{L_POSTED}:</b> {postrow.POST_DATE}nbsp;nbsp;nbsp;<a href="{ROOT_PATH}viewtopic.php?p={postrow.POST_ID}#p{postrow.POST_ID}"><b>#{postrow.POST_NUMBER}</b></a>nbsp;

Make sure to add a & character to the start of each nbsp; block. That is a non-breaking space which cannot be displayed properly in code blocks.
φ
Posts: 1600
Joined: March 12th 2009, 11:00pm
Location: Uncertain due to momentum
Likes Given: 26
Likes Received: 357

Who is online

Users browsing this forum: No registered users and 1 guest