Support » Themes and Templates » Difference between content-page.php and page.php

  • Resolved janneval

    (@janneval)


    Hi!

    I would like to know what is the difference between following template files in Underscores starter theme (underscores.me)?

    – content.php – single.php
    – content-page.php – page.php
    – content-search.php – search.php
    – content-none – 404.php

    I’m building my theme on Underscores and I would love to through out ALL the unnecessary files. I want to have just few different views:
    1) Single view where the whole post/page is shown
    2) Catergory/archive view with list of post excerpts (front page is also like this)
    3) 404 not found view
    4) search result view

    I would like to have just two template files where one makes one single post/page view and another the excerpt list view.. I’m sure there is reason behind but I just cannot understand why there is so many template files… Anyone can tell me? I cannot find for example content-page.php from the template hierarchy. I tried to read it true but it didn’t help.

    So my question is: What is meaning of those files (content-page.php, content-page.php, content-search.php, content-none.php) and which all files can I remove so that my simple site still works nice and smooth?

Viewing 2 replies - 1 through 2 (of 2 total)
  • all those content-{???}.php template files might get called by some templates, possibly via a get_template_part( 'content', '?????' ) code; in which case, you cannot delete them.

    check the codes of page.php, search.php, index.php etc…

    http://codex.wordpress.org/Function_Reference/get_template_part

    Yeah.. thats what I tried to do, look though the code, but then I tired of it and found a better way: I simply deleted one by one plenty of those files which I didn’t understand. :))

    Before doing it I added to the beginning of each file something like <strong>echo 'This is index.php.';</strong> where index.php was replaced by the name of that file where I added it. Then I could see from my site exactly which template files where called in different cases.. (Front page, archives, single post view etc..)

    WordPress is really a smart thing! If it has no one file, it replaces it with another. For example normally to load a view of a single page, it used following files:
    functions.php,
    page.php,
    header.php,
    content-page.php,
    sidebar.php
    and footer.php.

    But if I remove page.php, it uses more general index.php to replace it. And if I remove content-page.php, it uses more general content.php on it’s place. So I CAN remove them, no harm!

    Only thing removing these files make is that without them I cannot specify for example that content of the page is shown in different way than the content of a post. Now all content is shown in the same way. But that’s ok for me! I can always add them again if needed or add CSS that makes difference between a page and a post.

    Thank you alchymyth for a good option. I’m sure I could have found it out that way too. This way was just faster.

    And thank me for a nice solution. Topic resolved. 🙂

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Difference between content-page.php and page.php’ is closed to new replies.