- This topic is empty.
-
AuthorPosts
-
January 8, 2010 at 9:47 am #27493cjkMember
Hi,
I posted a question in the PHP help section a couple days back without any replies. Thought maybe since it was wordpress / php geared that it might fit in here better.
I am having an issue with a conditional statement on my page.php file that checks for page name and if page name "A" then show a mini loop of posts from category 1, elseif page name B then show from cat 2 etc.
Can anyone have a quick peek at my coding attempt and help me find my error(s) – or perhaps suggest a better way of handling this?
Code:Read the rest of this page »‘); ?>
‘, ‘‘); ?>
Read The Latest News
query(‘category_name=News&showposts=3’);
?>
have_posts())
: $recentnews->the_post();
?>
Read Articles about Lessons
query(‘category_name=Lessons&showposts=3’);
?>
have_posts())
: $recentlessons->the_post();
?>
Read Training Articles
query(‘category_name=training-articles&showposts=3’);
?>
have_posts())
: $recentarticles->the_post();
?>
Read Articles on Showing
query(‘category_name=showing-articles&showposts=3’);
?>
have_posts())
: $recentshowing->the_post();
?>
Read News about our Stallion
query(‘category_name=Stallion&showposts=3’);
?>
have_posts())
: $recentstallion->the_post();
?>
Thanks so much!
What is currently happening with this page? What is broken?
Hey Ashton,
Ha! That might have helped huh? Sorry…
Nothing is being displayed. It is like the code isn’t even there.
I have triple checked all of the page and cat names to make sure this wasn’t the issue.
The mini loops should work, because I copy / pasted them from another area of my site where they do work, changed the cats obviously. I suspect it is something with my conditional statement?
Cheers!
Chris
Okay, Here’s some questions:
Is the header, footer and sidebar showing up?
What is the name of that file? (index.php?)
What page are you going to get this page to display?
One possibility is a messup with the hierarchy… are you familiar with this: http://codex.wordpress.org/Template_Hierarchy ?
Hey Ashton,
Yep, the page loads as if nothing has changed. I made sure to disable cache when testing this…
It is my page.php
Notes:
I have a number of *static* pages plus several hundred posts across 6 categories. I am trying to show the 3 most recent posts from a specific category at the bottom (after the loop) of each of these pages, a different category will be used for some pages. Some pages will show the same loop (once I get this issue figured out I will add (array) into the conditional statement to handle that.
See notes above, I think the easiest way to describe what I am trying to do is:
Below the main content of the displayed *static* page…
If on page "about" grab the 3 latest posts from category "News" and display them as excerpts, else if on page "whatever" get the 3 latest from category "B" and display as excerpts, else if on page "somesuch" get the 3 latest from category C and display as excerpts, any other page, do nothing.
I don’t want this in a sidebar… I would like it to display in the same div / column as the content of the static page…
Make sense?
Hmmmm… Okay so it sounds like you’ve got the hierarchy set up correctly.
The next thing I’d check is your if statements:
Are you sure this is working? Have you tired using the Page ID instead of the page name?
Hey Ashton,
Yeah, I tried page name, slug and ID# as I understand all 3 should work. I focused on that first too as a simple typo would break it. I do believe it is the conditional statement though. I tried the mini loops without the if statement and they displayed as expected. I then took the loops out and replaced them with text in <h2> tags, you know, if this page display this text etc. Again, these <h2> text did not show
So this leads me to believe the issue is the statement? Yes?
Yes.
Did you try the ID with single quotes around it?
Hey Ashton,
Yes, always single, regular up/down quotes wrapping page name, or slug, or ID. But, should it not work with any of these, the same?
It should work with any of these. I have had similar trouble with this is_page() function before and I just had to fiddle with it until it worked. So that’s what I recommend… lol
Ain’t that the truth…
I just retyped it from scratch and it worked as advertised… obviously there is an error in the syntax of one line but for the life of me I can’t find it!
SOLVED!!! Don’t know why, but it just is!
Cheers!
Thanks for your support!
- The forum ‘Back End’ is closed to new topics and replies.