Solved

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

Posted on 2011-03-25
10
448 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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

WordPress is constantly evolving, and with each evolution appears to get better and better.  One of the big drawbacks prior to version 3 was that there was no way to be able to set up a custom menu from the backend. The Old Way Adding menus is…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
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 viewer will learn how to count occurrences of each item in an array.

746 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

10 Experts available now in Live!

Get 1:1 Help Now