Forums

Widget Logic - Just plain doesn't work (22 posts)

  1. OneEyedParrot
    Member
    Posted 11 months ago #

    Widget Logic just plain doesn't work for my theme. I can tell you three basic things:

    1. The widget always is displayed on every page
    2. Setting logic to 'false' doesn't change anything
    3. The default theme does work with widget logic

    I saw this topic:
    http://wordpress.org/support/topic/199255

    I think we have the exact same cases.

    So what exactly makes a theme widget logic compatible?

  2. OneEyedParrot
    Member
    Posted 11 months ago #

    Has anyone got any idea at all? I checked the default theme and the code that draws the dynamic sidebar appears to exactly the same as what I have.

  3. alanft
    Member
    Posted 11 months ago #

    what's your theme?

    short answer, if a theme messes around a lot with WP queries, the standard conditional tags (is_home etc) can fail. however if you've tried just false, and it still doesn't work, that's really odd. that should block the widget regardless.

    unless you have some sort of aggressive caching going on.

    tell me more

  4. OneEyedParrot
    Member
    Posted 11 months ago #

    Hi alanft,

    The theme I'm using is built from a wordpress-ignorant design. So in terms of Wordpress functionality, I made it.

    The worst I mess around with WP queries is indeed in the sidebar. It's just a simple code to show a rundown of stories from a particular category. If I take it out, though, it does not change a thing. Here's the code from the sidebar.php:

    <td class="left_content">
    <?php
    
    if ( function_exists('dynamic_sidebar') ) {
         dynamic_sidebar();
    }
    ?>
    
    <?php if( is_home() ) {
    
    $postlist = get_posts('category_name=events&numberposts=5');
    foreach ($postlist as $post) {?>
    <div class="event-post">
    	<h2 class="event-title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
    <span class="event-entry">
    	<?php the_excerpt(); ?>
    	<?php the_content("Read more &raquo;"); ?>
    </span>
    </div>
    <? } ?>
    <? } ?>
    </td>
  5. alanft
    Member
    Posted 11 months ago #

    and that code is after the dynamic sidebar is called anyway - so it shouldn't have any impact.

    does the problem persist even with the default theme rather than your own?

    edit:

    oops i see you've already tried that and it is ok, so there is something up with your theme. do you have a large functions.php? otherwise i'm totally out of troubleshooting idead without getting hand on :-(

  6. OneEyedParrot
    Member
    Posted 11 months ago #

    Thanks for following up :)

    Theme functions file is pretty small. Here it is:

    <?php
    if ( function_exists('register_sidebar') )
        register_sidebar(array(
            'before_widget' => '<li id="%1$s" class="widget %2$s">',
            'after_widget' => '</li>',
            'before_title' => '<h2 class="widgettitle">',
            'after_title' => '</h2>',
        ));
    
    function exclude_category($query) {
    	if ( $query->is_home ) {
    		$query->set('cat', '-7');
    	}
    	return $query;
    }
    
    add_filter('pre_get_posts', 'exclude_category');
    ?>

    I've removed that exclude_category function and that did nothing.

  7. OneEyedParrot
    Member
    Posted 11 months ago #

    The only other code that executes before this is in header.php. I gave this a look-see but nothing too interesting - just a bunch of bloginfo() calls.

    Is there something that needs to be in functions.php that I don't have?

  8. alanft
    Member
    Posted 11 months ago #

    well i'm stumped.

    you could try troubleshooting using an exec PHP widget - that way you can ececute some PHP like

    if (is_home()) echo "THIS IS HOME";

    in a widget to see if is_home() is working ok, and so on. if you could parcel up your theme and make it available to download, i'll see if it is the theme. (it really doesn't look like it, from the code you give). you're on 2.6, and i can setup a vanilla 2.6 wp here with your theme to play with

  9. OneEyedParrot
    Member
    Posted 11 months ago #

    So here's the results:

    1. I installed PHP-Exec. The extension works fine. Widget Logic = :(
    2. Here's the theme:
    http://pk-fire.com/etc/spranklez.zip

    Thanks so much again

    EDIT: The site I'm working on is at:
    http://spranklestudios.com/wp/

  10. OneEyedParrot
    Member
    Posted 11 months ago #

    Aha! It's always the simplest of things, isn't it?

    Googling around, I found this topic:
    http://wordpress.org/support/topic/197792

    I saw that and simply thought, "Huh."

    I looked at the default theme. Sure enough, it makes a call to wp_head(). Right before the </head> tag.

    My theme didn't. :)

    alanft, thanks so much for your help. And I just realized you're the developer of Widget Logic - great plugin!

    Also, I might add that this issue could be FAQ-worthy. ;)

  11. alanft
    Member
    Posted 11 months ago #

    thank you! i will indeed add this to the faq.

    i will have to look into how that makes a difference.

  12. OneEyedParrot
    Member
    Posted 11 months ago #

    I think that wp_head() triggers one of those critical hooks that WL depends on very dearly to work.

  13. alanft
    Member
    Posted 11 months ago #

    foolish me - it kicks off the all important hook in widget logic!

    blushes all round!

  14. suite22
    Member
    Posted 8 months ago #

    Hi, 1st time using WordPress. I installed your plugin so that I can replace my widget headers with images. I've uploaded one graphic that I would like to replace on a widget. It can be viewed at http://www.breemusic.com/images/learn.jpg If you visit my site at http://www.breemusic.com I am trying to replace the text in the top left widget with that graphic. How can I do this with your plugin. I've read all documentation and I am still stuck.

    Thanks

  15. alanft
    Member
    Posted 8 months ago #

    you don't need WL to do this. you can do it in just CSS

    there's a part explanation here

    http://wordpress.org/support/topic/173940

    (ignore kevinadams workround at the bottom - that's a terrible way to do it). Basically what you need to do is add a bit of CSS in your theme that targets your widget header like this:

    .widget_recent_comments h2 {
    text-indent: -9999px;
    background-image: url('imageurl.jpg');
    display: block;
    width: 100px;
    height: 100px;
    }

    which targets a widget with class "widget_recent_comments" (look in the HTML of your site to find out the class of the widget you want to target) and changes the heading part of that (the h2 sub-bit) so that the text is effectively hidden (indented out of sight) and the whole h2 chunk is definsed as a box of the specified size and background image

    HTH

  16. mtg169
    Member
    Posted 7 months ago #

    I am having a problem with widget logic working when I specify categories to include in query_posts. I am using the is_home() conditional tag on a couple of sidebar widgets. If I exclude categories in query_posts it works fine. I'd like to specify included categories only so that I do not have to change the code every time I add a new category.

    The following code works and widgets are only displayed on home page:
    query_posts("cat=-1,-6,-11,-21,-23,-24,-27,-35,-38,-40&posts_per_page=1");

    If I use this code, the widgets with the is_home() conditional tags do not show on any page at all:
    query_posts("cat=3,4,5,7&posts_per_page=1");

  17. alanft
    Member
    Posted 7 months ago #

    TBH i'm surprised that the first example (exclusion) works. the built-in conditional tags like is_home() etc are set by WP by checking the query terms provided to build a page

    what you can do to troubleshoot these unusual pages is look at the whole $wp_query object with some code like this

    global $wp_query;
    echo "<PRE>";
    print_r($wp_query);
    echo "</PRE>";

    executed somwhere on the page - add it to your footer.php temporarily perhaps. or put it in PHP widget.

    all the is_home() function does is return the value of $wp_query->is_home

    HTH

  18. mtg169
    Member
    Posted 7 months ago #

    It's odd. When I exclude categories, the value of is_home is 1. When I include them, there is no value and that's why they aren't being displayed. Any ideas why is_home would have no value when you are on the home page only when you include categories?

  19. alanft
    Member
    Posted 7 months ago #

    there's some code in query.php

    if ( empty($qv['cat']) || ($qv['cat'] == '0') ) {
    	$this->is_category = false;
    } else {
    	if (strpos($qv['cat'], '-') !== false) {
    		$this->is_category = false;
    	} else {
    		$this->is_category = true;
    	}
    }

    which i translate as if you specify 'cat=' in your query then yout page will get marked as is_category unless there is at least one exclude '-' in the value given. this goes on to mark is_archive as true which then precludes is_home being set true

    you could work round it by excluding just one category you don't care for. or alternatively you could take matters into your own hands, after you issue your bespoke query_posts, just set

    global $wp_query; $wp_query->is_home=true;

  20. mtg169
    Member
    Posted 7 months ago #

    Thanks for your input. I've decided to just set is_home to true on my home page and all works fine.

  21. tictactau
    Member
    Posted 1 month ago #

    Widget logic works great everywhere, but on pages.. or subpages... I checked wp_head and read all the faqs, but still i refuses to work on pages.
    Any insight, please?

  22. alanft
    Member
    Posted 1 month ago #

    does the problem persist if you (temporarily) switch to the default theme? if not, then it's something in your theme.

    does your theme have a page.php file? if so, does it do any custom query stuff in which case:

    have you tried setting the wp_reset_query option?

Reply

You must log in to post.

About this Topic