News page with categories as filters
-
Im setting up a site using wordpress.
Im using pages to display certain content, so i have a news section which will drag posts from the “news” category. Posts are also categorised into child categories as follows:
News
– Print
– Web
– GeneralId like to be able to filter news by these categories but cant get it to work.
This is the code im using to display news posts
<?php /* Template Name: News */ ?> <?php get_header(); ?> <div id="header" class="news col last span-all"> <?php query_posts('pagename=news'); ?> <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> <h3><?php $values = get_post_custom_values("intro-header"); echo $values[0]; ?></h3> <?php if ( get_post_meta($post->ID, 'header-image', true) ) { ?> <img src="<?php $values = get_post_custom_values("header-image"); echo $values[0]; ?>" /> <?php } ?> <?php endwhile; else: ?> <?php endif; ?> </div> <hr /> <div id="content" class="col right span-8 last"> <?php $style_classes = array('col','col', 'col', 'last'); $styles_count = count($style_classes); $style_index = 0; ?> <?php query_posts('category_name=news'); ?> <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> <div class="post-small span-2 left <?php echo $style_classes[$style_index++ % $styles_count]; ?>"> <!-- display the thumbnail for the first image --> <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"> <?php $attachments = get_children( array( 'post_parent' => get_the_ID(), 'post_type' => 'attachment', 'numberposts' => 1, // show all -1 'post_status' => 'inherit', 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order ASC' ) ); foreach ( $attachments as $attachment_id => $attachment ) { echo wp_get_attachment_image( $attachment_id ); } ?> </a> <h4><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h4> <?php the_excerpt(); ?> <a href="<?php the_permalink(); ?>" class="read-more" title="Read More"> Read More</a> </div> <?php endwhile; ?> <!-- <div class="navigation"> <div class="alignleft"><?php next_posts_link('« Older Entries') ?></div> <div class="alignright"><?php previous_posts_link('Newer Entries »') ?></div> </div> --> <?php else : ?> <h3>Not Found</h3> <p>Sorry, but you are looking for something that we havent done yet!</p> <?php endif; ?> </div> <hr /> <div id="sidebar" class="col span-0"> <div class="section"> <h4 class="ver small">Filter by Category</h4> <ul class="nav"> <?php wp_list_categories('title_li=&orderby=id&show_count=1&use_desc_for_title=0&child_of=4'); ?> </ul> </div> </div> <hr /> <?php get_footer(); ?>
Thanks
Viewing 7 replies - 1 through 7 (of 7 total)
Viewing 7 replies - 1 through 7 (of 7 total)
- The topic ‘News page with categories as filters’ is closed to new replies.