• Resolved SusanaMPL

    (@susanampl)


    Hello, first of all, sorry for my english.
    I’ve searched the forums in English and Spanish, the internet and I’ve also reviewed several themes( cotango , twentyfourteen , twentythirteen , twentytwelve , thebootstrap ) but I don’t understand the difference between single.php and content.php .
    In the three themes index.php use the function:
    < php get_template_part ( 'content' , get_post_format ()); ? >
    In The Bootstrap changes a little but it does the same.
    I understand that this function calls a file to load the content of a single post, sometimes differentiating between types of posts.
    If this is so, what is the function of single.php file? file which is present in every themes I’ve revised; according I’ve read in the documentation, single.php is used to display the content of a post ( what he does content.php ).
    Moreover, in all the reviewed themes, single.php has the function get_template_part used to load another template, content-postformat.php, and I can’t find from where they call the single.php file in any of the themes.

    If someone could explain the difference I would greatly appreciate it .

    And if noone can understand what I can say, please, erase the question.

    Thanks and sorry.

Viewing 3 replies - 1 through 3 (of 3 total)
  • single.php is loaded automatically by WordPress for single posts. Have you reviewed the theme template hierarchy in Theme Development? I think it will become a lot clearer once you understand the hierarchy.

    Hello SusanaMPL,

    The function of the single.php template is used when viewing a single instance of a WordPress post type. It is a standard file that will get called by the template hierarchy system.

    Template Hierarchy

    Diagram

    If you follow the diagram you can see when the single.php file will get used in your theme.

    One reason themes will load a separate template for the content inside of the single.php is to accommodate for multiple post types.

    For example in your theme if you had 5 post types that when viewed singly they all had a sidebar and an ad placement. You could add all of the code for the sidebar and the add placement inside the single.php file.

    Then for each of your post types you could have a completely different layout by using the get_template_part function inside the single.php. This way you would not have to duplicate the sidebar and ad placement inside a template for each post type.

    Hope that helps!

    Thread Starter SusanaMPL

    (@susanampl)

    Simalam thank you very much, I have reviewed the files and you’re right, I haven’t realized that, content-postFormat.php don’t have get_header and cia.
    Really, thank you very much.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘What is the difference between single.php and content.php’ is closed to new replies.