Solved

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

Posted on 2011-03-25
10
452 Views
Last Modified: 2012-05-11
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
Comment
Question by:VAN_AL
  • 4
  • 4
  • 2
10 Comments
 
LVL 23

Expert Comment

by:jeremyjared74
ID: 35219925
Wouldn't that cause to have duplicate titles?
0
 
LVL 1

Author Comment

by:VAN_AL
ID: 35220017
Yeah actually that's what's happening, and I don't how to fix it.
0
 
LVL 23

Expert Comment

by:jeremyjared74
ID: 35220227
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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
LVL 1

Author Comment

by:VAN_AL
ID: 35220301
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
 
LVL 31

Expert Comment

by:gwkg
ID: 35224243
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
 
LVL 31

Accepted Solution

by:
gwkg earned 500 total points
ID: 35224249
0
 
LVL 1

Author Comment

by:VAN_AL
ID: 35225075
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
 
LVL 31

Expert Comment

by:gwkg
ID: 36102673
This should help you figure out which template files are creating which pages

http://codex.wordpress.org/Template_Hierarchy

0
 
LVL 31

Expert Comment

by:gwkg
ID: 36102677
I just realized this was an old question... you probably have figure that out by now =)
0
 
LVL 1

Author Comment

by:VAN_AL
ID: 36108642
I have, thanks for your help gwkg
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses four methods for overlaying images in a container on a web page
This article discusses how to create an extensible mechanism for linked drop downs.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question