• Resolved baconchaney

    (@baconchaney)


    Hi everyone,

    I am convinced I am doing something really dumb here but unfortunately I cannot figure out for the life of me where I am going wrong.

    I am currently creating my own theme for my website and created a custom post type for projects to use like a portfolio. ( I haven’t done any of the styling until I have finished the functionality so it is looking a little rough.) What I am trying to achieve is for the project page, if there is one post then display the post, if there is more than one post then display in a different manner and if there aren’t posts then display the 404.
    What appears to be happening is it is echoing the correct number of project posts but instead of outputting all three it is outputting the first post in both the =1 and the >=2 but not displaying any of the other posts. I am a bit stumped and any help would be greatly appreciated.

    Thanks in advance

    page with the problem

    https://pastebin.com/kr0msdhi

Viewing 4 replies - 1 through 4 (of 4 total)
  • review:
    https://php.net/manual/en/control-structures.if.php

    i.e. use curly brackets { } around your multiple lines …

    Thread Starter baconchaney

    (@baconchaney)

    Hi Alcymyth,

    Thanks for that, it has solved half the issue for me. I didn’t think I had to use the curly brackets with alternative syntax as it hasn’t been an issue for me previously.
    The only other issue I have now is that it is only outputting the most recent post though I have it in the settings at the default (10 per page). I can only assume the loop is stopping before outputting the next post in the sequence?

    Thanks again in advance

    you are only using:
    if( have_posts() ) : the_post;
    instead of:
    if( have_posts() ) : while( have_posts() ) : the_post();

    – and of course add the corresponding endwhile;

    https://codex.www.ads-software.com/The_Loop

    Thread Starter baconchaney

    (@baconchaney)

    You sir are a legend!
    I actually added the while( have_posts()) : etc when I first set the loop up but I kept getting syntax errors so thank you for clearing that up.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘issue using wp_count_posts to style based on post quantity’ is closed to new replies.