Skip to content

Instantly share code, notes, and snippets.

@matiasinsaurralde
Last active December 16, 2015 16:40
Show Gist options
  • Save matiasinsaurralde/5465067 to your computer and use it in GitHub Desktop.
Save matiasinsaurralde/5465067 to your computer and use it in GitHub Desktop.
Wordpress Custom Page
<?php
/*
Template Name: Extended category
(we want to enable many plugins that do not work with the default category template)
*/
?>
<?php
get_header();
bd_page_before();
// find the category id based on the post title
$pagename = get_query_var('pagename');
if ( !$pagename && $id > 0 ) {
$post = $wp_query->get_queried_object();
$pagename = $post->post_name;
};
$category_id = get_cat_ID( $pagename );
?>
<div id="main">
<div id="main-content" class="wrap">
<div id="primary">
<?php
$posts = get_posts("category=".$category_id."&orderby=rand&numberposts=3");
foreach($posts as $post) {
?>
<?php get_template_part('loop', 'post'); ?>
<?php
};
?>
</div>
<?php get_sidebar(); ?>
</div>
</div>
<?php
bd_page_after();
get_footer();
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment