Forums

is_home conditional help (12 posts)

  1. Righton
    Member
    Posted 11 months ago #

    I have a small button that floats with my content to shoot people back up top on long pages.

    I would like for this to not show on the index page so I'm trying to figure out the is_home conditional tag stuff.

    I simply have the image placed with fixed positioning and I'm using this to display it...

    <a href="#top"><img src="<?php bloginfo('template_directory'); ?>/images/top.png" id="toplink"/></a>

    I would like for that to be ignored on home but used everywhere else and I cannot figure out how to structure the conditional code.

    Anyone up for helping me?

    Thanks!

    (PS - you can see it in use here: http://jamesmeister.com/)

  2. filosofo
    Member
    Posted 10 months ago #

    <?php if ( ! is_home() ) : ?>
    <a href="#top"><img src="<?php bloginfo('template_directory'); ?>/images/top.png" id="toplink"/></a>
    <?php endif; ?>
  3. Righton
    Member
    Posted 10 months ago #

    I used that and I'm still seeing it pop up on the home page.

  4. filosofo
    Member
    Posted 10 months ago #

    Keep in might there is a difference between the front page and the home page. Basically, the "front" page is the top level of your site; the "home" page is wherever the latest posts are listed, which when there's a static front page is not the top level page. One of is_home() or is_front_page() should do what you want.

  5. Righton
    Member
    Posted 10 months ago #

    I've used is_home and is_front_page and both still show up on the main front page.

  6. ilovecolors
    Member
    Posted 10 months ago #

    I use is_front_page in most of my projects, so you could use

    <?php
    if (!is_front_page())
    {
    ?>
    
      <a href="#top">
        <img src="<?php bloginfo('template_directory'); ?>/images/top.png" id="toplink"/>
      </a>
    
    <?php
    }
    ?>

    Remember what the Codex says

    is_front_page()
    When it is the front of the site displayed, whether it is posts or a Page. Returns true when the main blog page is being displayed and the 'Settings->Reading->Front page displays' is set to "Your latest posts", or when 'Settings->Reading->Front page displays' is set to "A static page" and the "Front Page" value is the current Page being displayed. Note: this tag was added at Version 2.5.

  7. Righton
    Member
    Posted 10 months ago #

    Strange... no matter how I seem to phrase the conditional (all of the examples above) it never vanishes from the front page.

    Could it be that I have renamed index.php to all.php and have rewritten index.php to only pull up the main category and include all.php?

    I'm using this for index.php

    <?php
    $_GET['cat'] = "1";
    include "all.php";
    ?>
  8. Otto42
    Moderator
    Posted 10 months ago #

    Could it be that I have renamed index.php to all.php and have rewritten index.php to only pull up the main category and include all.php?

    Yes, that could do it. Don't do that.

    If you want the category to be forced to 1 on the index page, then there are much better ways. query_posts('cat=1'); for example.

  9. Righton
    Member
    Posted 10 months ago #

    I use that for each "page" I want, to pull out one category per "page".

  10. Otto42
    Moderator
    Posted 10 months ago #

    Okay, but why? I mean, category pages are built in. http://example.com/category/whatever/, for example.

  11. Righton
    Member
    Posted 10 months ago #

    is that something you need to build in? I just tried jamesmeister.com/graphic_design/ and it didn't work.

  12. Otto42
    Moderator
    Posted 10 months ago #

    a) You need to be using non-default permalinks to get that sort of style of URL.

    b) The word "category" is not optional. You can change it though, look at your Settings->Permalink page.

Reply

You must log in to post.

About this Topic