- This topic is empty.
January 8, 2010 at 9:47 am #27493
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
Read Articles about Lessons
Read Training Articles
Read Articles on Showing
Read News about our Stallion
Thanks so much!
What is currently happening with this page? What is broken?
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?
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 ?
Yep, the page loads as if nothing has changed. I made sure to disable cache when testing this…
It is my page.php
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…
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?
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?
Did you try the ID with single quotes around it?
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!
Thanks for your support!
- The forum ‘Back End’ is closed to new topics and replies.