I have a wordpress index.php that runs through this code: My problem is, that when I get to the part of the loop where there is no posts to post (ie. There is a faulty URI or a dead link), wordpress just serves me this line ('Sorry, no posts matched your criteria), as a integrated part of a wordpress theme. This is no good, because there needs to be a header in the 404 page saying something like this: And here is my callenge and job-to-do: I (think that I) need to make some kind of “IF†statement in the top of the header or before the header saying something like “if this is a faulty URI or if no posts meet your criteria, then go to 404.php and present that†I have tried to mix up som php for that but couldn’t get it to work. Is there anybody out there who can figure this one out? Help is really appreciated.
<?phpif(have_posts()):while(have_posts()): the_post();?> what the hell kinda short hand code is that? I've never seen such a messy code, and i cant even tell what it does. if(): <--- wrong should give you error, never see nthat before. while(): <--- wrong again, should give you error, if it doesn't then im crazy... man i dont even know if thats PHP or ASP??
_e('Sorry, no posts matched your criteria.'); Modify this part to: echo "<script type=\"text/javascript\">window.location.href='YOUR 404 PATH';</script>";
This solution is a no-go. It will still try to put some content (the 404) on the main content place, an not make a switch to the 404 page. Besides this solution will give me a "header already sent" error, and I need to send 404 header information when a page is not found.
Hrmmm, I am lost for words here. What do I need that for? If you don't have anything constructive to say... I'd be happy for some pointers though.
This is shorthand similar to <?=(test ? true : false)?> eg <?=($x==1 ? 'x equals one' : 'x does not equal one')?> same as if ($x==1) { echo 'x equals one'; } else { echo 'x does not equal one'; }
sounds about right. I'll give it a try. I don't suppose you have anything resembling a piece of code example that I could study?
It's not something I'ved one myself. But I think it's quite straight forward. Use ob_start() to start buffing content and ob_nd_flush() to send it to the browser
stuw, you are The Man Thx a lot for seeing through this problem of mine. All I ever needed was to do exactly what you told me: Line 1: <?php ob_start(); ?> Line (somewhere in the main body where it was needed): <?php header("HTTP/1.1 404 Not Found");?> <?php ob_end_flush(); ?> <?php $page = file_get_contents('404.php'); echo $page;?> as I needed to get the header 404 not found sentence in the header if there were no posts or an invalid URI. My Google sitemap verified with Google now. Very Cool indeed. *happy-man-humming-all-day*
USually short hand causes errors... That's why i posted what i posted. Re-code it, neatly, correctly, not short-hand for extra mistakes.
I am having a similar problem getting Google to verify my site. But I am not using php scripts. Any suggestions. http://www.bollywoodmovies.us
// Rant # 1 coming.... I disagree. Neatly is subjective, "not short-hand" is not necessarily going to be easier to read, and "correctly", well, it is correct- otherwise it'd spit back a syntax error. You cannot generalize and say if (condition) { } else { } PHP: is the best syntax. A better suggestion would be to use the same syntax consistently throughout an entire project (Which wordpress does.) // Rant # 2 coming... I can't help but correct you. The wordpress code is actually: if (condition): else: endif; PHP: Which is simply an alternative to if (condition) { } else { } PHP: and it is different from this setup condition ? if_true_result : if_false_result; PHP: The main difference being that the last construct returns the resulting value, the other 2 do not- not an insignificant difference. Thanks for hearing me out
woooah drink some coffe dude, or take a chill pill! Actually I agree with you on point 1 As for point 2 I wasn't trying to explain the logic - just that short hand notation existed