Solved

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

Posted on 2011-03-25
10
453 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
This article discusses how to implement server side field validation and display customized error messages to the client.
The purpose of this video is to demonstrate how to add AdSense Ads to a WordPress Website, and how to set up WordPress to automatically place Ads in Sidebars. This will be demonstrated using a Windows 8 PC. Log into your AdSense account. : Cli…
The purpose of this video is to demonstrate how to Import and export files in WordPress. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp-login.php : Click on Too…

733 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