0

I have the following coding:

<?php
        global $post;
        $args = array( 'numberposts' => 8);
        $myposts = get_posts( $args );
        foreach( $myposts as $post ) :  setup_postdata($post);
        echo '<a href='.the_permalink().'>'.the_title().'</a><br />';
        endforeach;
?>

Dreamweaver is highlighting a potential syntax error on line 6 & 7. I'm sure it's something very very simple but can someone point me in the right direction to solve this error please?

  • 1
    Seems okey to me. Did you tried running it? Sometimes Dreamweaver shows error where isn't any. Happened to me couple of times. – Sisir Mar 5 '12 at 12:44
  • +1 @Sisir - happens to me a lot; might be the quotes missing around the link url. – Michael Mar 5 '12 at 13:20
  • I just put this into Dreamweaver CS5.5 (directly copy-pasted) and I'm not getting an error. – mor7ifer Mar 5 '12 at 13:49
3

Not sure if it is causing Dreamweaver to flag an error (try running it?), but on the second from last line you want to be using get_the_title(). This returns the posts' title, whereas the_title() will echo it.

echo '<a href='.the_permalink().'>'.get_the_title().'</a><br />';
  • 1
    same with: the_permalink() -> get_permalink($post->ID) – Michael Mar 5 '12 at 13:21
  • Yup, I missed that one. – Stephen Harris Mar 5 '12 at 13:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.