• On my site that uses evidens white theme (http://cityrat.com) as well as my test site at http://furgarden.com, I’m having trouble with any attempt to feature or list content in a sidebar widget that relates to a single post’s category.

    I can’t seem to target all post pages within specific categories.

    For example when I try to use a widget that calls in content from, say, the category “music” (that part is fine, the widgets get the content FROM the category with no problem), and have that widget appear on all POST pages within the category “music”, I can’t seem to do it. I tried in_category(‘7’) as well as the category name with Widget Logic and it does nothing, and I don’t have any luck with Widget Context either (though i have no problem getting the widget to appear on home vs. post pages etc). I tried it with parent categories, names and URL (/*) as well as IDs.

    I’m using the /%postname% structure for posts and default for cats and tags.

    Can anyone help?? I just want to be able to display certain widgets on all posts within a certain category.

    thanks!!
    michelle

    http://wordpress.org/extend/plugins/widget-logic/

Viewing 8 replies - 1 through 8 (of 8 total)
  • Hi Michelle. I was looking to do a very similar thing and I got it to work somewhat using the is_category(‘category name’) instead of the in_category(‘7’) that you stated.

    I really wish someone would address this. I would like to have a single post display one of about 6 different widgets based on the URL slug but nobody seems to be able to help with that either.

    http://codex.wordpress.org/Conditional_Tags

    for instance, is_single() can use ID, name, or slug

    or use a combination; example:

    is_single('fruit-cake') && in_category('bananas')

    That is a step in the right direction. The only problem is that I would need to create a new condition for every post based on the exact URL slug. What would be ideal for me would be to be able to have a post automatically display the proper widget based off of a term in the slug instead of the exact phrase.

    My websites are about ‘insurance’ of all types. So if I put up a post about “dental insurance”, and the slug is /dental-insurance, have the term ‘dental’ in the slug be the condition that pulls in the proper widget.

    I think it would need to be something like is_single() slug contains(‘(keyword’)

    Really appreciate you help so far. I have been working at solving this for a while now!

    Another thing…

    I can get this to work using categories, but since categories can mess up my URL strength I am needing to try an not use them at all if possible.

    I am not a code writer so your help is very much appreciated!

    Basically I need a keyword in the slug to set the condition as to which widget to use.

    I think it would need to be something like is_single() slug contains(‘(keyword’)

    is_single() && strpos($post->post_name, 'dental')!==false

    this worked as a conditional test, however i have not tested it in ‘widget-logic’

    I just tried it in Widget Logic and could not get it to work for me.

    I did get everything to work using this:
    is_page(‘page-name’) || is_category(‘category-name’) || is_single() && in_category(‘category-name’).

    Since I don’t want to use the categories for SEO purposes, after I built the categories, I can now assign a post to a category but on the site itself, I just make sure the category widget is not shown and that keeps my URLs clean.

    Thanks for taking the time to mess around with it. Your input is appreciated!

    Thread Starter michelle cohen

    (@michelle-cohen)

    Thanks for the replies! I get so frustrated when I post here and just hear crickets…

    I just went back and tried some of these solutions (just getting back into messing with it); For some reason, using both BNS Featured Category widget and open PHP widget using Widget Logic I was able to use
    in_category(‘7’) in the widget logic field
    and have it work properly (i.e. widget contains links from category 7 and only shows up on single posts that are in category 7. )

    next, how to get it to show up on the home page ALSO if I want to. Anyone? My home page is not a page.

    All you have to do to get it to show up on the home page is add this to the widget logic code: is_home() I would try placing that at the beginning of the widget logic code and then after it, use a double pipe symbol as a separator. Example… is_home() || in_category(‘7’)

    That tells the widget to display on the home page, as well as in category 7. If you want the widget only on a specific page, or category you can use ‘is’ instead of ‘in’.

    For adding something to many different types of pages, you could set very specific criteria by using a combination of ‘is’ and ‘in’.

    For example, you could have single post display a widget by setting the criteria to be: is_single() && in_category(‘7’) .This would allow any single post to display a particular widget if that post was ALSO found in category 7. If only part of that criteria is met, the widget will not be displayed.

    Now if you wanted any particular post to display ONLY that widget, you would input the name/title of the post into the field like this: is_single(post-name) && in_category(‘7’) . This would make that post only display that widget if it had the proper name AND was assigned to category 7. The is_single() would mean that any single post would display the widget, regardless of category it was assigned to.

    Hope this helps! Let me know if you need some better clarification. I am new to this too but have been working on it extensively for a bit now!

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘getting widgets to appear on posts by category: Widget Logic, etc.’ is closed to new replies.