• Resolved AndreyPutilov

    (@andreyputilov)


    Hello, I have developed my own theme with index.php file but without 404.php

    The problem is present when URL is like mysite.com/meaninglesstext, but everything is good, when URL is mysite.com/category/invalidpostname

    I am testing is_404() and have_posts() at the very beginning of index.php file, no code is included before, but both conditions turn out true;

    I have no self-made post types, I have turned off all plugins. Permalink settings are /%category%/%postname%/ . I tryed to change category and tag prefixes placing casual text, but no effect, though it is not important. Thanks in advance

Viewing 7 replies - 1 through 7 (of 7 total)
  • is_404() won’t work as it tests for a 404 page. If you just use
    if ( have_posts() ):

    then you can add your 404 text as part of an else: after the main Loop.

    Thread Starter AndreyPutilov

    (@andreyputilov)

    Ok, I have created a 404.php file, and it solved my problem, but I am still interested, why have_posts returns true.

    Why the first case mysite.com/meaninglesstext produces a query, but another case mysite.com/category/invalidpostname does not.

    I am still interested, why have_posts returns true.

    Does it? Do you have an else: code block?

    Thread Starter AndreyPutilov

    (@andreyputilov)

    shurely it does, it outputs a list of all new posts. It is not equal to the previous query

    If posts are being output after the Loop, then you have serious problems in that template file.

    Thread Starter AndreyPutilov

    (@andreyputilov)

    No, it is not my problem. Look, I have created a clean index.php file with this code

    [Code moderated as per the Forum Rules. The maximum number of lines of code that you can post in these forums is ten lines. Please use the pastebin]

    The result is https://www.peeep.us/7b74626d

    Thread Starter AndreyPutilov

    (@andreyputilov)

    Ok, this is a very strange behaviour but I am not looking forward to dealing with it cause a creation of 404.php file is an acceptable solution.

    In any case I want to thank esmi and all the rest because it helped me to sort out what is running in a wrong way and what is not.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘is_404() is true and have_posts() is also true?!’ is closed to new replies.