Forums

[resolved] Having index.php redirect to single.php that shows the latest post (3 posts)

  1. Tuukka Virtaperko
    Member
    Posted 1 year ago #

    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?

  2. alchymyth
    The Sweeper
    Posted 1 year ago #

    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 ?>">

  3. Tuukka Virtaperko
    Member
    Posted 1 year ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic