Skip to content

Instantly share code, notes, and snippets.

@schalkburger
Created February 17, 2015 09:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save schalkburger/c6bd92fbefc2ad54b79e to your computer and use it in GitHub Desktop.
Save schalkburger/c6bd92fbefc2ad54b79e to your computer and use it in GitHub Desktop.
Wordpress list posts
<?php
if (is_page()) {
$cat=get_cat_ID($post->post_title); // Use page title to get a category ID
$posts = get_posts ("cat=$cat&showposts=3"); // Show 3 posts
if ($posts) {
foreach ($posts as $post):
setup_postdata($post); ?>
<a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a>
<?php the_excerpt(); ?>
<?php endforeach;
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment