Search Results for 'code'
-
AuthorSearch Results
-
November 5, 2019 at 5:46 am #205247
In reply to: Show User/Member Join Date
sumitseo
ParticipantAdd this php code snippet into themes functions.php file but did not happen any changes
November 4, 2019 at 1:32 pm #205229In reply to: Get Number of Favorites & Subscription to a topic
Babblebey
Participant$topic = bbp_get_topic_id(); $users = get_users() ; $count = 0; foreach ($users as $user) { $topic_list = array(get_usermeta ($user->id, 'wp__bbp_favorites', false)) ; if (in_array ($topic , $topic_list)) $count++ ; } echo $count;And this one worked Robin! Thank you!
November 4, 2019 at 1:24 pm #205228In reply to: Get Number of Favorites & Subscription to a topic
Babblebey
ParticipantI guess I will be patient for you to test this Robin
$topic = bbp_get_topic_id(); $users = get_users() ; $count = 0; foreach ($users as $user) { $topic_list = get_usermeta ($user->id, 'wp__bbp_favorites', false) ; if (in_array ($topic , $topic_list)) $count++ ; } echo $count;I am getting the error
Warning: in_array() expects parameter 2 to be array, string given in C:\wamp\www\omna\wp-content\themes\omna2\bbpress\content-single-topic-lead.php on line 134
November 4, 2019 at 11:16 am #205227In reply to: Get Number of Favorites & Subscription to a topic
Robin W
Moderatorunder 2.5.14 favorites are stored in usermeta under ‘wp__bbp_favorites’ as a list of topics
so to get a count for a topic, you would need to loop through all users and for each one count if the current topic was in it.
so something like (not tested as am tied up elsewhere, so just spending 5 mins on this)
$topic = some function to get current topic number if not already there $users = get_users() ; $count = 0 ; foreach ($users as $user) { $topic_list = get_usermeta ($user->id, 'wp__bbp_favorites', false) ; if (in_array ($topic , $topic_list) $count++ ; } echo $count ;November 4, 2019 at 7:02 am #205215Topic: Get Number of Favorites & Subscription to a topic
in forum InstallationBabblebey
ParticipantI am trying to make up my own topic description/summary area, so I would like to display the current number of favourites and subscriptions the current topic has.
I have done successfully some other part of the area
<?php !bbp_show_lead_topic() ? bbp_topic_reply_count() : bbp_topic_post_count(); // Display No. of replies in current topic ?> <?php bbp_topic_voice_count(); //Display No of Users in current topic ?> <?php bbp_author_link( array( 'post_id' => bbp_get_topic_last_active_id(), 'type' => 'avatar', 'size' => 20 ) ); //Display Last Reply User ?> <?php bbp_topic_freshness_link(); //Display Last Reply Time ?>So I currently want a function that will display the number of favourites(priority) and subscriptions(not much priority).
Thanking you in anticipation of any working response.
November 4, 2019 at 6:23 am #205212In reply to: How to hide avatars in the list of topics
Danishsard
ParticipantThis does not remove photos from the page code but from the view and that’s something. Thank you for your help!
November 3, 2019 at 2:33 pm #205198In reply to: Topic Index Shortcode: Filter By Certain Forums?
Robin W
Moderatorthe [bsp-display-topic-index] shortcode in my style pack plugin may be what you need
once activated go to
dashboard>settings>bbp style pack>shortcodes to see how it works
November 3, 2019 at 1:29 pm #205193In reply to: Search Not Working
stracy2
ParticipantHi Robin. Thank you for responding.
database size should be no problem
I’m glad to hear that, thank you.
This is a custom convert that is a work in progress.
Forums, Topic, Replies all look good, along with a single word search, but we just noticed this issue with searching more than one word.
Another clue, after enabling debug output, “sometimes” a two word search will give this error:
“Fatal error: Allowed memory size of bytes exhausted in /opt/bitnami/apps/wordpress/htdocs/wp-includes/post.php on line 2272”November 3, 2019 at 1:27 pm #205192Topic: Topic Index Shortcode: Filter By Certain Forums?
in forum Installationoguruma
ParticipantI want to use the [bbp-topic-index] shortcode, however I really want to filter by A) Public Forums, and/or B) certain forums.
When you use the topic-index shortcode, it spits out topics regardless of the forum. The problem with this is that I use BuddyPress and there are groups with private forms. I don’t want the topic-index shortcode to display these private forums.
Now, I could use the [bbp-single-forum id=$forum_id] shortcode. The problem with this, however, is that it will display ALL of the topics for that forum. Now, I COULD hide everything after the first 15 or so topics with CSS, but this is a pretty terrible solution because 1) a boatload of topics are still going to (unnecessarily) be part of the HTML markup and widespread use of display:none is bad for SEO.
Any ideas?
November 3, 2019 at 1:11 pm #205190In reply to: How to notify per forum?
Robin W
Moderatorsorry, but we all have to live, and I don’t plan to replicate Vinny’s code for free.
Users are of course free to subscribe themselves to forums, and then they receive what you are after
November 3, 2019 at 1:06 pm #205189In reply to: How to hide avatars in the list of topics
Robin W
Moderatortry
#bbpress-forums p.bbp-topic-meta img.avatar{ display : none ; }November 3, 2019 at 12:14 pm #205188In reply to: How to hide avatars in the list of topics
Danishsard
ParticipantHello, will this also not remove images from the view of a specific entry in the conversation tree?
It will still load in the page code, you could delete the image by adding files. I tried but the site is broken because I do not know how to edit the line of code that displays it loop topic so as not to spoil and delete only the avatar on the topic list page
November 3, 2019 at 8:56 am #205183In reply to: How to hide avatars in the list of topics
Robin W
Moderatorthe simplest way would be to put this in your theme’s custom css area
img.avatar { display : none ; }November 2, 2019 at 7:35 pm #205169Topic: How to hide avatars in the list of topics
in forum InstallationDanishsard
ParticipantHello, on the list of forum topics avatery are visible, how can I hide or delete them. I just need a username without these pictures.
I don’t know where to turn it on or how to enable it, even by editing the forum file code
My forum page https://infomiasto.eu/forum/tematy/rozmowy/
November 2, 2019 at 10:56 am #205167In reply to: Working Member List?
Robin W
Moderatorthis is code from bbpress version 1 – 9 years ago, unlikely to work
November 1, 2019 at 2:01 pm #205155berry metal
ParticipantI don’t use hand-coded, inline tempolates. I am using Templatera of WPBakery, and I am happy with it as it gives me a graphical overview of the structure, and they are easy to re-make or replace.
In WPBakery, I have a javascript module, an html module, but there is no PHP module.
But there is a text module which does accept shortcodes.
What do you recommend in this scenario?November 1, 2019 at 1:50 pm #205153Robin W
Moderatorthe code would go in your single post template – not having seen the template, I can’t say where !
I was presuming that you were editing this template and Ftp’ing it to your site, in which case, yes it could break it, but you’d just keep a copy of the old template and FTP that back. If you have debugging switched on, then this will tell you where the error is to let you correct
November 1, 2019 at 1:50 pm #205152In reply to: bbpress Loop Argument
Babblebey
ParticipantThank you once again, Robin
<?php if ( babblebey_has_topics() ): while ( bbp_topics() ) : bbp_the_topic(); get_template_part( 'template-parts/topic', 'card' ); endwhile; endif; ?>I used it like that
November 1, 2019 at 1:42 pm #205151In reply to: bbpress Loop Argument
Babblebey
ParticipantSo I will be calling
babblebey_has_topics()?????? Please see as stated below too<!--Sidebar Start--> <div class="col-md-4"> <div class="sidebar-topics row sticky-top"> <div class="col-md-12 col-sm-12 col-12 ml-2 mb-2 p-1"> <h3 class="">Latest Forum Topic</h3> </div> <div class="col-md-12 col-sm-12 col-12"> <?php if ( babblebey_has_topics() ): while ( babblebey_topics() ) : babblebey_the_topic(); get_template_part( 'template-parts/topic', 'card' ); endwhile; endif; ?> </div> </div> </div> <!--Sidebar Ends-->November 1, 2019 at 1:37 pm #205150In reply to: bbpress Loop Argument
Robin W
ModeratorI’d be tempted to just clone the bbp_has_topics function
eg
add this to your functions file
function babblebey_has_topics( $args = '' ) { global $wp_rewrite; /** Defaults **************************************************************/ // Other defaults $default_topic_search = !empty( $_REQUEST['ts'] ) ? $_REQUEST['ts'] : false; $default_show_stickies = (bool) ( bbp_is_single_forum() || bbp_is_topic_archive() ) && ( false === $default_topic_search ); $default_post_parent = bbp_is_single_forum() ? bbp_get_forum_id() : 'any'; // Default argument array $default = array( 'post_type' => bbp_get_topic_post_type(), // Narrow query down to bbPress topics 'post_parent' => $default_post_parent, // Forum ID 'meta_key' => '_bbp_last_active_time', // Make sure topic has some last activity time 'orderby' => 'meta_value', // 'meta_value', 'author', 'date', 'title', 'modified', 'parent', rand', 'order' => 'DESC', // 'ASC', 'DESC' 'posts_per_page' => -1, // Topics per page 'paged' => bbp_get_paged(), // Page Number 's' => $default_topic_search, // Topic Search 'show_stickies' => $default_show_stickies, // Ignore sticky topics? 'max_num_pages' => false, // Maximum number of pages to show ); // What are the default allowed statuses (based on user caps) if ( bbp_get_view_all() ) { // Default view=all statuses $post_statuses = array( bbp_get_public_status_id(), bbp_get_closed_status_id(), bbp_get_spam_status_id(), bbp_get_trash_status_id() ); // Add support for private status if ( current_user_can( 'read_private_topics' ) ) { $post_statuses[] = bbp_get_private_status_id(); } // Join post statuses together $default['post_status'] = implode( ',', $post_statuses ); // Lean on the 'perm' query var value of 'readable' to provide statuses } else { $default['perm'] = 'readable'; } // Maybe query for topic tags if ( bbp_is_topic_tag() ) { $default['term'] = bbp_get_topic_tag_slug(); $default['taxonomy'] = bbp_get_topic_tag_tax_id(); } /** Setup *****************************************************************/ // Parse arguments against default values $r = bbp_parse_args( $args, $default, 'babblebey_topics' ); // Get bbPress $bbp = bbpress(); // Call the query $bbp->topic_query = new WP_Query( $r ); // Set post_parent back to 0 if originally set to 'any' if ( 'any' === $r['post_parent'] ) $r['post_parent'] = 0; // Limited the number of pages shown if ( !empty( $r['max_num_pages'] ) ) $bbp->topic_query->max_num_pages = $r['max_num_pages']; /** Stickies **************************************************************/ // Put sticky posts at the top of the posts array if ( !empty( $r['show_stickies'] ) && $r['paged'] <= 1 ) { // Get super stickies and stickies in this forum $stickies = bbp_get_super_stickies(); // Get stickies for current forum if ( !empty( $r['post_parent'] ) ) { $stickies = array_merge( $stickies, bbp_get_stickies( $r['post_parent'] ) ); } // Remove any duplicate stickies $stickies = array_unique( $stickies ); // We have stickies if ( is_array( $stickies ) && !empty( $stickies ) ) { // Start the offset at -1 so first sticky is at correct 0 offset $sticky_offset = -1; // Loop over topics and relocate stickies to the front. foreach ( $stickies as $sticky_index => $sticky_ID ) { // Get the post offset from the posts array $post_offsets = wp_filter_object_list( $bbp->topic_query->posts, array( 'ID' => $sticky_ID ), 'OR', 'ID' ); // Continue if no post offsets if ( empty( $post_offsets ) ) { continue; } // Loop over posts in current query and splice them into position foreach ( array_keys( $post_offsets ) as $post_offset ) { $sticky_offset++; $sticky = $bbp->topic_query->posts[$post_offset]; // Remove sticky from current position array_splice( $bbp->topic_query->posts, $post_offset, 1 ); // Move to front, after other stickies array_splice( $bbp->topic_query->posts, $sticky_offset, 0, array( $sticky ) ); // Cleanup unset( $stickies[$sticky_index] ); unset( $sticky ); } // Cleanup unset( $post_offsets ); } // Cleanup unset( $sticky_offset ); // If any posts have been excluded specifically, Ignore those that are sticky. if ( !empty( $stickies ) && !empty( $r['post__not_in'] ) ) { $stickies = array_diff( $stickies, $r['post__not_in'] ); } // Fetch sticky posts that weren't in the query results if ( !empty( $stickies ) ) { // Query to use in get_posts to get sticky posts $sticky_query = array( 'post_type' => bbp_get_topic_post_type(), 'post_parent' => 'any', 'meta_key' => '_bbp_last_active_time', 'orderby' => 'meta_value', 'order' => 'DESC', 'include' => $stickies ); // Cleanup unset( $stickies ); // Conditionally exclude private/hidden forum ID's $exclude_forum_ids = bbp_exclude_forum_ids( 'array' ); if ( ! empty( $exclude_forum_ids ) ) { $sticky_query['post_parent__not_in'] = $exclude_forum_ids; } // What are the default allowed statuses (based on user caps) if ( bbp_get_view_all() ) { $sticky_query['post_status'] = $r['post_status']; // Lean on the 'perm' query var value of 'readable' to provide statuses } else { $sticky_query['post_status'] = $r['perm']; } // Get all stickies $sticky_posts = get_posts( $sticky_query ); if ( !empty( $sticky_posts ) ) { // Get a count of the visible stickies $sticky_count = count( $sticky_posts ); // Merge the stickies topics with the query topics . $bbp->topic_query->posts = array_merge( $sticky_posts, $bbp->topic_query->posts ); // Adjust loop and counts for new sticky positions $bbp->topic_query->found_posts = (int) $bbp->topic_query->found_posts + (int) $sticky_count; $bbp->topic_query->post_count = (int) $bbp->topic_query->post_count + (int) $sticky_count; // Cleanup unset( $sticky_posts ); } } } } // If no limit to posts per page, set it to the current post_count if ( -1 === $r['posts_per_page'] ) $r['posts_per_page'] = $bbp->topic_query->post_count; // Add pagination values to query object $bbp->topic_query->posts_per_page = $r['posts_per_page']; $bbp->topic_query->paged = $r['paged']; // Only add pagination if query returned results if ( ( (int) $bbp->topic_query->post_count || (int) $bbp->topic_query->found_posts ) && (int) $bbp->topic_query->posts_per_page ) { // Limit the number of topics shown based on maximum allowed pages if ( ( !empty( $r['max_num_pages'] ) ) && $bbp->topic_query->found_posts > $bbp->topic_query->max_num_pages * $bbp->topic_query->post_count ) $bbp->topic_query->found_posts = $bbp->topic_query->max_num_pages * $bbp->topic_query->post_count; // If pretty permalinks are enabled, make our pagination pretty if ( $wp_rewrite->using_permalinks() ) { // User's topics if ( bbp_is_single_user_topics() ) { $base = bbp_get_user_topics_created_url( bbp_get_displayed_user_id() ); // User's favorites } elseif ( bbp_is_favorites() ) { $base = bbp_get_favorites_permalink( bbp_get_displayed_user_id() ); // User's subscriptions } elseif ( bbp_is_subscriptions() ) { $base = bbp_get_subscriptions_permalink( bbp_get_displayed_user_id() ); // Root profile page } elseif ( bbp_is_single_user() ) { $base = bbp_get_user_profile_url( bbp_get_displayed_user_id() ); // View } elseif ( bbp_is_single_view() ) { $base = bbp_get_view_url(); // Topic tag } elseif ( bbp_is_topic_tag() ) { $base = bbp_get_topic_tag_link(); // Page or single post } elseif ( is_page() || is_single() ) { $base = get_permalink(); // Forum archive } elseif ( bbp_is_forum_archive() ) { $base = bbp_get_forums_url(); // Topic archive } elseif ( bbp_is_topic_archive() ) { $base = bbp_get_topics_url(); // Default } else { $base = get_permalink( (int) $r['post_parent'] ); } // Use pagination base $base = trailingslashit( $base ) . user_trailingslashit( $wp_rewrite->pagination_base . '/%#%/' ); // Unpretty pagination } else { $base = add_query_arg( 'paged', '%#%' ); } // Pagination settings with filter $bbp_topic_pagination = apply_filters( 'bbp_topic_pagination', array ( 'base' => $base, 'format' => '', 'total' => $r['posts_per_page'] === $bbp->topic_query->found_posts ? 1 : ceil( (int) $bbp->topic_query->found_posts / (int) $r['posts_per_page'] ), 'current' => (int) $bbp->topic_query->paged, 'prev_text' => is_rtl() ? '→' : '←', 'next_text' => is_rtl() ? '←' : '→', 'mid_size' => 1 ) ); // Add pagination to query object $bbp->topic_query->pagination_links = paginate_links( $bbp_topic_pagination ); // Remove first page from pagination $bbp->topic_query->pagination_links = str_replace( $wp_rewrite->pagination_base . "/1/'", "'", $bbp->topic_query->pagination_links ); } // Return object return apply_filters( 'babblebey_has_topics', $bbp->topic_query->have_posts(), $bbp->topic_query ); }which is just bbp_has_topics’ renamed with pagination changed to -1
and then call that
November 1, 2019 at 1:35 pm #205149berry metal
ParticipantThank you!
Should I insert the code above in my functions.php as it is, and use [bbp-single-topic id='.$forum_id.'] in my template?
The fact that is not tested, can it break my site?November 1, 2019 at 1:30 pm #205148Robin W
Moderatoruntested, but try
$title = get_the_title() ; $forums = bbp_get_forums_for_current_user() ; foreach ($forums as $forum) { if ($forum->post_title == $title) { $forum_id= $forum->ID ; } } do_shortcode( '[bbp-single-topic id='.$forum_id.']' );November 1, 2019 at 1:03 pm #205143In reply to: bbpress Loop Argument
Babblebey
ParticipantThe Post Per Page as its been set up from the “Forum Setting”:

Works as it should, i.e dictate the number of topics to display per Single Forum Page:

But the same setting is inturn affecting my custom loop I have placed on my HomePage Sticky Sidebar to display latest topics:

I want something similar to the ` $args = array(‘posts_per_page’ => 10 //my custom number) as its being used in the normal WP Post Loop like this below:
<?php $args = array(
‘posts_per_page’ => 10 // Like this one here
);
$posts = new WP_Query($args);
if ($posts->have_posts()):
while($posts->have_posts()): $posts->the_post();
get_template_part( ‘template-parts/content’, get_post_format() );
endwhile;
endif;
wp_reset_postdata(); ?>
`November 1, 2019 at 1:02 pm #205142Robin W
Moderatorso where are you placing this code ? eg in a page template?
November 1, 2019 at 12:51 pm #205140Robin W
Moderatorbbp_is_user_subscribed_to_topic()bbp_is_user_favorite( $user_id, $topic_id ); -
AuthorSearch Results