Search code examples
phpwordpresswordpress-theming

get_template_part vs the_content?


I have looked at several themes, and I see that "the loop" often works something like this:

while (have_posts()) {
    the_post();
    get_template_part('content');
}

The code that I developed for my theme looks like the following:

while (have_posts()) {
    the_post();
    the_content();
}

My code works as well, and it was something I came up with before I looked at the code for the other themes. I understand that there must be a reason why get_template_part('content') is used, rather than the_content(). I think the reason has something to do with the ability to customize things in a child theme, but I have scrutinized the documentation and the WordPress code, and I can't really figure out what the difference is exactly.

So what is the advantages of using get_template_part('content') overthe_content()?


Solution

  • get_template_part('content') & the_content() both are very different thing for use.

    • the_content() -> this will directly take only content of the editor area of your page from admin to front.

    • get_template_part('content') -> this will call to a file named content.php in your theme folder & take out put from that file, this file may can include html tags too after & before content of editor area.

    in general case for all theme content.php has basic output code of editor, but when you are using any custom template then you may can use the_content() for easiness.