Theme Redesign Bespoke Wordpress Development Geolocation functionality Bespoke Logo
Web Design Wordpress Development Theme Options Bespoke Widgets
Web Design Wordpress Development Social Network Integration Data Capture Facebook Widget
Web Design Wordpress Development Online Shop Unit Locator Admin Section
Web Design Wordpress Development Bespoke "Custom Fields" Functionality Javascript Photo Gallery
Web Design Wordpress Multi User External Blog Aggregation Social Networking Functionality
I responded to a request for help on twitter today from @russellbishop
Here is the request -
Hi there,
Here’s the link to the Wordpress site I’m constructing;
As you can see on the left hand side, I’ve built a collapsing menu with which to navigate around the site. Unfortunately I’ve had to build that menu manually, as I’m yet to find a function that will give me my categories and their respective posts in a list.
If anyone is able to help I’d really appreciate it.
So, bold hero that I am I tweeted him the answer -
@RussellBishop You need to set up a new query for each <?Query_posts(‘cat=1′); put the loop here only showing titles. Wp_reset_query();?>
Here’s what I meant-
<?php query_posts('posts_per_page=-1&cat=1');?>//this is the line to change per category
<?php if(have_posts()) : ?>
<?php while(have_posts()) : the_post(); ?>
<li><?php the_title(); ?></li>
<?php endwhile; ?>
<?php else : ?>
<?php endif; ?>
<?php wp_reset_query(); ?>
This would show post titles for every post within the category with the id of 1.
TIP: Easy way to find category IDs is to hover over the edit link of that category and look at your browsers status bar. That’ll tell ya!
Maybe that can help some one else along the way.
***UPDATE***
I have since showed Mr Russell how to automatically list the categories and their subsequent posts without having to specify the cat id.
Here it is-
<?php
$cat_args=array(
'orderby' => 'name',
'order' => 'ASC'
);
$categories=get_categories($cat_args);
foreach($categories as $category) {
$args=array(
'orderby' => 'date',
'category__in' => array($category->term_id)
);
$posts=get_posts($args);
if ($posts) {
echo '<ul><h1><a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category->name.'</a></h1>';
foreach($posts as $post) {
setup_postdata($post); ?>
<li><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></li>
<?php
}
echo '</ul>'; }
}
?>
You can be the first to comment!
Leave a comment