Navneil Naicker
Navneil Naicker

Reputation: 3691

Custom Template for Wordpress Posts

On WordPress, I have created "Categories" under "Posts". So what I' am doing is adding new "Post" under their respective Category. Example of some Category are "Photo Gallery, Press Releases, Video Gallery".

Now, I' am trying to display from category slug "press-releases". So my URL structure will be www.example.com/press-releases/xyz

I have already read the documentations and few other blogs regarding this but can't really seem to understand. I' am abit confused when it come to doing this. Can anyone help me.

Upvotes: 2

Views: 73

Answers (2)

Krunal Shah
Krunal Shah

Reputation: 2101

Try this code:

Just replace "CATEGORYNAME" with your category name whereever you want:

<?php query_posts('category_name=CATEGORYNAME&showposts=5');
while (have_posts()) : the_post();
  // do whatever you want
?>
<b><a href="<?php the_permalink() ?>" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a>
<?php
endwhile;
?>

Thanks

Upvotes: 2

I am Cavic
I am Cavic

Reputation: 1085

There is probably few ways to do this I would say the easy way would be to create a template-page like this:

PHP CODE

<?php /* Template Name: Available Lots */?>
<?php get_header();?>

<?php // The Query
      // Replace here-goes-the-slug with what you are trying to find
      query_posts( array ( 'category_name' => 'here-goes-the-slug', 'posts_per_page' => -1 ) );?>

<?php if(have_posts()):?>
<?php // The Loop
      while ( have_posts() ) : the_post();?>

// Here goes the code if there is posts found

<?php endwhile; ?>
<?php else: ?>

// Here goes the code if there is no posts in this category


// This code is very important it resets the query for new use
<?php // Reset Query
      wp_reset_query(); ?>

<?php get_footer();?>

This will create a template page for you, now create a new page in your WP. Call it what ever you like on the right side you will see "Template" drop down menu. From this menu select this template you have just created and you are good to go.

Upvotes: 2

Related Questions