depends on how you define complicated – solutions are frequently only a few lines of code, but getting there takes the time 🙂
you need to pick up the forum id
so
$forum_id = bbp_get_forum_id();
if (( $forum_id == 123) or ( $forum_id == 456)){
etc…
and then you would add the
Custom action hook to add in the template file where the div shall be displayed:
<?php do_action( 'different_div' ); ?>
in the appropriate forum template
Hi, I’m so sorry for not responding I thought the thread was closed but yes now it is using the shortcode.
Hi Robin. Yes, you have a good point. My functions.php file is filling up with these and it’s making no difference on load times. TBH I’m not sure how I would edit the above function to pull the correct forum ID as this one seems to deal with topic ID instead. Does it treat topic ID and forum ID as the same? As in, can I just change the ID number within this part:
if (( $topic_id == 123)
Exactly I think this code:
function my_custom_display_topic_index_query () {
global $_GET;
if($_GET[‘myOrderBy’])$myOrderBy=$_GET[‘myOrderBy’];else $myOrderBy=’last_edited’;
if($_GET[‘myOrder’])$myOrder=$_GET[‘myOrder’];else $myOrder=’DESC’;
$args[‘orderby’] = $myOrderBy;
$args[‘order’] = $myOrder;
return $args;
}
add_filter(‘bbp_before_has_topics_parse_args’, ‘my_custom_display_topic_index_query’ );
function printSelections(){
global $_SERVER;
return ‘<div class=”queries”><form action=”https://’ . $_SERVER[‘HTTP_HOST’] . $_SERVER[‘REQUEST_URI’].'”><table class=”querytable”><tr><td><select name=”myOrderBy”><option value=”post_modified”>Viimeisin muutos</option><option value=”post_date”>Luontipäivä</option><option value=”post_title”>Nimi/option><option value=”post_author”>Tekijä/option></select></td><td><input name=”myOrder” type=”radio” value=”DESC” />Laskeva</td><td><input name=”myOrder” type=”radio” value=”ASC” />Nouseva</td></tr></table></form>’;
}
add_shortcode( ‘printSelections’, ‘printSelections’ );
// Add do_shortcode(‘printSelections’); to loop-forums.php
<li class=”bbp-header”>
<ul class=”forum-titles”>
<li class=”bbp-forum-info”><?php _e( ‘Forum’, ‘bbpress’ ); ?><?php topPostLinksEcho(); ?>
<li class=”bbp-forum-topic-count”><?php _e( ‘Topics’, ‘bbpress’ ); ?>
<li class=”bbp-forum-reply-count”><?php bbp_show_lead_topic() ? _e( ‘Replies’, ‘bbpress’ ) : _e( ‘Posts’, ‘bbpress’ ); ?>
<li class=”bbp-forum-freshness”><?php _e( ‘Freshness’, ‘bbpress’ ); ?>
<?php do_shortcode(‘[printSelections]’); ?>
given the speed of most servers, I doubt that you would notice any time delay in processing the code in is a few lines of many thousand that get processed on each page load and one DB call.
best solution would be to time with and without and see if you can spot anything – but run it many times to get an average
In single-loop-forum.php I want to style my first forum differently to the rest by removing the voices/topics/freshness columns. As it happens this forum is only visible to non-logged in users by using this code:
.logged-in #bbp-forum-40250 {
display: none;
}
I found this code here:
/*Different divs for all topics of specific forums*/
function add_different_div() {
$topic_id = bbp_get_topic_forum_id();
if (( $topic_id == 123) or ( $topic_id == 456)){
?>
<div> this is some custom div text </div>
<?php
}
elseif ( $topic_id == 789){?>
<div> this is some OTHER custom div text </div>
<?php
}}
add_action( 'different_div', 'add_different_div' );
… but creating a function seems overkill. I think I just need an if() statement that says ‘if this forum ID then style it this way; else…’.
Any pointers?
Thanks.
I just too would like to add 1-3 buttons to the forum topics listing in order to change the default order. I would code it to changed template, if I would know what functions to use.
Just a note to everyone who might find this. It’s been more than 4 years, and this code still works great.
For anyone looking to add signatures on BuddyBoss Platform instead of bbPress/BuddyPress, this works too.
How do I get bbPress to return to the same page when someone presses Favorite from within the Bbpress single topic shortcode?
I want to avoid the redirect to the topic page after pressing the Favorite link.
Hi All !!
I have upgraded phpBB 3.0.4 to 3.2.8 recently following steps on Upgrading from 3.0 to 3.2
When trying to import to bbpress 2.5.4 on a WP 5.2.3 I get this message:
Error en la base de datos de WordPress: [Unknown column 'forums.forum_topics' in 'field list']
SELECT convert(forums.forum_id USING "utf8mb4") AS forum_id,convert(forums.parent_id USING "utf8mb4") AS parent_id,convert(forums.forum_topics USING "utf8mb4") AS forum_topics,convert(forums.forum_posts USING "utf8mb4") AS forum_posts,convert(forums.forum_topics_real USING "utf8mb4") AS forum_topics_real,convert(forums.forum_name USING "utf8mb4") AS forum_name,convert(forums.forum_desc USING "utf8mb4") AS forum_desc,convert(forums.left_id USING "utf8mb4") AS left_id,convert(forums.forum_type USING "utf8mb4") AS forum_type,convert(forums.forum_status USING "utf8mb4") AS forum_status FROM phpbb_forums AS forums LIMIT 0, 100
No hay foros que convertir
No hay datos que limpiar
Effectively column forum_topics was on table forum in phpbb version 3.0.4 but it is not anymore on phpbb version 3.2.8.
Script to import from phpbb must have a bug or expect a different database structure for phpbb.
Any suggestions?
Thanks in advance
@casiepa yes I mean that… but the guy mentions that that code is not working 😛
Can someone else confirm that importing a post where the content contains brackets [] causes the custom importer to hang (get stuck actually)?
Related post
Hello all,
I am using BuddyPress with bbPress and I am noticing an issue when I have a forum topic with multiple pages. When I add a new reply it creates a BuddyPress activity that stores in the DB a primary_link of the type /forums/topic/topic-name/page/XX/#post-YYYY. For example /forums/topic/test-notification-for-reply/page/2/#post-3063
The problem is that if I delete some previous replies from page 1 and this reply moves to the first page from the second page it was previously, its activity permalink (primary_link) remains the same and the activity still points to page 2 of the topic (not page 1 that is its new page).
Is there any fix for this?
OK, I think I have solved this by following this thread, except I had to do one thing the other way around…
1. Scrap User Role Editor and install the Members plugin by Justin Tadlock
2. Don’t put anything in your functions file
3. In WordPress under Users/Roles, clone the Participant user role and give it a name and slug (in my case I am using ‘bosun’) and save the new role.
4. Add this code to your functions file:
function vip_add_custom_role( $bbp_roles ) {
$bbp_roles['bosun'] = array(
'name' => 'Bosun',
'capabilities' => bbp_get_caps_for_role( bbp_get_participant_role() ) // the same capabilities as participants
);
return $bbp_roles;
}
add_filter( 'bbp_get_dynamic_roles', 'vip_add_custom_role', 1 );
… where bbp_roles and name is changed to your own name of the user role. This must be the same as the name/slug you inserted when cloning the participant user role.
5. Now any forum user assigned this user role will display the correct role, rather that ‘participant’ ‘subscriber’ or ‘spectator’.
The thing I had to do the other way around from the instructions in the other thread was to not put anything in the functions file and install the plugin first.
Phew. Took me two days to get there!
Hi,
I attempted to create some new bbp roles using the code in the codex to copy the ‘participant’ role. Unfortunately this did not work for me despite deactivating all plugins (seems quite a few other people had the same issue).
Instead I am using User Role Editor to create a new forum role, which I have called ‘bosun’. Upon sign-up a new user is correctly assigned this role and has the capabilities of a participant, which is great, but their forum role is still displaying as ‘spectator’.
I would like to display the user’s role under the avatar.
One thing I can do is display:none the div class bbp-author-role and then add in a new div to display the user_role, which I think is what URE plugin generates.
I appreciate that some of this has to do with the URE plugin and that it is not supported here. What I am trying to understand is what I need to change in order to hide the bbp-author-role div and add in a new div calling the URE role. I can only find references to bbp-author-role in templates.php which is a function:
function bbp_topic_author_role( $args = array() ) {
echo bbp_get_topic_author_role( $args );
}
/**
* Return the topic author role
*
* @since bbPress (r3860)
*
* @param array $args Optional.
* @uses bbp_get_topic_id() To get the topic id
* @uses bbp_get_user_display_role() To get the user display role
* @uses bbp_get_topic_author_id() To get the topic author id
* @uses apply_filters() Calls bbp_get_topic_author_role with the author
* role & args
* @return string topic author role
*/
function bbp_get_topic_author_role( $args = array() ) {
// Parse arguments against default values
$r = bbp_parse_args( $args, array(
'topic_id' => 0,
'class' => 'bbp-author-role',
'before' => '',
'after' => ''
), 'get_topic_author_role' );
$topic_id = bbp_get_topic_id( $r['topic_id'] );
$role = bbp_get_user_display_role( bbp_get_topic_author_id( $topic_id ) );
$author_role = sprintf( '%1$s<div class="%2$s">%3$s</div>%4$s', $r['before'], $r['class'], $role, $r['after'] );
return apply_filters( 'bbp_get_topic_author_role', $author_role, $r );
}
Not using Buddy Press.
Here is a list of the bbPress related plugins that are installed currently:
– AccessAlly – bbPress Add-on
– bbP private groups
– bbPress – Mark as Read
– bbPress – Moderation Tools
– bbPress Notifications
– bbPress Notify (No-Spam)
– bbPress Profile Link Shortcode
– bbPress Search Widget
– bbPress Toolkit
– bbPress Unread Posts
It’s like using the shortcode
, or is it using the shortcode [bbp-search] ??
And, for the record, I tried Robin’s code too. This time the user was originally a ‘participant’. When adding Robin’s code and trying to save as my new forum user role, it reverts back to ‘participant’. Caching is turned off.
Did anyone find a solution to this? I have am having the same issue and am using:
function add_custom_role( $bbp_roles ) {
$bbp_roles['my_custom_role'] = array(
'name' => 'Bosun',
'capabilities' => bbp_get_caps_for_role( bbp_get_participant_role() ) // same capabilities as participants
);
return $bbp_roles;
}
add_filter( 'bbp_get_dynamic_roles', 'add_custom_role', 1 );
Sorry, been away for a while.
It’s like using the shortcode
Thanks so much.
Hey Robin,
Thanks for getting back to me. I’ve just this moment found a simple solution. What do you think of this:
.logged-in #bbp-forum-40250 {
display: none;
}
If you just want to remove it from the list then you could amend loop-single-forum.php
create a directory on your theme called ‘bbpress’
ie wp-content/themes/%your-theme-name%/bbpress
where %your-theme-name% is the name of your theme
find
wp-content/plugins/bbpress/templates/default/bbpress/loop-single-forum.php
Make a copy of this file, and put in in the directory called bbpress that you created above, so you end up with
wp-content/themes/%your-theme-name%/bbpress/loop-single-forum.php
bbPress will now use this template instead of the original
and you can amend this
change it to (assuming 40250 is the fiorum id)
<?php
/**
* Forums Loop - Single Forum
*
* @package bbPress
* @subpackage Theme
*/
if ( !bbp_get_forum_id() == '40250')) {
?>
<ul id="bbp-forum-<?php bbp_forum_id(); ?>" <?php bbp_forum_class(); ?>>
<li class="bbp-forum-info">
<?php if ( bbp_is_user_home() && bbp_is_subscriptions() ) : ?>
<span class="bbp-row-actions">
<?php do_action( 'bbp_theme_before_forum_subscription_action' ); ?>
<?php bbp_forum_subscription_link( array( 'before' => '', 'subscribe' => '+', 'unsubscribe' => '×' ) ); ?>
<?php do_action( 'bbp_theme_after_forum_subscription_action' ); ?>
</span>
<?php endif; ?>
<?php do_action( 'bbp_theme_before_forum_title' ); ?>
<a class="bbp-forum-title" href="<?php bbp_forum_permalink(); ?>"><?php bbp_forum_title(); ?></a>
<?php do_action( 'bbp_theme_after_forum_title' ); ?>
<?php do_action( 'bbp_theme_before_forum_description' ); ?>
<div class="bbp-forum-content"><?php bbp_forum_content(); ?></div>
<?php do_action( 'bbp_theme_after_forum_description' ); ?>
<?php do_action( 'bbp_theme_before_forum_sub_forums' ); ?>
<?php bbp_list_forums(); ?>
<?php do_action( 'bbp_theme_after_forum_sub_forums' ); ?>
<?php bbp_forum_row_actions(); ?>
</li>
<li class="bbp-forum-topic-count"><?php bbp_forum_topic_count(); ?></li>
<li class="bbp-forum-reply-count"><?php bbp_show_lead_topic() ? bbp_forum_reply_count() : bbp_forum_post_count(); ?></li>
<li class="bbp-forum-freshness">
<?php do_action( 'bbp_theme_before_forum_freshness_link' ); ?>
<?php bbp_forum_freshness_link(); ?>
<?php do_action( 'bbp_theme_after_forum_freshness_link' ); ?>
<p class="bbp-topic-meta">
<?php do_action( 'bbp_theme_before_topic_author' ); ?>
<span class="bbp-topic-freshness-author"><?php bbp_author_link( array( 'post_id' => bbp_get_forum_last_active_id(), 'size' => 14 ) ); ?></span>
<?php do_action( 'bbp_theme_after_topic_author' ); ?>
</p>
</li>
</ul><!-- #bbp-forum-<?php bbp_forum_id(); ?> -->
<?php } ?>
Not tested but should work, if not then might be another bbpress plugin overwriting the template – come back
ok, the code does not allow for pagnination if you have nested replies allowed in the forum settings.
That is just the way the code is written, I am not an author of the code.
Posted this code in file functions and obsolyutno nothing to acquire not has changed: (as was 80 messages on page tube top so and remained, in all themes. Although the settings specified no more than 10.