Easy movies download - Comprar piso en Denia - Repair Bad Credit - Loans - Credit Counseling

PDA

View Full Version : transfer to 404 with php - or something like that anyway


miko67
Jan 15th 2006, 2:17 pm
I have a wordpress index.php that runs through this code:

<!-- S T A R T M A I N C O N T E N T -->
<div id="main">
<?phpif(have_posts()):while(have_posts()): the_post();?>
<?php the_date('','<h2>','</h2>');?>
<div class="post">
<h3 class="storytitle" id="post-<?php the_ID();?>"><a href="<?php the_permalink()?>" rel="bookmark">
<?php the_title();?>
</a></h3>
<div class="meta">
<?php _e("Filed under:");?>
<?php the_category(',')?>  <?php the_author()?> @ <?php the_time()?>
<?php edit_post_link(__('Edit This'));?>
</div>
<div class="storycontent">
<?php the_content(__('(more...)'));?>
</div>
<div class="feedback" align="right">
<?php wp_link_pages();?>
<?php comments_popup_link(__('Comments (0)'), __('Comments (1)'), __('Comments (%)'));?>
</div>
<!-- <?php// trackback_rdf(); ?> -->
</div>
<divclass="postend"> " " " </div>
<?php comments_template();// Get wp-comments.php template ?>
<?phpendwhile;else:?>
<p>
<?php _e('Sorry, no posts matched your criteria.');?>
</p>
<?phpendif;?><?php posts_nav_link('  ', __('« Previous Page'), __('Next Page »'));?>
</div>
<!-- E N D M A I N C O N T E N T -->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:

<?php header("HTTP/1.1 404 Not Found");?>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.

execute
Jan 15th 2006, 2:56 pm
<?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??

WoodyRoundUp
Jan 15th 2006, 2:57 pm
_e('Sorry, no posts matched your criteria.');

Modify this part to:

echo "<script type=\"text/javascript\">window.location.href='YOUR 404 PATH';</script>";

miko67
Jan 16th 2006, 3:35 am
_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.

miko67
Jan 16th 2006, 3:41 am
<?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 don't even know if that's PHP or ASP??Hrmmm, I am lost for words here. What do I need that for?

If you don't have anything constructive to say...:eek:

I'd be happy for some pointers though.

mitchandre
Jan 16th 2006, 4:00 am
Is that php code?

miko67
Jan 16th 2006, 4:11 am
Is that php code?Supposedly... any pointers?

stuw
Jan 16th 2006, 4:31 am
<?phpif(have_posts()):while(have_posts()): the_post();?>
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';
}

stuw
Jan 16th 2006, 4:33 am
maybe you could buffer your output, and then if there are no posts send the redirect headers....

miko67
Jan 16th 2006, 7:29 am
maybe you could buffer your output, and then if there are no posts send the redirect headers....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?

stuw
Jan 16th 2006, 7:36 pm
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

miko67
Jan 17th 2006, 7:41 am
Use ob_start() to start buffing content and ob_nd_flush() to send it to the browserstuw, you are :cool: The Man :cool:

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*

stuw
Jan 17th 2006, 3:49 pm
thanks for posting your code. I use wordpress myself so this will come in handy.

execute
Jan 27th 2006, 6:14 pm
USually short hand causes errors... That's why i posted what i posted.
Re-code it, neatly, correctly, not short-hand for extra mistakes.

buyallgifts
Apr 11th 2006, 8:39 am
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

miko67
Apr 11th 2006, 11:48 am
... similar problem ... Any suggestions.Only one suggestions... Get around to doing php. It ought to be available to you.:)

exam
Apr 11th 2006, 12:33 pm
// Rant # 1 coming....

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 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 {

} 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...
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';
}
I can't help but correct you. The wordpress code is actually:if (condition):

else:

endif;Which is simply an alternative to if (condition) {

} else {

} and it is different from this setup condition ? if_true_result : if_false_result;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 :)

stuw
Apr 11th 2006, 6:15 pm
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