Forums

Display widget on certain pages (26 posts)

  1. jonathanstegall
    Member
    Posted 1 year ago #

    Hello,

    Currently, I'm trying to set up a widget that displays itself on certain pages. To do this, I found the Widget Logic plugin. It takes any PHP argument, and if that argument returns as true, the widget will display.

    I would like to create an argument that does the following:

    1. Allow me to pass a desired category slug
    2. Check the slug of the current category (or it's parent, if it is a subcategory)
    3. If the slug I passed matches the slug of the category, return true

    I can't seem to get anything to successfully do this, though. The closest I have come is like this:

    1. Allow me to pass a desired category id (so, 12 instead of news)
    2. Check the slug of the current category (or its parent)
    3. So, the function does not return true because it expects a slug to match a number.

    Any ideas on how I might be able to reconcile this? Thanks.

    Jonathan

  2. alanft
    Member
    Posted 1 year ago #

    hi there - Widget Logic guy here!

    check http://codex.wordpress.org/Conditional_Tags for examples of how to use conditional tags. the example they give there for checking category slugs is

    is_category('blue-cheese')

    and something like that should work for you in widget logic. if not let me know.

  3. Ovidiu
    Member
    Posted 1 year ago #

    can I just jump in on this conversation? I tried to psot on the plugins homepage, but had connection problems so ehre I go:

    I have 2 sidebars, with both showing on the homepage but only one on all other pages. So I need to use your plugin, to make 2 widgets from sidebar 1 to disappear on the homepage.

    I tried !is_home() for both widgets, but as soon as I save,both conditions disappear. It seems to work fine if I only use this condition on one widget, but as soon as I use this condition ob two widgets, like I said, the conditions both disappear...

    any clue what could be wrong? did you test your plugin in a similar situation?

    can you try and use !is_home() on two widgets, and then save and see if that works for you?

  4. alanft
    Member
    Posted 1 year ago #

    yes i have tested such a setup - i have quite a complex setup with lots of widgets and logic text for each.

    but have you got the newly released version 0.42 - there were some problems with 0.4 and losing settings under certain circumstances. not seen that with 0.42 yet in my 'lab' setup.

    (mind you i haven't done much testing with multiple sidebars - must get on that...)

  5. Ovidiu
    Member
    Posted 1 year ago #

    yes I do have the latest version...
    I also experienced another glitch: after saving some settings, all of a sudden the field where I could input the "logic" was gone - I had to check: "Use 'widget_content' filter?" again to make that field appear again.

    would you want to help out? if so, I could give you a temp. access.

  6. alanft
    Member
    Posted 1 year ago #

    definitely - that would be very helpful. are you using the 'cancel' button on the widgets BTW?

  7. alanft
    Member
    Posted 1 year ago #

    also :-(

    really thought i'd caught all these 'dropouts'. any help you can give to track these down would be appreciated.

  8. Ovidiu
    Member
    Posted 1 year ago #

    please drop me an email: ovidiu at pacura dot ru - I will reply with access data to the site I do currently have problems with.

  9. alanft
    Member
    Posted 1 year ago #

    just mailed you. cheers!

  10. alanft
    Member
    Posted 1 year ago #

    hi - not got any e-mail yet, but...

    i think i found a way to lose widget logic text that shouldn't happen that i missed in 0.42. so i've made a quick 0.43 release to patch that. let me know how you find it.

  11. Ovidiu
    Member
    Posted 1 year ago #

    sorry man I got home yesterday at about 19 o'clock, and fell asleep shortly after. And as I can't access my private mails from work, I'll have to test your new 0.43 version. I'll let you know how it goes.

  12. Ovidiu
    Member
    Posted 1 year ago #

    ok, works better. I still had the problem that the widget logi field disappeared, but after completely deactivating and reactivating the plugin, it worked...

    works now. you can see the result here: http://pacura.ru you'll notice on the homepage there are 2 sidebars, while everzwhere else there is only one. And the content from the disappearing sidebar magicaly appears in the remaining sidebar :-) although I am not sure I will leave it there, as I am still testing, modifying the layout.

    THX a lot for this great plugin. now widgets are almost as good as sidebar modules, maybe you know that plugin? maybe you could use it as an inspiration for your plugin? there are still a lot of nice features that plugin has... but unfortunately it is no longer developed. http://nybblelabs.org.uk/projects/sidebar-modules/

  13. alanft
    Member
    Posted 1 year ago #

    !!! wow no i had not seen that plugin before - looks like i need to dig into what it does exactly.

    also glad to hear 0.43 has improved things for you.

    (i was never really clear on the 'cancel' button on widgets, and now i see it's meant to be a 'forget changes' button rather than a reset to default values. just me being dense.)

  14. Ovidiu
    Member
    Posted 1 year ago #

    if you can get your plugin to do what that plugin did, you can sell it :-)
    unfortunately that plugin only worked up to wp 2.something I think, if I remember right, there was a hack floating around so it worked with 2.3 but it is really worth looking into.

  15. VengeanceFury
    Member
    Posted 1 year ago #

    i'd like to jump in on this conversation.... I need some help with conditional statements: I am trying to make a widget display only on 3 specific pages....and I am not sure how to do this. I've tried this:
    if (is_home()) {} elseif (is_page('3')) {} elseif (is_page('49')) {}
    I've also tried this:
    is_page('3''49')
    and this:
    is_page('3') or is_page('49') or is_home()
    and this:
    is_page('3') || is_page('49') || is_home()
    I'm pretty new to php...I'm learning through tweaking the given code within wordpress docs.
    Thanks for any help anyone gives.

  16. alanft
    Member
    Posted 1 year ago #

    the last one should work. all i can suggest is: try putting it in parenthesis?

    ( is_page('3') || is_page('49') || is_home() )

  17. VengeanceFury
    Member
    Posted 1 year ago #

    thank you greatly...the parenthesis worked! p.s. sorry for posting another topic...i thought no one would see my new post in this thread.

  18. alanft
    Member
    Posted 1 year ago #

    cool. i'm going to update the code so that you don't have to do this - i.e. add in an implied parenthesis around logic like that.

  19. sschuler
    Member
    Posted 1 year ago #

    Hi, i'm trying to make a widget HIDE only on one page and show it on all other pages. Can't get the conditional tag right.
    Can you help ?
    Thank's

  20. alanft
    Member
    Posted 1 year ago #

    !is_page(X)

  21. MSchwed
    Member
    Posted 7 months ago #

    This was really great, thanks for the help alanft!

  22. Birgit
    Member
    Posted 7 months ago #

    Is it possible to combine

    !is_home()

    with

    is_category('x') || in_category('x')

    ? I can't seem to find a way to hide this widget from the front page/index.. Thanks in advance!

  23. alanft
    Member
    Posted 7 months ago #

    first off, is_category(x) will never be true on the front page

    and you need to be careful with in_category('x'). because if the page isn't a single post, then in_category(x) will be tested on the last or first post shown on the page.

    so usually in_category(x) needs to be combined with is_single() like this:

    is_single() && in_category('x')

    and THAT will never be true on the home page either.

    so there's no need to combine those with !is_home() in this case anyway.

    HTH

  24. Birgit
    Member
    Posted 7 months ago #

    Thank you, very helpful! :) What if I actually do want to display the widget on archive/category pages and not only on the single post pages?

    Specific case: Site is a sports news site. Category is handball, sub categories are local handball teams. For each team, one text widget. For each single post about a team, the widget appears, like described. I would love to display the widget(s) on the archive page for "handball" as well. Plural form because there will be one widget for each team on that archive page.

  25. alanft
    Member
    Posted 7 months ago #

    is_category(x) || (is_single() && in_category(x))

    i think i will add this code to the FAQ as it comes up very often

  26. Birgit
    Member
    Posted 7 months ago #

    Brilliant! Thanks so much!

Topic Closed

This topic has been closed to new replies.

About this Topic