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?

3
  • 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
    Commented Mar 5, 2012 at 12:44
  • +1 @Sisir - happens to me a lot; might be the quotes missing around the link url.
    – Michael
    Commented Mar 5, 2012 at 13:20
  • I just put this into Dreamweaver CS5.5 (directly copy-pasted) and I'm not getting an error.
    – mor7ifer
    Commented Mar 5, 2012 at 13:49

1 Answer 1

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 />';
2
  • 1
    same with: the_permalink() -> get_permalink($post->ID)
    – Michael
    Commented Mar 5, 2012 at 13:21
  • Yup, I missed that one. Commented Mar 5, 2012 at 13:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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