WordPress.org

Ready to get started?Download WordPress

Forums

is_home conditional help (12 posts)

  1. Righton
    Member
    Posted 5 years 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. Austin Matzko
    Member
    Posted 5 years 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 5 years ago #

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

  4. Austin Matzko
    Member
    Posted 5 years 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 5 years ago #

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

  6. Elio Rivero
    Member
    Posted 5 years 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 5 years 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. Samuel Wood (Otto)
    Tech Ninja
    Posted 5 years 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 5 years ago #

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

  10. Samuel Wood (Otto)
    Tech Ninja
    Posted 5 years ago #

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

  11. Righton
    Member
    Posted 5 years ago #

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

  12. Samuel Wood (Otto)
    Tech Ninja
    Posted 5 years 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.

Topic Closed

This topic has been closed to new replies.

About this Topic