• 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:

    https://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!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hello,

    Try something like this:

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

    Good Bye!

    Thread Starter artfulalibi

    (@artfulalibi)

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

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

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘echo a link – help’ is closed to new replies.