Notifications
Clear all

[Solved] Sticky Topics Order - Simple Layout

9 Posts
6 Users
2 Likes
894 Views
Posts: 19
Topic starter
(@fastertomaster)
Eminent Member
Joined: 4 years ago

Hi team,

Is there a way to make this work: https://wpforo.com/community/general-discussions/sticky-topics-order-updated-function/

For simple (not threaded) forums and sub-forums?

Thanks, A

8 Replies
Posts: 986
Moderator
(@martin)
Support Team
Joined: 8 years ago

Hi @fastertomaster,

There is no a general solution for all places, it depends on the forum layout and the page (home forum list or in forum topic list). Please specify an exact layout and an exact page.

1 Reply
(@fastertomaster)
Joined: 4 years ago

Eminent Member
Posts: 19

Thanks @martin - I'd love to do this for an in-forum topic list using the simplified layout.

I've already got all my IDs and the previous function installed. Just need the tweak to make it work for that view. 🤗

Really appreciate the help!

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

Hi @fastertomaster,

For the Simplified forum layout you can use this code in the current active WordPress theme functions.php file. If you have an active WordPress child theme, you should only use the child theme functions.php file. Once you put this code and saved. Go to Dashboard > Forums > Dashboard and click on the [Delete All Caches] button.

 

function wpforo_custom_sticky_topic_order( $current_object, $wpf_url_parse ){

$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($current_object['template']) ){
if( $current_object['template'] == 'topic' && wpfval($current_object, 'topics') ){
$topics = $current_object['topics'];
$tmp = array(); $ordered = array();
$forumid = $current_object['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);
if(!empty($topics)) $current_object['topics'] = $topics;
}
}
}

return $current_object;
}
add_filter('wpforo_after_init_current_object', 'wpforo_custom_sticky_topic_order', 10, 2);

 

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 should add/edit the row this way:


$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);

 

 

Posts: 19
Topic starter
(@fastertomaster)
Eminent Member
Joined: 4 years ago

Works perfectly. Thank you for the awesome continued support.

Review left on the plugin page:

https://wordpress.org/support/topic/superb-support-77/#new-topic-0

Thank you!

2 Replies
Sofy
 Sofy
Admin
(@sofy)
Joined: 6 years ago

Support Team
Posts: 4233

Thank you for the review fastertomaster.

Robert
Admin
(@robert)
Joined: 8 years ago

Support Team
Posts: 10499

Thank you very much for the nice review! We really appreciate it.

t.niron
Posts: 86
(@t-niron)
Estimable Member
Joined: 4 years ago

Hello,

How do I find topic id and forum id?
 
Thank you

 

1 Reply
Alvina
Moderator
(@alvina)
Joined: 4 years ago

Member
Posts: 1869

@t-niron,

You just need to hover in the "RSS" button to see the forum and topic ID's, see the screenshot below: