Forums

WP code not working (2 posts)

  1. iTal
    Member
    Posted 2 years ago #

    Hi all,

    I'm new to WP and PHP as well. Therefore, I'm sorry in advance for the newbie question.

    I tried to used the code below in order to show a list of my posts on a page called blog-example.php. However, nothing is displayed on the page. What am I doing wrong?

    Details:
    The blog-example.php file is in the root folder and the blog folder is there as well.
    When I view source it seems like it encounters an error after it requires the wp-blog-header.php file.

    //blog-example.php code:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    </head>
    <body>
    
    <?php
    require('blog/wp-blog-header.php');
    ?>
    
    <?php
    $posts = get_posts('numberposts=10&order=ASC&orderby=post_title');
    foreach ($posts as $post) : start_wp(); ?>
    <?php the_date(); echo "<br />"; ?>
    <?php the_title(); ?>
    <?php the_excerpt(); ?>
    <?php
    endforeach;
    ?>
    </body>
    </html>

    I thank you all for your help

  2. iridiax
    Member
    Posted 2 years ago #

    A custom page template file goes in your chosen theme's folder and it requires some special template code:

    http://codex.wordpress.org/Pages#Creating_Your_Own_Page_Templates

    The easiest way to do it is to just duplicate and rename your current theme's page.php and then add your custom code and the special template code.

Topic Closed

This topic has been closed to new replies.

About this Topic