I am trying to use the get_posts() function in WordPress to display a list of posts a specific category on my homepage. Here’s my code:
<div id="announcements">
<?php
$myposts = get_posts( 'category'=>3 );
foreach ( $myposts as $post ) : setup_postdata( $post );
?>
<div id="announcement-post-title">
<b><a href="<?php the_permalink() ?>" title="Permanent Link to
<?php the_title(); ?>" class="homepage-post-title">
<?php the_title(); ?></a></b>
</div>
<div id="announcement-post-content">
<?php the_content(); ?>
</div>
<div id="announcement-post-read-more">
<a href="<?php the_permalink() ?>" class="read-more-button">Read
More</a>
</div>
<?php endforeach; ?>
</div>
When I view the page, though, I get the following error:
Parse error: syntax error, unexpected T_DOUBLE_ARROW in /home1/mt/public_html/resources2/wp-content/themes/twentytwelve/front-page.php on line 26
Line 26 is this one:
$myposts = get_posts( 'category'=>3 );
Any ideas why this is happening?
Thanks in advance!
The get_posts() function expects an array to be passed.
Try:
See the wordpress codex