• Resolved endofamnesia

    (@endofamnesia)


    I have a heavily modded wordpress installation almost ready to go as a small record label online shop. I added category icons as a final touch (they will be artists photos)

    Only problem is that in order for them to work I need the sidebar to display these images on category pages only.

    So I used conditional tags to make sure of this…as follows:


    <?php
    if (is_category())
    {
    get_cat_icon('');
    }
    ?>

    All works fine except the main index page no longer thinks it’s the index page!

    It tries to display a category icon.

    Now I know the trouble lies on my code on the index page because if I strip out everything between the content div tags, it goes back to knowing it’s the index page.

    On my index page all I have is three seperate uses of

    <?php query_posts('category_name=new-release&showposts=4'); ?>

    (each with different categories) – one for latest new releases, one for latest pre-orders and one for a featured album.

    So does anyone know what tells the conditional tags which is the index page? Are these <php query posts> confusing WP? Why?

    Any help would be greatfully received (and with the possibilty of a free CD ??

Viewing 11 replies - 1 through 11 (of 11 total)
  • Are these <php query posts> confusing WP? Why?
    Yup. By querying Posts of a specific category, you make it a Category page, hence is_category() returns true in the front page.

    There are a couple solution to this, But I’d suggest that you create a template file category.php. Call get_cat_icon('') in category.php, but omit it in index.php.

    Thread Starter endofamnesia

    (@endofamnesia)

    Thanks for your reply.

    I’m not quite sure how your solution works?

    Do you mean create a file called category.php with just the get_cat_icon(”) in?

    How would I include it on the sidebar of catergories and not the index page?

    In your index.php, alter your query_posts() tag like so:

    <?php
    query_posts('category_name=new-release&showposts=4');
    $wp_query->is_category = false;
    $wp_query->is_archive = false;
    $wp_query->is_home = true;
    ?>

    Geeky, but should fix things up.

    ^^If you want to do Kafkaesqui’s, make sure you add those three lines after the last query_posts().

    If you want to do mine:
    1. Omit the following from index.php
    <?php
    if (is_category())
    {
    get_cat_icon('');
    }
    ?>

    2. Create a file category.php and copy the content of index.php to it.

    3. Call get_cat_icon() in sidebar in category.php.

    note: index.php is loaded when you go to mysite.com
    if you go to mysite.com/?cat=1 or mysite.com/category/news, category.php is loaded

    I’ve got a 2.0 blog running with an equasion in the index.php for if (is_home()) and it’s working fine.

    What’s changed?

    How come my code will still work and yours doesn’t?

    Explained here.

    dss, if is_home (or any conditional) is tested *before* query_posts() is called, it should work as normal. Tested after query_posts(), and…

    interesting…

    yes, sidebar and nav menu query is functional.

    it would be nice to be able to call and if for author images within a post, but it would be just as easy to lay out a new class, and set it aside from the content (thus before the call for the post) and say if (is_author(x)) then <image x>

    something like the way the default template addresses explained navigation in the sidebar?

    just a thought.

    dss, you mean assigning WP_Query to a new object? It would provide another (in some ways better) way to get around the *weakness* of query_posts() in this area.

    Thread Starter endofamnesia

    (@endofamnesia)

    Thanks Kafkaesqui and alphaoide for your help.

    I ended up using Kafkaesqui solution and it worked perfectly.

    Are these <php query posts> confusing WP? Why?
    Yup. By querying Posts of a specific category, you make it a Category page, hence is_category() returns true in the front page.

    Alphaoide, you are my hero and I bow to you. I was having a *total* issue with “if (is_home))” only working the first time it was shown, because I was querying a post (I only wanted one category to appear on the index page). I was querying posts also at the end of the index page, and they refused to show up. When I changed the second “if (is_home())” to “if (is_category(‘1’))” (Catgeory 1 being posts that are supposed to go to my index page) – it worked like a charm.

    Thanks for switching that light bulb on over my head! ??

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘is_home no longer working’ is closed to new replies.