Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

share|improve this question
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. –  m0r7if3r Mar 5 '12 at 13:49
add comment

1 Answer 1

up vote 3 down vote accepted

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 />';
share|improve this answer
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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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