• Resolved Rob Cubbon

    (@robcub)


    Hi, I’m sure this is really simple as I’ve copied the theme code from a really simple theme and dressed it up a bit. The site has a static front page and the blog is at https://kk-plumbing.co.uk/blog if you click on any of the posts you get all of the posts (but without the posts titles as links so it must be single.php) and when you click a category, again, you get all categories.

Viewing 15 replies - 1 through 15 (of 26 total)
  • It may indeed be simple, but without seeing your code, it is unlikely you will get any help. Try posting the code in the pastebin, and posting a link to it here.

    Thread Starter Rob Cubbon

    (@robcub)

    Point taken, thanks, vtxyzzy.

    Here is single.php: https://wordpress.pastebin.com/u66GrmFz

    Here is archive.php: https://wordpress.pastebin.com/iZwrrJmk

    Thread Starter Rob Cubbon

    (@robcub)

    Here is index.php: https://wordpress.pastebin.com/TeJhZGin

    Please let me know if anyone wants any other code.

    I don’t see anything obvious, but I suspect a problem with the permalinks. Try to switch to the default permalinks and see if the problem goes away.

    Thread Starter Rob Cubbon

    (@robcub)

    No, it’s not that. I’ve left them at default so you can see.

    The only other thing I can suggest is to verify that you are in fact executing the files you think you are.

    I like to put an HTML comment in my php files so I know for sure which one is getting called. Something like this:

    <!-- single.php --><div id="container">

    Then I can look at the source of a page and see the comment.

    If this does not give any leads, I am out of ideas.

    Thread Starter Rob Cubbon

    (@robcub)

    I’ve done this (I’ve put <!-- single.php --> just before <div id="container"> in single.php and put <!-- archive.php --> just before <div id="container"> in archive.php) and they show up where you’d expect them to.

    And I put the pretty permalinks back.

    One last try and I’m done. It seems that single.php is getting called correctly, but with the wrong query. If the unmodified theme works this way, it is probably due to coding in the theme or possibly a corrupted WP install.

    If the default theme displays single posts correctly, look for something in the theme. Otherwise, try a fresh install of WP.

    Thread Starter Rob Cubbon

    (@robcub)

    It works fine with the default theme and I’ve just done a re-install and it hasn’t changed anything.

    So I must have made a mistake with this theme. Is there any other file that could cause this to happen other than index.php, single.php or archive.php ?

    Did you start with a free theme? If so, post the name and I will try to load it into my test site to see if I can spot the problem.

    Thread Starter Rob Cubbon

    (@robcub)

    No this theme I’ve cobbled together from what you’re left with when you’ve gone through this tutorial https://www.wpdesigner.com/2007/02/19/so-you-want-to-create-wordpress-themes-huh/ which is pretty bare bones.

    I’ve used this on several websites – I’ve just been comparing the single.php with another site I’ve done which works and they’re exactly the same.

    Thanks for offering though. I can zip this theme up and put it somewhere if you’re interested?

    OK. I might need to look at the theme, but first, lets do a little debugging. Add the print_r line below into your single.php and lets take a look at the query request that is created. Please run this and post the query that it shows.

    <div id="container">
         <?php print_r($wp_query->request); ?>
    Thread Starter Rob Cubbon

    (@robcub)

    SELECT SQL_CALC_FOUND_ROWS wp_posts.* FROM wp_posts WHERE 1=1 AND wp_posts.post_type = 'post' AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'private') ORDER BY wp_posts.post_date DESC LIMIT 0, 5

    thanks

    All right, the query is indeed not correct. There should be a clause in there like ‘AND wp_posts.ID = 74’ to select only a single post.

    You could have something in functions.php, or a plugin that is changing the query.

    I would first try disabling all plugins. If that does not work, please post functions.php in the pastbin and I will take a look.

    Thread Starter Rob Cubbon

    (@robcub)

    I had already tried the plugins and the problem remains. It’s only Headspace 2, Google Sitemap Generator and Contact Form 7. The functions.php is only:

    <?php
    if ( function_exists('register_sidebar') )
        register_sidebar();
    ?>

    I have tried the homepage to be latest blog posts rather than static front page and the problem still persists.

    I could have done something really stupid in the back end. Please bear in mind I’m really not very bright.

Viewing 15 replies - 1 through 15 (of 26 total)
  • The topic ‘single.php displays all posts, archive.php displays all categories’ is closed to new replies.