MyBB Hacks

Full Version: Is this possible? Displaying threads on index with x criteria
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3
Hi everyone,

So, here is a rough mock-up of my index page concept. I want to call your attention to the "Hottest Brands" box.

[Image: wf6fJ.jpg]

The Brand Directory is a forum using xThreads.

Here are the things I would like to do.
  • Display three threads from Brands forum on index in this box
  • Have these threads ordered based on # of replies in previous [x] days
  • Display rank image of 1st, 2nd, and 3rd next to each of them (optional but desired)
  • Fetch thumbnail with exact dimensions to display with thread
  • Short description and tags are custom thread fields

It seems that RateU has accomplished pretty much exactly what I want already, except he using views as the selection method.

[Image: JFHl1.png]

I would greatly appreciate your guidance.
I suppose yes, RateU shared a file with the funtions to pull thread from x forum, you could read it and fit it to your needs (IDK in what thread he shared it).
I think that the sticking point is going to be the number of replies in X days Brad. As far as I know, MYBB stores the replies data in the threads table without a date range on the replies. You would have to make a plugin or something that calculated that for you.
(05-10-2012 08:26 PM)leefish Wrote: [ -> ]I think that the sticking point is going to be the number of replies in X days Brad. As far as I know, MYBB stores the replies data in the threads table without a date range on the replies. You would have to make a plugin or something that calculated that for you.

I'd be willing to pay someone to do this if you know anyone. Smile
Brad, if I knew HOW I would make it for you for free. Sadly, I do not. It can be done by querying the posts table, but that would need a cache of some sort as you are putting it on your index page, and I am failing miserably at caching. I just can't get it to work.

Maybe RateU or Sama34 could have a go at it for you (if they want to).
I'll try to make it a bit general (hopefully). We use XThreads functions here, (the hard things is done by XThreads Biggrin), so maybe we can use it for other XThreads applications.

Try this (attached - modify it as our needs).
Edit the file, find and and modify the value:

PHP Code:
$forumid = 2;
$xdays = 10;
$tlimit = 3;

Edit mnxt_mrtxpd_threads and/or mnxt_mrtxpd_threads_thread templates as our needs.

By default, we can find thread subject inside the mnxt_mrtxpd_threads_thread.
Use {$thread['profilelink']} for thread author username (linked to profile).

In the template, we can use {$threadfields['key']} for non attachments fields (description, category and etc), and {$threadfields['key']['item']} for attachments fields (image and/or files).

We can use something like this if we want the thumbnail displayed in the side box has a different size with the thumbnail displayed in threadlist/showthread:

HTML Code
<a href="{$thread['threadlink']}"><img src="{$threadfields['key']['thumbs']['thumbnail_size']['url']}" alt="{$thread['subject']} Preview" title="{$thread['subject']}" width="{$threadfields['key']['thumbs']['thumbnail_size']['w']}" height="{$threadfields['key']['thumbs']['thumbnail_size']['h']}" /></a>

Modify it as our needs, depends on the Key for our image custom fields. And make sure that the thumbnail size is in our Image Thumbnail Generation list settings (or we can add it there, and run the Rebuild XThreads Attachment Thumbnails tools).

{$forumurl_q} followed by filtertf_key will lead us to the forumdisplay (filtered).

Use {$thread['rank']} for the rank.
If we want to use image for the rank, we can use it something like this:

HTML Code
<img src="images/hottest_threads_{$thraed['rank']}.png" alt="" />

Then upload hottest_threads_1.png, hottest_threads_2.png, hottest_threads_3.png and etc, depends on the limit, where 1 is the hottest threads.

Please tell me if there is something wrong with the code. I'm still learning.

whoa- that was fast. You know what I am going to ask, right? How to make this for multiple forum ids.....?

I looked in the code, I see this line:

Code:
WHERE t.fid='.intval($forumid).' AND t.visible=1 AND t.closed NOT LIKE "moved|%" AND p.visible=1 AND t.replies>0 AND p.dateline>'.$cutdate.' AND p.pid!=t.firstpost


If I was to make the fid variable a comma separated list and changed the line in the query as below, would that also work?

Code:
if(is_array(explode(',', $forumid])))
		{
			foreach(explode(',', $forumid']) as $forum_fid)
			{
				$forum_fid_array[] = intval($forum_fid);
			}
		}
if(!empty($threadfieldscache)){
		$xtfields = '';
		foreach($threadfieldscache as &$tf){
			$xtfields .= ',tf.'.$tf['field'].' AS xthreads_'.$tf['field'];
		}
	}
	$query = $db->query('SELECT COUNT(p.pid) as posts,t.tid,t.fid,t.subject,t.username as threadusername,u.username,u.usergroup,u.displaygroup'.$xtfields.'
		FROM '.TABLE_PREFIX.'threads t
		LEFT JOIN '.TABLE_PREFIX.'threadfields_data tf ON(tf.tid=t.tid)
		LEFT JOIN '.TABLE_PREFIX.'posts p ON(p.tid=t.tid)
		LEFT JOIN '.TABLE_PREFIX.'users u ON(u.uid=t.uid)
		WHERE t.fid IN ('".implode("','", $forum_fid_array)."') AND t.visible=1 AND t.closed NOT LIKE "moved|%" AND p.visible=1 AND t.replies>0 AND p.dateline>'.$cutdate.' AND p.pid!=t.firstpost
		GROUP BY p.tid
		ORDER BY posts desc
		LIMIT 0,'.intval($tlimit).'
	');

I think we need to check whether a forum available for a user or not.
The plugin posted in this post is for multiple forum, Lee:
http://mybbhacks.zingaburga.com/showthre...http://mybbhacks.zingaburga.com/showthread.php?tid=531&pid=1096
We only need to change the query. It has similar method, but we need to use global threadfields cache.
Another question - we are using the threadfields cache - so does that mean that if there is no change to the query then there will no hits on the db on page reload?

Editing to add - actually, the forums I want to use in the query are already viewable by all, except for banned users, so I could just say if banned - return you are banned (or something). So I will try it with this one.
Incredible, it works! Thank you!
Pages: 1 2 3
Reference URL's