WordPress.org

Ready to get started?Download WordPress

Forums

Showing news archive on page? (3 posts)

  1. LeLLow
    Member
    Posted 6 years ago #

    I've been trying to set a page called "archives.php" on my site to display all older news, however, I run into errors.

    I copy the code from archives.php on the default theme and paste it into my editor - name it "archives.php" and when I go to preview it I get this error:

    Fatal error: Unknown function: get_header() in /home/minnie/domains/ed-westwick.org/public_html/archives.php on line 1

    I tried changing the get_header to header.php (as well as my footer) so it's like this:

    <?php
    include('header.php');

    But that leaves me with this:

    Parse error: syntax error, unexpected '<' in /home/minnie/domains/ed-westwick.org/public_html/archives.php on line 4

    I can't seem to get it working. I wanted to get my archives like this http://www.scarlett-fan.com/archives.php or this here : http://www.tomcruisefan.com/archives.php .

    Anyone know what I'm doing wrong, how can I fix this?

    Thanks :)

  2. converting2wp
    Member
    Posted 6 years ago #

    The code in archives.php needs to be run in a WordPress context. What that means is

    1. Create the archives.php, modeled on the archives.php from the default theme and a file like index.php or page.php from your current theme. Save it in (or upload it to) the directory with the rest of the files from your theme. [Don't put it in the top level in public_html.]

    2. At the top of archives.php, you'll see code like

    <?php
    /*
    Template Name: Archives
    */
    ?>

    This snippet is important. The template name will be used in the next step.

    3. Login to WordPress and go to the Administration > Write > Page panel and create a new page. Enter a Page Title of Archives and, in the Page Template dropdown on the right, select the template Archives. [If you create other templates, you'd give them different names and use this drop-down to tie them to a page.] Add other text that you want but which isn't included in the archives.php -- or just leave the page body blank. Publish the page.

    4. Browse to http://yoursite.com/archives (not archives.php) and you might not get exactly what you want, but you should get past the "Fatal error" above.

    This Codex page on the Template Hierarchy is useful in figuring out what code will be used to display a particular page.

  3. LeLLow
    Member
    Posted 6 years ago #

    Thanks so much!! :D

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags