WordPress.org

Ready to get started?Download WordPress

Forums

Related Links
[resolved] display related posts if they exist, if not show something else (3 posts)

  1. csleh
    Member
    Posted 3 years ago #

    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

  2. csleh
    Member
    Posted 3 years ago #

    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 } ?>
  3. piffpaffpuff
    Member
    Plugin Author

    Posted 3 years ago #

    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
    }

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic