Forum | Apply Plugin to Specific Category

You must be logged in to post Login

Apply Plugin to Specific Category

UserPost

11:43 pm
October 25, 2009


MichaelShedd

Member

posts 5

Hey, I'm Michael the new contact and Web developer for the MustangDaily.


We want to implement a public editorial calender so that our readers can comment on individual story ideas for the upcoming week. I was wondering if anyone could help me out with applying plugins to specific categories. We want to make it so that individuals can make comment on certain post paragraphs. The plugin we plan to use is called Feedback by Paragraph. We don't want readers to have the ability to comment by paragraph on all other posts. This plugin is different is different from the standard comment box found on all single post pages.


thanks,

Michael

11:47 pm
October 25, 2009


MichaelShedd

Member

posts 5

if anyone has a better suggestion too that would be awesome.

10:15 pm
October 26, 2009


Mo Jangda

Toronto, ON

Member

posts 35

You could try something like this:

Find these lines in the plugin:

add_filter('the_content', 'FBP_preFlight');
add_filter('comments_array', 'FBPfiltercomments', 1);
add_filter('get_comments_number', 'FBPfiltercommentcount');
add_filter('comments_template', 'FBPcommentsmessage');

And wrap them in an if statement as follows:

if( in_category( '1' ) ) {
    add_filter('the_content', 'FBP_preFlight');
    add_filter('comments_array', 'FBPfiltercomments', 1);
    add_filter('get_comments_number', 'FBPfiltercommentcount');
    add_filter('comments_template', 'FBPcommentsmessage');
}

Replace '1' with the ID or slug of the category you want to limit it the plugin to and that should work. If you have multiple categories:

if( in_category( array('editorials', 'planning', 'blahblah') ) {

6:42 pm
October 27, 2009


MichaelShedd

Member

posts 5

sweet thanx man.

i'll give that a whirl when i get some time.

i appreciate the response!

3:22 pm
October 31, 2009


MichaelShedd

Member

posts 5

so i put in the code:

if( in_category( '1' ) ) {

add_filter('the_content', 'FBP_preFlight');
add_filter('comments_array', 'FBPfiltercomments', 1);
add_filter('get_comments_number', 'FBPfiltercommentcount');
add_filter('comments_template', 'FBPcommentsmessage');

}


i'm locally hosting a version of the mustangdaily.net site on my computer so i just created a category name and category slug of 1 to simplify things. once i added the new code, the plugin feature was no longer displayed in the post filed under category 1 (in addition to all the other categories). the plugin was showing up on all post before so i know it works.


i'm not sure why your suggestion didn't work because from what i'm able to understand the code means if it's in category '1' use the plugin. so i'll keep working on it (maybe i did something wrong), but if u (or anyone else) come up with another suggestion or an ideas why it didnt work let me know.

thanks!

6:42 pm
October 31, 2009


Daniel Bachhuber

Admin

posts 102

Hey Michael,

There's a difference between a category ID and category slug. I believe you can use either with in_category(), but it might be best to use the ID. If you go to /wp-admin/categories.php, and then "Edit" a category, you'll be able to get the ID from the URL. I believe that will give you a better result.

7:34 pm
October 31, 2009


MichaelShedd

Member

posts 5

thanks daniel…

I tried that earlier too. I figured that might be the problem since Mo Jangda mentioned either using the slug or the ID. The category ID ended up being 3 in the category's case and it still wasnt working.


I am wondering how wordpress is able to decipher the difference between a category and an ID. Do I have to include something that denotes the use of an ID instead of a category?

9:37 pm
October 31, 2009


Daniel Bachhuber

Admin

posts 102

The other thing I can think of is how you are passing the variable. If you want to pass the category ID, you might need to pass it as an integer as opposed to a string. This would look like in_category(3) instead of in_category('3'). If you pass it as a string, or quotes around the character, then it might be assuming that's the name for the category instead of the ID.


About the CoPress forum

Most Users Ever Online:

119


Currently Online:

5 Guests

Forum Stats:

Groups: 1

Forums: 7

Topics: 107

Posts: 538

Membership:

There are 151 Members

There have been 2 Guests

There are 5 Admins

There is 1 Moderator

Top Posters:

Chris Ullyott – 66

Mo Jangda – 35

arobinsonwku – 32

laurenmichell – 21

CMLife – 16

sbressler – 15

Administrators: Daniel Bachhuber (102 Posts), William P. Davis (65 Posts), joey (39 Posts), Greg Linch (14 Posts), adam (1 Post)

Moderators: Andrew Spittle (49 Posts)