Solved

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

Posted on 2011-03-25
10
450 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
change password links 7 74
object oriented programming comparison 5 55
Animated .jpg? 13 60
str_replace not working in php script 4 9
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
This article discusses how to create an extensible mechanism for linked drop downs.
The purpose of this video is to demonstrate how to manually back up a WordPress Database. This will be demonstrated using a Windows 8 PC. The Host used will be IPage.com Log into your Hosting account. IPage will be used for demonstration : Locat…
The purpose of this video is to demonstrate how to prevent comment spam on a WordPress Website. This will be demonstrated using a Windows 8 PC. Plugin Akismet will be used. Go to your WordPress login page. This will look like the following: myw…

920 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now