• Resolved Tuukka Virtaperko

    (@complex-buttons)


    I’m trying to make index.php redirect to single.php that is showing the most recent post. I put this as the content of index.php:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head profile="http://gmpg.org/xfn/11">
    
    <meta HTTP-EQUIV="REFRESH" content="0; url=http://sarjakuva.tuukkavirtaperko.net/?p=<?php $newest_post_id ?>">
    
    </head>
    </html>

    It only creates a page that keeps reloading itself. Does anyone know what went wrong here?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Michael

    (@alchymyth)

    where is the value for the variable $newest_post_id defined?

    also, the variable, if it has the value of the latest post ID, should be echoed:

    <meta HTTP-EQUIV="REFRESH" content="0; url=http://sarjakuva.tuukkavirtaperko.net/?p=<?php echo $newest_post_id ?>">

    Thread Starter Tuukka Virtaperko

    (@complex-buttons)

    Problem solved!

    I thought the value was defined automatically by WordPress. I just copied it from here without really understanding what I was reading. But the thread also contains instructions for defining the value. This code works:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head profile="http://gmpg.org/xfn/11">
    
    <?php $newest_post_id = $posts[0]->ID ?>
    <meta HTTP-EQUIV="REFRESH" content="0; url=http://sarjakuva.tuukkavirtaperko.net/?p=<?php echo $newest_post_id ?>">
    
    </head>
    </html>

    Thanks a lot! I didn’t know how to use echo.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Having index.php redirect to single.php that shows the latest post’ is closed to new replies.