Jump to content
Sign in to follow this  
dbhynds

Displaying Posts in Categories in Wordpress

Recommended Posts

I'm creating a website using WordPress, www.dougberkytheatre.com.I'm new to php (really new, as in learning it for this project) and I'm having some trouble getting it to do what I want.I have several posts labelled under Category 3. I want to display the titles of each page in the navigation. I can get it to display correctly, but any time you click the link to load a page, always loads the same post.Here is the code I have for the navigation:

<table border=0 cellpadding=0 cellspacing=0><tr><?php query_posts('cat=3'); ?><?php while (have_posts()) : the_post(); ?><td class="nav" nowrap><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></td><td><img src="/images/navdivider.gif"></td><?php endwhile; ?><td class="nav" width="100%"></td></tr></table>

Here is my code for the main body of my page:

<h1><?php the_title(); ?></h1><?php the_content(); ?>

So here's the problem, the site automatically loads the page entitled "Test Post." However, when you click "Test post 2" it will load "Test Post" instead. Basically, any link you click will always display "Test Post."I think the "<?php query_posts('cat=3'); ?>" code is somehow causing it, because when I delete that, everything works fine. The problem is that I don't want posts in Category 4 to be displayed in the navigation, and deleting this code causes Category 4 posts to be displayed. Oh, the other wierd thing that tells me it's somehow connected to that line of code is that when I move the Navigation code below the Main Body, everything works fine. So it's like the query_post function is somehow getting hung up on the last post in the category (which is "Test Post"), but only does so if the function occurs before the main body code.Can someone help me out here? I'm completely new to php.

Share this post


Link to post
Share on other sites

If the category you want to display is in the URL then you should use that to display the title and content. e.g.<a href="post.php?cat=4">category</a>query_posts('cat=' . $_GET['cat']);

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...