get_template_part( 'content', get_post_format() ); You don’t need to add this code, it’s provided by default in Elegant Themes themes, and most professional themes out there. Thanks.

The most exciting part is being able to dynamically insert content, and in WordPress we do that with The Loop. False and null, cast to strings, equals ''. You can see this approach in action in the Twenty Eleven and Twenty Twelve themes. Evert post format template file should be named content-{post-format}.php. Have you ever noticed a date or category in a blog post? Think get_template_part( 'something', get_query_var( 'paged' ) ) where an integer might be valid.

For example, if the post was set as an image, the content-image.php template would be used. Learned post formats are things like post, attachment etc. content-search.php. Now, imagine you’re working on a child theme. They work perfectly in index.php, search.php, archive.php (I use the code get_template_part('content', get_post_format()) there).. What logic should I write to the single.php to force to use the content-gallery.php with corresponding CSS styles in case I choose the gallery post format? Ok, so my php-pages are content-aside.php, content-gallery.php, content-link.php. You create content.php and content-gallery.php. This is what’s called a ”post meta data” – an important part of a blog post. For example, if the post format is link, the content-link.php is used. In this lesson we learn how to use the "get_template_part()" function to avoid repeating code throughout our theme files. while ( have_posts() ) : the_post(); get_template_part( 'content', get_post_format() ); endwhile; will start the loop and for each post that is retrieved by this loop will be rendered in the frontend using another template named content in the theme's root directory depending upon the post format if available. content-page.php. Pagination generally starts with 1, but you get the idea. So if you want a special template for the aside format, you need only to create a content-aside.php file and start editing the loop’s content … You will have the power to divide your content based on the information that they contain. Now go to Settings > Permalinks.By default, WordPress is set to Day and name, which is a really ugly URL structure.Click on Post name and apply the changes.. With a little bit of WordPress and PHP skills, you can easily follow all the steps yourself.

We've finally made the first dynamic change to the page. With get_template_part(), the child’s content.php can simply replace the parent’s—but since include() and require() pull in files in a “non-WordPress” way, the child theme must instead replace every theme file that uses these template parts, creating huge unnecessary bulk in the child theme. The front end should reflect what you put in your settings. WordPress custom post type is the perfect solution to organize your website, especially if it focuses on more than one subject. Get_template_part pulls a template from a specific PHP file, which can be altered based on post format. Vì mặc định sau này ta sẽ viết CSS cho phần #main-content sẽ hiển thị hơi nhỏ vì nó còn để dành diện tích cho sidebar, nên ta cần thêm một class vào để sau này có thể viết CSS đè lên cho nó giãn ra … Now, create and upload your custom format loops files to the root of your current theme. Likewise, the content-link.php template could be used if the format was set as a link. get_template_part( 'content', get_post_format() ); That will look for files like content-link.php, content-gallery.php and so on, and will always fall back to content.php if none of the others are found. The Loop. Also, don’t forget to add a content.php file as well, because it will be the default file to fall back to as a default.

get_template_part( 'content', get_post_format() ); Which will attempt to include content-gallery.php for gallery post formats, content-quote.php for quote post formats, and so on.

Check out the new WordPress Code Reference! Interested in functions, hooks, classes, or methods? Create a content-competitions.php file; Within the loop in that file, call get_template_part('content-competitions', get_post_format() )' This works, but I'm not sure this is the correct method. 最近研究官方主题 Twenty Eleven ,有一些东西网上现成的中文资料不好找,在博客里记载下来,算是分享,也算是备忘,wordpress 3.0 以后就开始便有了get_template_part() 这个函数 ,应该是为文章呈现形式提供更为多样化的选择而给出的新功能。 The above didn’t work (replacing get_post_format() with get_post_type() crashed WordPress believe it or not) I’m marking the answer as accepted as it guided me towards the solution (add a conditional to the content.php template using get_post_type()).

By finding out the post format using the get_post_format function, the theme allows different types of posts to be displayed as they were attended. Alternatively, if no post format is defined, WordPress simply uses content.php. The get_post_format(); tag within the get_template_part(); automatically picks up the type of post format defined for the post and uses the corresponding template file. Example: content-video.php and content-audio.php. If the particular file doesn’t exist, it will fall back to loading content.php. It helps in providing succinct meta data regarding your blog’s content pieces. Is it necessary to include the whole category-competitions.php file to change that one line, or is there a built in way to achieve this that I am missing?