Notifications
Clear all

[Solved] Sticky Topics Order - Need them in a certain order, regardless of current posts

11 Posts
4 Users
2 Likes
2,891 Views
Posts: 52
Topic starter
(@thedrawingboard)
Trusted Member
Joined: 5 years ago

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!

10 Replies
Robert
Posts: 10499
Admin
(@robert)
Support Team
Joined: 8 years ago

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:

 

5 Replies
VereK
(@verek)
Joined: 6 years ago

Honorable Member
Posts: 495

This code no longer functions since the 1.6 update.

Robert
Admin
(@robert)
Joined: 8 years ago

Support Team
Posts: 10499

Where exactly? On Forum page or on Topics page?

Have you deleted wpForo cache in Dashboard > Forums > Dashboard admin page before checking? Check this post please: https://wpforo.com/community/general-discussions/sticky-posts-need-them-in-a-certain-order-regardless-of-current-posts/#post-21543

VereK
(@verek)
Joined: 6 years ago

Honorable Member
Posts: 495

Forums.

(@fastertomaster)
Joined: 4 years ago

Eminent Member
Posts: 19

Hey @robert - was there ever a fix for this code? It's also not working for me.

In the access details you already have for my staging site forum [32] (Stop Working Harder) should be organised as per the rules in the functions.php but it doesn't seem to work.

Clearing the cache's isn't effective.

Thanks!

Robert
Admin
(@robert)
Joined: 8 years ago

Support Team
Posts: 10499

@fastertomaster,

We just tested and all works fine. You should navigate to Dashboard > Forums > Dashboard and click on [Delete all caches] button. Also, please delete website cache. I'm sure you're adding wrong IDs or you've not deleted the wpForo cache. Please provide more information in your separate topic, this topic is closed.

Posts: 52
Topic starter
(@thedrawingboard)
Trusted Member
Joined: 5 years ago

Thank you, Robert!!!

This is VERY helpful to me, and I sincerely appreciate your support.

Off to fix my sticky posts. 🙂 

Thanks again.

Cheers!

Posts: 52
Topic starter
(@thedrawingboard)
Trusted Member
Joined: 5 years ago

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!

Robert
Posts: 10499
Admin
(@robert)
Support Team
Joined: 8 years ago

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.

Page 1 / 2