WordPress.org

Forums

echo a link - help (4 posts)

  1. artfulalibi
    Member
    Posted 6 years ago #

    Hello,

    Please forgive my basic PHP skills. I am writing a basic function, but for some reason I can't get the links to come out right. Here is my code:

    function featuredStory() {
    $featuredPosts = new WP_Query();
    $featuredPosts->query('cat=9&showposts=5');
    while ($featuredPosts->have_posts()) : $featuredPosts->the_post();
    echo '<a href="' .the_permalink(). '" rel="bookmark">' .the_title(). '</a>';
    endwhile;
    }

    The resulting link doesn't work. It shows up like this:

    http://siteurl/?p=9This is the first featured
    <a rel="bookmark" href=""/>

    Why is the anchor text showing up after, and with no closing a? I have tried reworking it, over and over. Arrg!

  2. cutomthemedesign
    Member
    Posted 6 years ago #

    Hello,

    Try something like this:

    echo '<a href="' .get_permalink(). '" rel="bookmark">' .the_title('', '', 0). '</a>';

    Good Bye!

  3. artfulalibi
    Member
    Posted 6 years ago #

    Thanks Custom! That worked. I guess the_title() requires those parameters in order to parse correctly?

  4. cutomthemedesign
    Member
    Posted 6 years ago #

    Yes the zero parameter will save the result instead of printing it. so this way it works when you add "echo" command to it.

Topic Closed

This topic has been closed to new replies.

About this Topic