WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] test if WP is displaying with index.php file (7 posts)

  1. syncbox
    Member
    Posted 6 years ago #

    Is there some way to test if the WP app is using the index.php file for displaying content? I know I can say

    if (is_category())

    or

    if (is_page())

    etc...

    but as far as I know, there is no

    if (is_index())

    I know that when no posts exists, WP does not use the category.php file... it uses index.php

    1) can I force it to somehow use category.php anyway?
    2) if not, can I test whether the index file is being used so that I can conditionally display something in the sidebar?

    Your help appreciated!

  2. moshu
    Member
    Posted 6 years ago #

    is_home

    more: Conditional_Tags

  3. syncbox
    Member
    Posted 6 years ago #

    so, is_home() would mean you are using the index.php file even if your options are setting the start or home page to a Page?

    I found a way to get my sidebar to display the right thing anyway with some nested if else logic, but I'll look into this too! Thank you!

  4. moshu
    Member
    Posted 6 years ago #

    None of the conditionals you were mentioning are looking for "files"! They are looking at what query is executed:
    showing the "home" or
    showing a category archive or
    showing a Page etc.

  5. syncbox
    Member
    Posted 6 years ago #

    well, that is what I thought, though typically, if you have a category.php file and the logic says if (is_category())

    it IS going to use the category.php file

    So is_home() isn't necessarily going to use index.php file if there is a page.php file AND home (start page) is the Page "home"

    So I will stick with the nested logic I came up with yesterday in my sidebar that allows me an "else" for pages and an "else" for everything else. Seems to work just fine.

    Thank you though, for taking the time to respond! It's much appreciated and I've learned so much from reading your posts (not just to my questions, but all of them)

  6. moshu
    Member
    Posted 6 years ago #

    if you have a category.php
    That's the keyword here!
    The is_category will work even with a theme that has NOT category.php file and is using the archive.php for displaying catgeory listing/archive... even more, if it has only index.php (as the classic) the conditional still works :)
    Does it make sense?

  7. cezarneaga
    Member
    Posted 5 years ago #

    hi syncbox,

    i want the same thing as you. what is your nested solution? or since 8 months have past, have you got another solution?
    thanks,
    Cezar

Topic Closed

This topic has been closed to new replies.

About this Topic