I really am loving getting started with wpForo, but I have to say - the sticky posts are driving me NUTS!
I need the sticky posts to STAY in a certain order, regardless of whether or not there are current posts.
For example, I have a Workshop Forum. I need the first sticky post to introduce the workshop, and then each following sticky post to announce the next step, then the next step, etc.
I've been posting the LAST topic first, working my way to what I want to be the FIRST sticky post, and that works - UNTIL someone posts within that forum! Then the sticky post with the current post goes back to the top position - completely messing up the order of the sticky posts as they need to be.
Is there ANY WAY to:
- For an Admin to rearrange sticky posts after they've been posted, so they STAY in the order needed?
- If not, is there a way to make the sticky posts at least STAY in the order we need them (even if we have to post the last sticky post first, so that the last post we do becomes the first in the list)?
I really hope this is something that can be done!!!
Thank you!
Hi @thedrawingboard,
The only way to order sticky topics is using custom function. Please put this code in current activate theme functions.php file. There is a good instruction How to Easily Add Custom Code in WordPress (without Breaking Your Site).
function custom_order_sticky_topics( $topics ) {
$rules = array();
//$rules[ ForumID ] = array( First TopicID, Second TopicID );
$rules[4] = array(19, 6);
$rules[7] = array(26, 63, 68);
if( function_exists('WPF') && isset(WPF()->current_object['template']) ){
if( WPF()->current_object['template'] == 'forum' || WPF()->current_object['template'] == 'topic' ){
$tmp = array(); $ordered = array();
if( empty($topics) || !isset($topics[0]['forumid']) || isset($topics[0]['permissions']) ){ return $topics; } else { $forumid = $topics[0]['forumid']; }
if( !empty( $rules ) && isset( $rules[$forumid] ) ){
foreach( $topics as $key => $topic ){ if( isset($topic['topicid'])) { $tmp[$topic['topicid']] = $topic; } }
if( !empty($tmp) ){ foreach( $rules[$forumid] as $topicid ){ if( isset($tmp[$topicid]) ) { $ordered[] = $tmp[$topicid]; unset($tmp[$topicid]); } } }
$topics = array_merge($ordered, $tmp);
$topics = array_values($topics);
}
}
}
return $topics;
}
add_filter( 'wpforo_get_topics', 'custom_order_sticky_topics', 20);
This is the part where you should edit and change forum/topic IDs. For example you want to set topicid 19 first, then topicid 6 second in forumid 4 you add/edit the row:
$rules[4] = array(19, 6);
If you don't have other forums where you want to add sticky topic ordering rules just remove the second line. I added this to show you can add as much $rules as you want:
$rules[7] = array(26, 63, 68);
Forum IDs can bi found in Dashboard > Forums > Forums admin page or in RSS Link
TopicIDs can be found in Topic Page's RSS link
Note: once the custom function is added in your theme functions.php file please navigate to Dashboard > Forums > Dashboard and click on [Delete all caches] button. Also, please delete website cache.
This is only designed for the Threaded Layout home page. The screen where you see threaded layout recent topics. It may also work for the Extended layout home page, but it's not tested yet. So please use this only for the threaded layout home page:
Thank you, Robert!!!
This is VERY helpful to me, and I sincerely appreciate your support.
Off to fix my sticky posts. 🙂
Thanks again.
Cheers!
Something interesting...
I added the code provided and the sticky posts are now showing up in the order I need them to be in, but only when you are viewing just the actual forum.
For example, I am using the Extended layout.
On the Home page of the Forum, I can see each Forum with the Topics listed below the Forum. In this topics list, the sticky posts are NOT in the order that I entered in the code.
However, if I click on the Forum title to go into that page (viewing just that Forum), THEN the sticky posts are in the order that I entered them in the code.
I thought this might be a cache issue, but I tried viewing the Forum in several different browser and I am seeing the same thing happening - where the Home page lists the sticky topics chronologically, and the actual Forum page lists them in the order set by the code.
@Robert - is this by design? Or do I need to change the code somewhere else, as well?
Thanks again!
It works for all pages. Just navigate to Dashboard > Forums > Dashboard admin page and click on [Delete all caches]. Then Delete your website cache and check it again.
In any case please leave your forum URL to understand what is your forum hierarchy. On the forum home page if you have sub-forums under one forum and all they have sticky topics this will not sort. In other cases it works fine on forum list as well as in topic list.