Tagged: BP Simple Front End Post, buddyblog
Just checking in again, any chance you’ll have time to have a look at it before christmas?
Hi Peter,
I am sorry, Been busy with a few other things. Will try to get it in next 2 days.@Leo,
Hi Leo, You will need to copy buddyblog/template/buddyblog to yourtheme/buddyblog and then modify the posts.php just like any normal WordPress loop. That will do it. My apologies for the delayed reply.Thank you
BrajeshJust checking in here, have you had time to try anything out here?
Hi Brajesh,
Thank you, I modified the posts.php and everything is fine now.
I just noticed that there’s a pagination problem. Maybe it is because I have changed my boddyblog slug
I have defined buddyblog slug in my bp-custom.php
define ( ‘BP_BUDDYBLOG_SLUG’, ‘myblog’ );So, the second posts page URL is something like this:
mysite.com/username/myblog/my-posts/page/2/when on the first page I try to click on the “2” (second page) link, it opens this URL mysite.com/username/myblog/page/2/ and it is a 404 page
how can I correct this?
I would like to make the next posts pages URLs like this:
mysite.com/username/myblog/page/2/
mysite.com/username/myblog/page/3/ etc.Thank you!
Leop.s. hope it’s ok to post it here or maybe I need to open a separate topic
Hi Peter,
I am sorry, been away for a week. I will be working on the new things from today onwards and will keep you updated.
@leopro
Hi Leao,
I am sorry for the inconvenience. Need a few hours to test it today and will get back to you. Unless I have made some mistake, just changing the slug should not cause such issue.Great to hear looking forward to try it out, as we haven’t been able to activate the blog-feature yet (with all the articles bla bla).
Hi Peter,
I will have a definite solution today.Sorry to keep you waiting for long.
Hi Peter,
After looking at our admin panel, It does not seem a good idea to allow checking the terms and there can be multiple taxonomies allowed and that can lead to a lot of confusion.So, I am posting code snippet to make it work like you want here. You can put these snippets in your bp-custom.php or your theme’s functions.php
Step 1: decide the taxonomy and terms you want to limit users
function buddyblog_custom_get_allowed_taxonomy() { return 'category';//your taxonomy } function buddyblog_custom_get_allowed_term_ids() { return array( 1,2,23 );//your own set of ids for category }
Change the values in these two functions as appropriate. We will use it in our next step.
Step 2: Limiting Users to post to certain terms only
/** * Limit User posts to selected category only * * @param int $settings * @return int */ function buddyblog_selected_cats_only( $settings ) { $taxonomy = buddyblog_custom_get_allowed_taxonomy();//which tax we are limiting too , you must have selected it in the admin settings if ( $settings['tax'][ $taxonomy ] ) { $settings['tax'][ $taxonomy ]['include'] = buddyblog_custom_get_allowed_term_ids() ;//array of term ids in that taxonomy } return $settings; } add_filter( 'buddyblog_post_form_settings', 'buddyblog_selected_cats_only' );
That’s all, you don’t need to make any change in the second block as it uses the values from first block.
Step 3: Do it only if you want to limit certain posts to be linked on profile and not others
function buddyblog_filter_posts_permalink_preference( $pref, $post ) { $terms = get_the_terms( $post, buddyblog_custom_get_allowed_taxonomy() ); if ( empty( $terms ) ) { //what to do when there are no cats attached //you decide return $pref; } $selected_term_ids = buddyblog_custom_get_allowed_term_ids(); $term_ids = wp_list_pluck( $terms, 'term_id' ); $has_selected_terms = array_diff( $term_ids, $selected_term_ids ); //all or atleast one term found if ( empty( $has_selected_terms ) || count( $has_selected_terms ) != count( $term_ids ) ) { $pref = true; //yes show it on profile } else { $pref = false; //dont show it on profile } return $pref; //return false if you don't want post to be linked to profile } add_filter( 'buddyblog_show_posts_on_profile', 'buddyblog_filter_posts_permalink_preference', 10, 2 );
In the above example, we are doing it based on the selected category. I don’t think it is a good strategy as we we are looking for the post terms before deciding permalink. There is a better solution using custom meta. We store a meta field( “_is_buddyblog_post”) whenever a post is posted/edited from front end(It was added in 1.1 and due to back compatibility I can not use in the plugin itself).
The simple way to filter permalink should to be to check if this meta exists and if yes, link to profile else link to normal like below
function buddyblog_filter_posts_permalink_preference2( $pref, $post ) { if( get_post_meta( $post->ID, '_is_buddyblog_post', true ) ) { //this was posted via buddyblog $pref = true; } else { $pref = false; } return $pref; //return false if you don't want post to be linked to profile } add_filter( 'buddyblog_show_posts_on_profile', 'buddyblog_filter_posts_permalink_preference2', 10, 2 );
You can play with the filter ‘buddyblog_show_posts_on_profile’ and decide which posts should be linked on the profile and which should not be.
Hope that helps.
- This reply was modified 8 years, 11 months ago by Brajesh Singh.
You must be logged in to reply to this topic.