WordPress.org

Ready to get started?Download WordPress

Forums

Page.php vs. Index.php (11 posts)

  1. thebindlestick
    Member
    Posted 7 years ago #

    In the Dark Ritual theme I have both pages of code, but they are identical as far as I can tell... are they both needed and if so, why? These are both in themes/DarkRitual, not at my root.

  2. rudolf45
    Member
    Posted 7 years ago #

    1. Every theme should have an index.php!
    2. page.php is used to display Pages.

    Read: http://codex.wordpress.org/Template_Hierarchy

  3. thebindlestick
    Member
    Posted 7 years ago #

    yes but what is the difference? Which one do I edit to see changes, both? Mine are both the exact same code, why is this?

  4. shovi
    Member
    Posted 7 years ago #

    all I've noticed so far is that the two templates are there so you can alter the way the posts versus pages display in wordpress. for example, you may want to pull out the comments section of a page because you want it to be static content.

  5. Samuel Wood (Otto)
    Tech Ninja
    Posted 7 years ago #

    yes but what is the difference? Which one do I edit to see changes, both? Mine are both the exact same code, why is this?

    thebindlestick: The fact that you're asking these questions suggests that you did not actually read the link that rudolf45 gave you.

    Read this. Really, go read it. It answers all the questions you have asked. all you have to do is to *READ*.
    http://codex.wordpress.org/Template_Hierarchy

    Answering the same questions over and over is annoying. This is why we have documentation.

  6. thebindlestick
    Member
    Posted 7 years ago #

    I did read it, asking the same question gets annoying too.

    What I read tells me that as long as I have my page.php Template in place, and all my other Templates, and home.php or index.php is in the root WP directory, I can delete theme/index.php because it is just there for redundancy, correct?

  7. rudolf45
    Member
    Posted 7 years ago #

    No, not correct. And you don't put template files in the WP root. All the template files live in the theme directory.

  8. Samuel Wood (Otto)
    Tech Ninja
    Posted 7 years ago #

    What I read tells me that as long as I have my page.php Template in place, and all my other Templates, and home.php or index.php is in the root WP directory, I can delete theme/index.php because it is just there for redundancy, correct?

    No, you can't do that. The index.php is the main file. It's the fallback position for everything in the Template Hierarchy.

    WordPress uses the Query String — information contained within each link on your web site — to decide which template or set of templates will be used to display the page.

    First, WordPress matches every Query String to query types — i.e. it decides what type of page (a search page, a category page, the home page etc.) is being requested.

    Templates are then chosen — and web page content is generated — in the order suggested by the WordPress Template hierarchy, depending upon what templates are available in a particular WordPress Theme.

    WordPress looks for template files with specific names in the current Theme's directory and uses the first matching template file it finds that matches the Template Hierarchy.

    With the exception of the basic index.php template file, Theme developers can choose whether they want to implement a particular template file or not. If WordPress cannot find a template file with a matching name, it skips down to the next file name in the hierarchy. If WordPress cannot find any matching template file, index.php (the Theme's home page template file) will be used.

  9. thebindlestick
    Member
    Posted 7 years ago #

    So should I be editing page.php or index.php in my Theme folder, to effect my pages?

  10. rudolf45
    Member
    Posted 7 years ago #

    Pages (with capital P) or just (web)pages?

    (and if you have to ask it - you still didn't read the Codex, so I'll be giving up on you, as a hopeless case...)

  11. t0v3
    Member
    Posted 7 years ago #

    You modify the index.php theme files to change the layout of your index page (surprise surprise) index page being the very first page people see when typing in the url to your domain.

    Pages are used when you create a page in the wordpress admin. They are static pages containing whatever you want. You go to them using yourdomain.com/?page_id=1

    So if you don't plan on using pages, don't modify the page.php file. You will however be using the index, so modify that

Topic Closed

This topic has been closed to new replies.

About this Topic