WordPress.org

Support

Support » Plugins and Hacks » [Resolved] display related posts if they exist, if not show something else

[Resolved] display related posts if they exist, if not show something else

  • csleh
    Participant

    @csleh

    Plug in is great! I’m trying to set it up so that if there aren’t any related posts some default text is shown.

    my goal is:
    – if there are related posts:
    – show this title and all the related posts (this part is working great)
    – if there aren’t any related posts:
    – show a different title and some set links

Viewing 2 replies - 1 through 2 (of 2 total)
  • csleh
    Participant

    @csleh

    I found it!

    Use this code if you want default text to show if there are no related links chosen with this plugin:

    <?php $related_links = get_related_links(true);
    if ($related_links) {
    ?>
    	 <?php foreach ($related_links as $link): ?>
            <p><strong><?php echo $link["type"]; ?></strong> <br>
    <a href="<?php echo $link["url"]; ?>"><?php echo $link["title"]; ?></a></p>
        <?php endforeach; ?>
    <?php } else { ?>
    	<p>display this default text</p>
    <?php } ?>
    Plugin Author piffpaffpuff
    Member

    @chabis

    yeah. or check the count of the array. btw: the trueargument in get_related_links is wrong.

    $related_links = get_related_links();
    if(count(related_links) == 0)
    {
      // no links
    }
    else
    {
      // has links
    }
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘[Resolved] display related posts if they exist, if not show something else’ is closed to new replies.