WordPress.org

Forums

[resolved] if no related posts (5 posts)

  1. jcyyap
    Member
    Posted 3 years ago #

    Hello friends,

    Was wondering if you guys have a solution to my problem,

    I have a related posts (based on categories) set up on each post and but when i create a new category, it messes up the related posts because there's nothing related, it displays a blank column. i knew this would happen but whats the code to display, say a random post or even text saying 'no related posts'?

    Hope i'm clear about what i said.
    i guess its something to do with <?php else : ?> , <?php if : ?> or something like that but i don't know!

    Please help wonderful people =)

    the full code is on pastebin:

    http://pastebin.com/H1JNEYj5

  2. chadrew
    Member
    Posted 3 years ago #

    http://pastebin.com/H1JNEYj5

    Where's the part that actually displays the post? And your ifs aren't closed. Anyway, I'm no expert, but it should be something like this (provided you fill in the part you left out):

    "No Related Posts"
    http://pastebin.com/Xrpw5fwm

    5 random posts:
    http://pastebin.com/k8d8qpvu

  3. jcyyap
    Member
    Posted 3 years ago #

    ahh sorry mate,

    didn't realize it wasn't the end until you said so.

    anyway, here it is in full:

    http://pastebin.com/QRg0y1UE

    i'll give yours a try.

    thanks a lot

    UPDATE:
    The else echo 'no related posts' didn't work.
    probably because you didn't have the full code at the beginning to work with. my bad.

    would be very grateful if you could correct my mistake.

    thanks =)

  4. chadrew
    Member
    Posted 3 years ago #

    http://pastebin.com/hms66hSZ

    Not sure if it should go before or after wp_reset_query()... But it seems to work for me.

  5. jcyyap
    Member
    Posted 3 years ago #

    Thanks a million!!

    Genius!

    Both worked perfectly =D

Topic Closed

This topic has been closed to new replies.

About this Topic