ThemeShaper Forums » Thematic

Filtering something - but only on specific pages.

(8 posts)
  • Started 10 years ago by djm
  • Latest reply from djm
  • This topic is resolved
  1. djm
    Member

    Hi,

    First off, thanks to Ian and Chris for their hard work on this framework, having a lot of fun making a theme for a new project of mine - which is nearly finished except for a few lil bits:

    I would like to filter a function but only on the home indexing page and paginations of such and also on the single page.

    I have tried the following using Wordpresses' conditionals in functions.php with little effect (the filter function does work if I remove the if statements around it however).

    if is_home() or is_single() {
    add_filter('etc', 'etc');
    }

    Any pointers? Cheers.

    Posted 10 years ago #
  2. I think I've used something like this before:

    if( is_front_page() || is_single() ) {
    add_filter();
    }

    Most likely one of those conditionals (is_home or is_single) is returning false for you. What do you get if you do either var_dump( is_single() );, var_dump( is_home() ); or var_dump( is_front_page() );

    Posted 10 years ago #
  3. djm
    Member

    Yeh, they're all returning false which is what I don't get.

    echo "is_single: "; var_dump( is_single() );
    echo "is_home: "; var_dump( is_home() );
    echo "is_front_page: "; var_dump( is_front_page() );

    in the child themes functions.php returns false for all no matter what page of the site I am on; yet function_exists on all the method names returns true..

    Any ideas what could be going on?

    Cheers

    Posted 10 years ago #
  4. djm
    Member

    Dupe post, see below.

    Posted 10 years ago #
  5. djm
    Member

    Aha, fixed this. Basically, Wordpress hasn't run query processing on the URL until after your theme has loaded - so if you run conditionals in functions.php: they will always return false.

    What you need to do is wrap your conditionals in a function and add that function to the 'wp' loader which runs after the URL query processing (and therefore will receive the correct returns on running the conditionals).

    So the above code would be:

    function test_conditionals() {
        if( is_front_page() || is_single() ) {
            add_filter();
        }
    }
    add_action('wp', 'test_conditionals');

    More here under heading 'The Tricky Part': http://w-shadow.com/blog/2009/02/22/make-your-plugin-faster-with-conditional-tags/

    Posted 10 years ago #
  6. Hi,

    works here ..

    home - is_single: bool(false) is_home: bool(true) is_front_page: bool(true)
    single - is_single: bool(true) is_home: bool(false) is_front_page: bool(false)

    .. code used:

    function test_code() {
    echo "is_single: "; var_dump( is_single() );
    echo "is_home: "; var_dump( is_home() );
    echo "is_front_page: "; var_dump( is_front_page() );}
    add_action('thematic_belowheader', 'test_code');

    Chris

    Posted 10 years ago #
  7. OK .. wasn't fast enough with my first post .. and can quit the second one :-)

    Posted 10 years ago #
  8. djm
    Member

    Cheers for the help anyway Chris :)

    Posted 10 years ago #

RSS feed for this topic

Reply

You must log in to post.