[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 458
  • Last Modified:

Display posts by Category, link to categories and display category title

Hi All,

I'm need some help with wordpress and getting categories setup for pages, currently I have the code below within my index.php, I created a new page and assigened it a custom temple but nothing happend, since I was using posts I had to modify the code within index.php to get the desired results.

I want to display the name of the category as the title, however when i run the code right below, i get the titles of the posts now, instead i want to display category they are in so the latest one would be called 'News 2011', how do I do that?
      <?php while(have_posts()) : the_post(); ?>
            <?php the_content('title'); ?>
      <?php endwhile; ?>

Also looking at the code within div id sidebar-menu, I want to display the categories I have created which are links, so once a user clicks on that link it takes you to the page with the posts displayed for that category, how do I achieve this?

<?php
/**
 * Template Name: News Releases
 *
 */
?>

<?php get_header(); ?>

<div id="sidebar-menu">	

	<ul>
	<?php wp_list_pages('depth=1&title_li=&sort_column=menu_order'); // display the sub-pages of the current parent page ?>
	</ul>
</div>
<div id="content-sub">	
	
	
<h3>News Releases</h3> <-Display Category title NOT post title

	
	
	
	<?php query_posts('category_name=news2011'); ?>
	<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
	<?php /* the_ID(); */ ?> 
	
	<?php /* the_date('F Y'); */ ?>
	<ol class="news">
	<strong><p><?php the_title()?></p></strong>
	<li><?php the_content(); ?></li>
	</ol>
	
	
	<?php endwhile; endif; ?>


</div>

<?php get_footer(); ?>

Open in new window

0
VAN_AL
Asked:
VAN_AL
  • 4
  • 4
  • 2
1 Solution
 
jeremyjared74Commented:
Wouldn't that cause to have duplicate titles?
0
 
VAN_ALAuthor Commented:
Yeah actually that's what's happening, and I don't how to fix it.
0
 
jeremyjared74Commented:
You can't fix it. Categories hold posts. Each post has to have a unique URL. If you made the posts have the URL of the category then every post would have the same URL which isn't possible. Maybe I'm not completely clear on what you want.
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
VAN_ALAuthor Commented:
I currently have on my left side menu, a list of links, these links are children of a parent link (the parent link is accessed from and only appears in the drop-down menu at the top of the page)

So my list menu has three pages (all links are pages)
1) News Releases
2) in The news
3) News Links

Now when I click on news releases. It would open up that page, BUT i want the menu i currently have displaying with a list of Categories beneth News Releases:

So like this:

News Releases
- News 2011 <- Link to a list of posts
- News 2010 <- Link to a list of posts
- News 2009 <- Link to a list of posts
- etc
- etc
2) in The news
3) News Links
0
 
gwkgCommented:
Display the post category with

<?php the_category(); ?>

Are News Releases, In The News, News Links all parent categories?  So you want to show a menu with categories and subcategories?

http://wordpress.org/extend/plugins/collapsing-categories/screenshots/



0
 
VAN_ALAuthor Commented:
I don't know if I have' done this the right way, what I did was I setup categories and added posts to each category and I setup a page called news, and made this page be the blog page under settings>reading menu in wp. However i noticed when i did this non of the content i added on my page within the admin menu on that page actually appeared and needed to modify the code and style sheet for index.php which is where the structure for the posts was and when i clicked to view the links it was taking me to a different page to view them, turned out that was a page called archives.php, so now i have index.php and archives.php setup to work as a page and display categories and posts within it? Sorry I'm new to wp.
0
 
gwkgCommented:
This should help you figure out which template files are creating which pages

http://codex.wordpress.org/Template_Hierarchy

0
 
gwkgCommented:
I just realized this was an old question... you probably have figure that out by now =)
0
 
VAN_ALAuthor Commented:
I have, thanks for your help gwkg
0

Featured Post

[Webinar] Kill tickets & tabs using PowerShell

Are you tired of cycling through the same browser tabs everyday to close the same repetitive tickets? In this webinar JumpCloud will show how you can leverage RESTful APIs to build your own PowerShell modules to kill tickets & tabs using the PowerShell command Invoke-RestMethod.

  • 4
  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now