PDA

View Full Version : Adding Thread Author to "Find latest posts" Search Results


MarkFL
01-05-2015, 02:32 AM
Hello All,

I help administrate a math help site, and one of our staff has requested that when we go to a user's profile, and click "Find latest posts" that we see the author of each thread listed in the search results. This will be helpful in quickly determining if a nominee for math helper is consistently posting in threads started by other users.

I have attached an image, with the desired added field enclosed in red, to demonstrate what I am wanting to do.

I would be grateful if someone could point me to the PHP file where this information is built...I was thinking it would be search.PHP in the root directory, but looking at that file I don't see where this is done. It seems like this would be a fairly simple thing to add, if I just knew where to begin...:D

John Lester
01-05-2015, 07:53 AM
Perhaps it's because I'm quite tired, but you do realize that the "author" is the person listed after the "by" right?

I'm not sure what you're actually looking for.

MarkFL
01-05-2015, 08:00 AM
Perhaps it's because I'm quite tired, but you do realize that the "author" is the person listed after the "by" right?

I'm not sure what you're actually looking for.

What I mean is the "Author" is the person who started the thread (the author of the first post in the thread, the thread starter), and "By" is the person who wrote the (possibly subsequent in the thread) post, the person whose posts are being retrieved in the search. :D

John Lester
01-05-2015, 08:16 AM
Ah yes, I see what you want to do now. I don't think I can help with this :(

HM666
01-05-2015, 06:09 PM
Have you tried just adding some code to the template instead? There must be code somewhere for then thread starter to just add in that tidbit into the template. possibly something in this template code can help you add this info to your search template:

<div class="threadmeta">
<div class="author">
<vb:if condition="$show['rmanage']">
<span class="rmanage"><a href="{vb:raw $vboptions.vbforum_url}{vb:if "$vboptions['vbforum_url']", '/', ''}postings.php?{vb:raw session.sessionurl}do=editthread&amp;t={vb:raw thread.redirectthreadid}">{vb:rawphrase manage}</a></span>
</vb:if>
<vb:if condition="!$show['detailedtime']">
{vb:rawphrase started_by_x_y_z_a, {vb:link member, {vb:raw thread}, null, 'postuserid', 'postusername'}, {vb:raw thread.postusername}, {vb:raw thread.startdate}, {vb:raw thread.starttime}, {vb:stylevar dirmark}}
<vb:else />
{vb:rawphrase started_by_x_y_z, {vb:link member, {vb:raw thread}, null, 'postuserid', 'postusername'}, {vb:raw thread.postusername}, {vb:raw thread.startdate}, {vb:stylevar dirmark}}
</vb:if>
<vb:if condition="$show['unsubscribe']">
&nbsp; <a href="{vb:raw $vboptions.vbforum_url}{vb:if "$vboptions['vbforum_url']", '/', ''}newreply.php?{vb:raw session.sessionurl}do=newreply&amp;t={vb:raw thread.threadid}" rel="nofollow">{vb:rawphrase reply}</a>
| <a href="{vb:raw $vboptions.vbforum_url}{vb:if "$vboptions['vbforum_url']", '/', ''}subscription.php?{vb:raw session.sessionurl}do=removesubscription&amp;return=uc p&amp;t={vb:raw thread.threadid}" rel="nofollow">{vb:rawphrase unsubscribe}</a>
</vb:if>
<vb:if condition="$thread['pagenav']">
<dl class="pagination" id="pagination_threadbit_{vb:raw thread.realthreadid}">
<dt class="label">{vb:raw thread.totalpages} {vb:rawphrase pages} <span class="separator">&bull;</span></dt>
<dd>
{vb:raw thread.pagenav}
<vb:if condition="$show['pagenavmore']"> <span class="separator">...</span> <span><a href="{vb:raw thread.lastpagelink}">{vb:raw thread.totalpages}</a></span></vb:if>
</dd>
</dl>
</vb:if>
<!-- iconinfo -->
<div class="threaddetails td">
<div class="threaddetailicons">
<vb:if condition="$show['taglist']">
<img src="{vb:stylevar imgdir_misc}/tag.png" alt="{vb:raw thread.taglist}" />
</vb:if>
<vb:if condition="$show['rexpires']">
<img src="{vb:stylevar imgdir_misc}/expires.gif" alt="{vb:rawphrase expires_on_x_y, {vb:raw thread.expiredate}, {vb:raw thread.expiretime}}" />
</vb:if>
<vb:if condition="$show['moderated']">
<img src="{vb:stylevar imgdir_misc}/moderated_small.gif" alt="{vb:rawphrase x_moderated_posts, {vb:raw thread.hiddencount}}" />
</vb:if>
<vb:if condition="$show['deletedthread']">
<img src="{vb:stylevar imgdir_misc}/trashcan_small.gif" alt="{vb:rawphrase x_deleted_posts, {vb:raw thread.deletedcount}}" />
</vb:if>
<vb:if condition="$show['paperclip']">
<a href="javascript://" onclick="attachments({vb:raw thread.threadid}); return false"> <img src="{vb:stylevar imgdir_misc}/paperclip.png" border="0" alt="{vb:rawphrase x_attachments, {vb:raw thread.attach}}" /></a>
</vb:if>
<vb:if condition="$show['subscribed']">
<img src="{vb:stylevar imgdir_misc}/subscribed.png" alt="{vb:rawphrase you_are_subscribed_to_this_thread}" />
</vb:if>
</div>
</div>

The author tag is where that info is in the threadbit.

MarkFL
01-05-2015, 07:47 PM
Yes, my first thought was to modify the "search_resultlist" template, but what I found is that all of the search results information for that query is returned as HTML in {vb:raw searchbits}.

<vb:if condition="$show['results']">
<ol id="searchbits" start="1" class="searchbits">
{vb:raw searchbits}
</ol>
<vb:else />

So, I am assuming this HTML is compiled and generated by PHP code somewhere. I could perhaps write some javascript code to alter this HTML after the fact, but I think it would be more efficient to alter the PHP code generating the HTML instead.

HM666
01-06-2015, 05:01 PM
Try the "search_threadbit" template instead. It may be where you need to edit. Sometimes the vB Raw command is actually calling a template or a portion of a template.

MarkFL
01-06-2015, 05:12 PM
Try the "search_threadbit" template instead. It may be where you need to edit. Sometimes the vB Raw command is actually calling a template or a portion of a template.

Thanks, I did look at that template too, but I believe it is responsible for displaying the thread listing when doing a simple word search or an advanced search. :D

HM666
01-06-2015, 06:13 PM
Ah! ok i see I missed the part about clicking the "Find Posts" in the users profile. Try this template then instead: "search_results_postbit" It is probably the place you need to look. you can put your code to add your author in this bit of code in the template. Just find this code:

<div class="userinfo_noavatar">
<div class="contact">
<div class="username_container">
<h2>{vb:rawphrase thread}: <a href="{vb:link thread, {vb:raw post}, null, 'threadid', 'threadtitle'}" title="{vb:raw post.threadtitle}">{vb:raw post.threadtitle}</a></h2>
<vb:if condition="$post['userid']">
{vb:rawphrase by_x, {vb:link member, {vb:raw post}, null, 'userid', 'username'}, {vb:raw post.username}}
<vb:else />
{vb:rawphrase by_x_guest, {vb:raw post.username}}
</vb:if>
</div>
</div>

and change it with your added author code:

<div class="userinfo_noavatar">
<div class="contact">
<div class="username_container">
<h2>{vb:rawphrase thread}: <a href="{vb:link thread, {vb:raw post}, null, 'threadid', 'threadtitle'}" title="{vb:raw post.threadtitle}">{vb:raw post.threadtitle}</a></h2>
<vb:if condition="$post['userid']">
{vb:rawphrase by_x, {vb:link member, {vb:raw post}, null, 'userid', 'username'}, {vb:raw post.username}}
<vb:else />
{vb:rawphrase by_x_guest, {vb:raw post.username}}
</vb:if>
<div>Author: YOUR AUTHOR CODE HERE</div>

</div>
</div>

I tested it and it should add the info in the proper place. You can see by my screen shot attached.

kh99
01-06-2015, 06:17 PM
OK, create a new plugin using hook location search_results_postbit and this code:
$post['postusername'] = $thread->get_field('postusername');
$post['postuserid'] = $thread->get_field('postuserid');


then edit template search_results_postbit and add something like this (the red part was added:
<vb:if condition="$post['postuserid']">
author <a href="{vb:link member, {vb:raw post}, null, 'userid', 'username'}">{vb:raw post.postusername}</a><br/>
<vb:else />
{vb:rawphrase by_x_guest, {vb:raw post.postusername}}
</vb:if>
<vb:if condition="$post['userid']">
{vb:rawphrase by_x, {vb:link member, {vb:raw post}, null, 'userid', 'username'}, {vb:raw post.username}}
<vb:else />
{vb:rawphrase by_x_guest, {vb:raw post.username}}
</vb:if>

You're no doubt better at html than I am so I just hacked it in there figuring that you could fix it. ETA: ...or use what Len posted above.

Also if you want you could create phrases and use them like the "by" section does.

Edit: oh, I just re-read your first post. I probably should just have told you that you want to look at packages/vbforum/search/result/post.php and let you handle the rest.

MarkFL
01-06-2015, 07:16 PM
I couldn't "like" Len's post until I like others...but I really appreciate both posts immensely, and when I am free tonight, will dive into this and post my results. :D

HM666
01-06-2015, 07:34 PM
Hope it helps and you are able to accomplish what you need with all your hair intact lol. :)

MarkFL
01-06-2015, 10:18 PM
OK, create a new plugin...

I followed your advice, making a slight change to the suggested template edit, and got exactly what I wanted.

This is the template edit I used:

<div class="username_container">
<h2>{vb:rawphrase thread}: <a href="{vb:link thread, {vb:raw post}, null, 'threadid', 'threadtitle'}" title="{vb:raw post.threadtitle}">{vb:raw post.threadtitle}</a></h2>
<vb:if condition="$post['postuserid']">
Thread started by <a href="{vb:link member, {vb:raw post}, null, 'postuserid', 'postusername'}">{vb:raw post.postusername}</a><br/>
<vb:else />
{vb:rawphrase by_x_guest, {vb:raw post.postusername}}
</vb:if>
<vb:if condition="$post['userid']">
Post {vb:rawphrase by_x, {vb:link member, {vb:raw post}, null, 'userid', 'username'}, {vb:raw post.username}}
<vb:else />
{vb:rawphrase by_x_guest, {vb:raw post.username}}
</vb:if>
</div>


The part in red is what I added...and I have attached an image of the result.

I thank both of you for your time and help. :cool:

ozzy47
01-06-2015, 10:20 PM
Excellent, thanks for sharing the final results. :)

HM666
01-06-2015, 10:37 PM
Awesome! Glad you got it sorted.

John Lester
01-07-2015, 03:38 AM
Now that I see it, I really like it :) Thanks for sharing what worked, I'll probably be using it myself sooner or later :D