Skip to content

Instantly share code, notes, and snippets.

@lluisgerard
Created October 26, 2011 11:29
Show Gist options
  • Save lluisgerard/1316084 to your computer and use it in GitHub Desktop.
Save lluisgerard/1316084 to your computer and use it in GitHub Desktop.
archive.php | Wordpress theme file part | Show just one category (parent category alone, or child categories alone)
<?php $cat_obj = $wp_query->get_queried_object(); ?>
<?php
if( $cat_obj->parent ) {
// CATEGORIA FILL / Child category only
while ( have_posts() ) : the_post(); ?>
<?php include('post.php'); ?>
<?php endwhile; ?>
<?php } else { ?>
<?php
// CATEGORIA PARE / Parent category only
while ( have_posts() ) : the_post(); ?>
<?php
// Controlem que sempre sigui una categoria pare / a parent has no parent
$category = get_the_category();
if ($category[0]->category_parent == 0) : ?>
<?php include('post.php'); ?>
<?php endif; ?>
<?php endwhile; ?>
<?php } ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment