WordPress single post templates

New Page

Navegar: Inicio / Manual de temas / Sección de archivos de plantilla / Archivos de plantilla de publicaciones

Publicar archivos de plantilla

Themes

  • Index.php
  • Home.php
  • Soltero.php
  • Singular.php
  • Archive.php
  • Author.php and Fecha.php
    • Author.php
    • Fecha.php
  • Category.php, Etiqueta.php and Taxonomy.php
  • Buscar.php

Hay a lot of plantilla archives that utiliza WordPress to display post type of post. Cualquier content related with a blog where this publication is at the bottom of the type of publication Publicación.

Index.php

index.phpmostrará los tipos de publication de publicaciones si no hay otro archivo de plantilla en su lugar. Como se indica en muchos lugares, cada tema debe tener un index.phparchivo para ser válido. Many basic themes can be consulted with the suya simply by using index.phppara mostrar sus tipos de publicaciones, pero los casos de uso dados anteriormente justificarían la creation de otros archivos de plantilla.

A menudo querrá una estructura o diseño de contenido único dependiendo de lo que se muestre. Hay muchas plantillas que puede usar para personalizar la estructura del contenido según el contexto dentro del sitio. Los dos archivos de plantilla de publication más notables son home.phpy single.phpque muestran una fuente de publicaciones y una sola publication, respectively.

Arrive ↑

Home.php

Cuando se usa a static main page y el site tiene a page defined for the list of blogs, el home.phparchivo se usa for the page of list of blogs designed. If you recommend the use of this plantilla in order to create a page personalized page because the page of the blog in a page page personalized no funcionará correctly. If no hay home.phpen el tema index.phpse utilizará en su lugar.

Arrive ↑

Soltero.php

You will want to build the simplest way possible in the structure of your plant and do not worry more plants unless you really need it. However, the town hall of los desarrolladores de themes is not created in the single-post.php archive for single.php es lo suficientemente específico. In its main part, all themes deben hold a single.php archive. A continuation will show a sample of a single.phparchivo del theme Twenty Fifteen.

<?php /** * La plantilla para mostrar todas las individuales publications y adjuntos archivos * * @paquete WordPress * @subpaquete veinte_quince * @desde Veinticinco Quince 1.0 */ obtention_encabezado(); ?> <div id=”primaria” clase=”content area”> <id principal=”principal” clase=”sitio-principal” rol=”principal”> <?php // Inicia el bucle. while ( have_posts() ): the_post(); /* * Includes the specific plantilla del formato de publication para el contenido. If quieres * use esto in a secundario tema, you will include an archivo llamado content-___.php * (donde ___ es el formato de publication) y ese se se usará en su lugar. */ get_template_part(‘content’, get_post_format() ); // If los comments están abiertos o tenemos al menos a comment, load the plantilla of comments. if (comments_abiertos() || get_comments_number() ): comments_plantilla(); will end if; // Navegación de publication anterior/siguiente. la_post_navegación( matriz( ‘next_text’ => ‘<span class=”meta-nav” aria-hidden=”true”>’ . __( ‘Siguiente’, ‘veinticinco’) . ‘</span>’. ‘<span class=”screen-reader-text”>’.__(‘Próxima publicación:’, ‘veinticinco’) .'</span>’.'<span class=”post-title”>%título</span>’ , ‘prev_text’ => ‘<span class=”meta-nav” aria-hidden=”true”>’.__(‘Previous’, ‘veinticinco’) .'</span>’.'<span class=” screen-reader-text”>’ . __( ‘Publicación anterior:’, ‘veinticinco’) . ‘</span>’. ‘<span class=”post-title”>%title</span>’, ) ); // Finalize the loop. mientra tanto; ?> </main><!– .site-main –> </div><!– .content area –> <?php get_pie from page(); ?>

In the sample code above, you can see that the header is inserted with get_header() and then there are two html tags. Then the loop starts and the template tag get_template_part( ‘content’, get_post_format()); extracts the appropriate content by determining the post type with get_post_format(). Then the comments are extracted with the comments_template() template tag. Then there is pagination. Finally, the content divs are closed, then the footer is inserted with get_footer().

Arrive ↑

Singular.php

WordPress version 4.3 added singular.php which comes in the hierarchy after single.php for posts, page.php for pages and variations of each. This pattern follows the rules of is_singular() and is used for a single message, regardless of message type. Themes that used the same code for these two files (or included in each other) can now be simplified into a single template.

Arrive ↑

Archive.php

Unless a developer includes meta data with permalinks in their templates, the archive.php will not be used. Meta data is information tied to the post. For example the date something was posted on, the author, and any categories, tags, or taxonomies used for the post are all examples of meta data. When a visitor to a website clicks on the meta data, the archive.php will render any posts associated with that piece of meta data. For example, if a visitor clicks on the name of an author, the archive.php will display all posts by that author.

Généralement, le titre de la page affichée par archive.php sera le nom des métadonnées sur lesquelles l’utilisateur a cliqué. Ainsi, si l’utilisateur a cliqué sur le nom de l’auteur, le nom de la page affichant tous les messages de l’autre auteur sera le nom de l’auteur et il peut souvent y avoir une description supplémentaire des métadonnées. Voici un exemple de code de Twenty Fifteen sur leur fichier archive.php. Cet extrait est le seul morceau de code qui différencie le fichier archive.php d’un fichier home.php ou index.php.

<header class=”page-header”> <?php the_archive_title( ‘<h1 class=”page-title”>’, ‘</h1> ‘ ); the_archive_description( ‘<div class=”taxonomy-description”>’, ‘</div> ‘ ); ?> </header> <!– .page-header –>

Arrive ↑

Author.php and Fecha.php

Author.php and date.php are more specific archive type files. If you need a refresher check out where they fit within the template heirarchy. Generally, archive.php will suffice for most themes’ needs and you won’t need to create these templates.

Arriba ↑

Author.php

If you are building a theme designed for multiple authors, it might make sense to build an author.php template. In the author.php template you could provide more information about an author, their gravatar, pull in their social media sites, and then all posts written by them. This would be a step up from relying just on the archive.php file.

Additionally, you can build specific author.php files for individual author’s by using their author ID or nicename. For example, say John Doe is the head author for a site with many guest authors. You may want all the guest authors’ information to display with author.php but you might build a specific author page with more information for John Doe by creating author-johndoe.php or author-3.php if his author ID is 3.

Arriba ↑

Fecha.php

Similarly, if you are building a theme directed at magazine or news websites, a date.php file might make sense to build as these websites frequently organize their articles and posts by date or issue. Additionally, you could build a day.php, month.php, or year.php if you found enough justification for it.

Arriba ↑

Categoría.php, Etiqueta.php y Taxonomía.php

If you need a refresher on what categories, tags, & taxonomies are you can look at their page. Often you won’t need to build out these template files. However, in an example of building a theme for food bloggers, there are some use cases for building these specific templates. In a food blogger website, the categories could be Great Restaurants, Beautiful Food, Ethnic Cuisine, and Recipes.

You might want most of your blog posts to display the same way except for any blogs that are categorized as recipes, because all recipes have ingredients and instrucitons sections. Therefore, you may want to build a category-recipe.php file to display your recipe blog posts in a grid view with some of the important details about the recipe visible.

De plus, le chocolat est peut-être une étiquette très importante pour le thème que vous construisez. Il peut être judicieux de créer un fichier tag-chocolate.php afin que vous puissiez afficher une image de bannière spécialisée de chocolat.

Arribe ↑

Buscar.php

Most themes have a search.php file so users are clear that their request went through. It’s common to have some sort of header identifying the query results, like this snippet found in the twenty fifteen topic.

<header class=”page-header”> <h1 class=”page-title”><?php printf( __( ‘Search results for: %s’, ‘twentyfifteen’ ), get_search_query() ); ?></h1> </header> <!– .page-header –>

This code snippet pulls in the query that was searched with get_search_query(). Often search.php will only pull in the excerpt instead of the full content since the user is trying to determine if the article or page fits their search.

 

navigation handbook

← Template Files Section Page Templates →

How to Create Custom Single Post Templates in WordPress

Last updated on September 1st, 2022 by Editorial Staff | Reader DisclosureDisclosure: Our content is reader-supported. This means if you click on some of our links, then we may earn a commission. See how WPBeginner is funded, why it matters, and how you can support us.

Comparte 1k Cuota Pío Cuota Facebook Messenger WhatsApp Correo electrónico

Do you want to create a custom single post template in WordPress?

Custom single post templates allow you to use different layouts for your individual blog posts. Many WordPress themes come with a few different page templates, and you can also create your own if needed.

In this article, we’ll show you how to easily create custom single post templates in WordPress. We’ll share multiple methods, so you can choose one that works best for your needs.

How to create personalized plantillas of unified publications in WordPress How to Create Custom Single Post Templates in WordPress

When Do You Need a Custom Single Post Template?

Sometimes you may want a different look and feel for certain posts on your WordPress website. For instance, you may want to use a different layout for featured articles or stories in a particular category.

This is where you need a custom single post template in WordPress.

By default, WordPress uses the single post template based on the WordPress template hierarchy. All themes come with a single.php template, and this is used by default for all of your single posts.

Some themes may also include additional templates or layout choices that you can use.

It is very much like creating a custom page template. Most WordPress themes also come with page templates that you can use while editing a post or page in WordPress.

Elect a plantilla de página Choosing a Page Template

Having said that, let’s take a look at how to easily create custom single post templates in WordPress. We’ll show you multiple methods, so you can use the one that works best for you.

  • Creating single post templates using the block editor
  • Creating custom single post templates using SeedProd
  • Using theme settings to create single post layouts
  • Manually creating custom single post templates with code
  • Creating custom single post templates by category
  • Creating custom single post templates for specific authors

Creating Single Post Templates Using the Block Editor

This method does not really create a post template and is limited in flexibility. However, it is the easiest way to save your own single post layouts and then reuse them.

The default WordPress block editor comes with a built-in feature that allows you to save and reuse blocks. One such reusable block is the group block.

The group block allows you to put several blocks and entire post layouts into one group. You can then save this group block and reuse it in your other posts.

Let’s take a look at how to use the group block to save your custom post templates.

First, you need to create a new post in WordPress. After that, simply add a group block to the content area.

Add Group Block Add Group Block

Now you can start adding blocks into the group block to create a single post layout for your WordPress blog.

You can add any blocks you want including columns, media and text, cover images, and more.

Add Blocks to the Group Add Blocks to the Group

Once you are satisfied with the layout you have created, you need to take your mouse up and select the group block.

Simply click on the three-dot menu icon and then select the ‘Add to Reusable blocks’ option.

Add Reusable Block Add Reusable Block

Next, you need to provide a name for the reusable block and then click on the Save button. WordPress will now save your reusable block including all the blocks inside the group block.

You can then edit any existing post on your website or create a new one. On the post edit screen, simply click on the add new block button and look for your saved block under the ‘Reusable’ tab.

Reuse Block Reuse Block

Add the block to your post and WordPress will load your entire group block with all the blocks and settings as you saved them.

This method allows you to save your custom layouts. However, it does not allow you to change how your theme handles single posts.

If you would like greater flexibility, then continue reading the next step.

Creating Custom Single Post Templates Using SeedProd

The easiest way to create a custom single post template is by using SeedProd. It’s the best WordPress website builder plugin and can create beautiful website layouts and custom templates without writing any code.

You can use SeedProd’s drag-and-drop builder to create a fully custom WordPress theme, including custom single post templates.

The first thing you need to do is install and activate the SeedProd plugin. For more details, see our step by step guide on how to install a WordPress plugin.

Upon activation, you need to enter your license key. You can find this information under your account on the SeedProd website.

SeedProd license key SeedProd license key

After that, it’s time to create a custom WordPress theme. This is much simpler than it sounds.

Creating a Custom WordPress Theme

First, you need to head over to the SeedProd » Theme Builder page. Here, you’ll use one of SeedProd’s ready-made themes as a starting point. This will replace your existing WordPress theme with a new, custom design.

You can do that by clicking the ‘Themes’ button.

Create your custom theme Create your custom theme

You will be shown a list of professionally designed themes that are designed for different types of websites. For example, there are templates called ‘Modern Business’, ‘Marketing Agency’, and ‘Mortgage Broker Theme’.

Take a look through the options and select one that best matches your needs by clicking the checkmark icon.

Select a Theme That Matches Your Needs Select a Theme That Matches Your Needs

Once you have chosen a theme, SeedProd will generate all the theme templates you need, including one for single pages and another for single posts.

Each template comes set up with attractive layouts and placeholder content that’s easy to customize.

SeedProd Creates All the Templates You Need for Your Theme SeedProd Creates All the Templates You Need for Your Theme

To learn more about creating a theme with SeedProd, see our guide on how to easily create a custom WordPress theme without any code.

Customizing the Default Single Post Template

SeedProd makes it easy to customize the default ‘Single Post’ template using a drag and drop page builder.

Simply click the ‘Edit Design’ link found under the template. This will open your post template in SeedProd’s visual editor.

Click the 'Edit Design' Link Under the Single Post Template Click the 'Edit Design' Link Under the Single Post Template

SeedProd’s visual editor has a 2 column layout. On the left, you’ll find blocks and sections that you can add to your design. And on the right is a preview of the template where you can see your changes in real-time.

SeedProd Visual Editor Blocks and Sections SeedProd Visual Editor Blocks and Sections

It’s also easy to customize the layout of your post template. Simply click on any block to see its settings in the left column.

For example, if you click on the post title, then you’ll be able to see its settings. Now you can change the alignment, font size, heading level, and more.

Click on a Block to Change Its Settings Click on a Block to Change Its Settings

Clicking the Advanced tab lets you change font colors, spacing, and other styles.

You can add additional blocks by dragging them from the left column into the preview column. SeedProd uses template tags to pull in dynamic content like post titles, featured images, comments, and more. This lets you add content to the template without having to edit each post individually.

For example, you can add a Posts block at the end of your post content. This will display recent posts that your visitors may wish to read when they finish the current post. This block will be shown automatically on all posts using this template.

Add a Posts Block to the Bottom of Your Single Posts Template Add a Posts Block to the Bottom of Your Single Posts Template

Next, you can change the settings of the Posts block to customize the content that is shown.

For example, you can display content from specific categories, use a two-column layout, and change the number of posts that are shown.

SeedProd Posts Block Settings SeedProd Posts Block Settings

Feel free to spend time experimenting with different blocks and exploring their settings.

After creating something you’d like to use as your post template, it is time to save it by clicking the green ‘Save’ button in the top right corner. After that, you can close the SeedProd visual editor by clicking the ‘X’ close icon.

When You're Finished, Save the Single Post Template When You're Finished, Save the Single Post Template

You can customize the rest of your WordPress theme in the same way. But if you need a little help, then refer back to our step-by-step guide on how to create a custom WordPress theme with SeedProd.

When you’re happy with how everything looks, make sure the ‘Enable SeedProd Theme’ switch is toggled to the on position. Your WordPress site will now use your SeedProd theme and custom single post template.

Enable the SeedProd Theme Enable the SeedProd Theme

Using Theme Settings to Create Custom Single Post Layouts

Many popular WordPress themes come with built-in settings to customize the appearance of your single post template.

If your theme supports these settings, then you’ll be able to find them on the post edit screen. The options available may change depending on the theme you are using.

For instance, the Astra theme offers customization options when editing a single post. Using these options, you can change sidebars, hide headers, title, menus, and more.

Astra Theme Single Post Template Customization Astra Theme Single Post Template Customization

On the other hand, many of the top WordPress themes come with ready-to-use templates that you can use.

If your theme includes single post templates, then you will find them under the ‘Template’ or ‘Post Attributes’ panel while editing a post.

Choosing a Template When Writing a Single Post Choosing a Template When Writing a Single Post

These templates are complete layouts that you can use with no configuration required.

Manually Creating Custom Single Post Templates With Code

This method is a bit advanced as it requires you to edit theme files, copy and paste code, and optionally add custom CSS. If you haven’t done this before, then check out our tutorial on how to copy and paste code in WordPress.

First, you need to open a plain text editor on your computer like Notepad and paste the following code inside it:

1

2

3

4

5

6

7

<?php

/*

  * Template Name: Featured Article

  * Template Post Type: post, page, product

  */

   

  get_header();  ?>

This code defines a new template called ‘Featured Article’ and makes it available for post, page, and product post types.

You should save this file as wpb-single-post.php on your desktop. Next, you need to add the template to your WordPress site. To do that, you need to use an FTP client to upload the file to your current theme folder.

Now you can log in to your WordPress admin area and create or edit a post. Scroll down a little on the post edit screen, and you will notice a new ‘Template’ panel or ‘Post Attributes’ meta box with an option to select the template.

Select Your Custom Post Template Select Your Custom Post Template

You will see your ‘Featured Article’ custom template listed there.

Right now your template is essentially empty so selecting it will simply display a white screen.

Let’s fix this.

The easiest way to do that is by copying the code from your theme’s single.php file and using it as a starting point. You’ll have to open the single.php file and then copy everything after the get_header() line.

Next, you need to paste this code at the end of your wpb-single-post.php file. Now you can save this file and upload it back to your server.

However, this will look exactly the same as your current single post template. You can now start making changes to your custom single post template.

You can add your own custom CSS classes, remove sidebars, create a full width template, or anything you want.

Creating Custom Single Post Templates by Category

Would you like to use a custom single post template based on categories? For example, you can give posts in the travel category a different layout to posts in the photography category.

You can do that using either the SeedProd Theme Builder or code.

Creating Custom Single Post Templates by Category Using SeedProd

Earlier we covered how to customize the SeedProd Theme Builder’s default single post template. But it doesn’t stop there. With SeedProd you can add as many custom post templates as you like, such as a different layout for every post category.

To add a new single post template, just click the ‘Duplicate’ link under the original post template. A new template called ‘Single Post – Copy’ will be created and added to the top of the theme templates page.

Create a New Post Template by Duplicating the Default Post Template Create a New Post Template by Duplicating the Default Post Template

You can customize the new template in the same way you customized the default Single Post template earlier. Simply click the template’s ‘Edit Design’ link and make any changes you like using SeedProd’s visual editor.

When you’ve finished customizing the template, you will need to add some conditions so that SeedProd will know which posts should use this template. In this case, we want it displayed when viewing posts within a single category.

Click the 'Edit Conditions' Link Click the 'Edit Conditions' Link

You can do that by clicking the template’s ‘Edit Conditions’ link and a new window will pop up.

Here you can give the template a name and priority. The default Single Post template has a priority of 0, so make sure you give this template a higher priority so it will be displayed on matching categories.

Add Conditions to Display the Template for a Certain Category Add Conditions to Display the Template for a Certain Category

Under ‘Conditions’, select ‘Has Category’ from the second drop down menu, then type the name of the category in the last field. For example, if you only want posts from the photography category to use this layout, then type ‘photography’.

When you’re finished, click the ‘Save’ button and now this template will be used for all posts in the matching category.

This is the easiest way to create multiple custom post templates in WordPress. It doesn’t require any knowledge of code and won’t accidentally mess up any theme files.

Creating Custom Single Post Templates by Category Using Code

This is another method for those who are comfortable adding code to their theme files.

First, you need to add this code to your theme’s functions.php file or a code snippets plugin.

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

/*

* Define a constant path to our single template folder

*/

define(SINGLE_PATH, TEMPLATEPATH . ‘/single’ );

  

/**

* Filter the single_template with our custom function

*/

add_filter( ‘single_template’ , ‘my_single_template’ );

  

/**

* Single template function which will choose our template

*/

function my_single_template( $single ) {

global $wp_query , $post ;

  

/**

* Checks for single template by category

* Check by category slug and ID

*/

foreach (( array )get_the_category() as $cat ) :

  

if ( file_exists (SINGLE_PATH . ‘/single-cat-‘ . $cat ->slug . ‘.php’ ))

return SINGLE_PATH . ‘/single-cat-‘ . $cat ->slug . ‘.php’ ;

  

elseif ( file_exists (SINGLE_PATH . ‘/single-cat-‘ . $cat ->term_id . ‘.php’ ))

return SINGLE_PATH . ‘/single-cat-‘ . $cat ->term_id . ‘.php’ ;

  

endforeach ;

}

This code first checks to see if WordPress is requesting a single post. If it is, then it tells WordPress to look for the template in the /single/ folder of your WordPress theme.

Now you need to add template files defined by this code.

Connect to your WordPress hosting using an FTP client or File Manager in cPanel and go to /wp-content/themes/your-theme-folder/.

Inside your current theme folder, you need to create a new folder called ‘single’. Next, you need to open this folder and create a new file inside it. Go ahead and name this file single-cat-{category-slug}. Replace {category-slug} with your actual category slug.

For example, if you have a category called ‘News’, then you will create single-cat-news.php file. If you have a category called ‘Travel Tips’, then create a template single-cat-travel-tips.php, and so on.

Creating Single Post Template for Categories Creating Single Post Template for Categories

Now, these template files will be totally empty. As a starting point, you can copy the contents of your single.php file from your theme folder and paste them inside each of these templates. After that, you’ll need to edit these templates to make your desired changes.

Une fois que vous avez terminé, vous pouvez accéder à votre site Web et afficher un message. Il utilisera le modèle que vous avez créé pour la catégorie dans laquelle ce message est classé.

Supposons maintenant que vous ayez un message classé dans deux catégories Nouvelles et Conseils de voyage. WordPress affichera automatiquement le modèle pour “Actualités” car il apparaît en premier dans l’ordre alphabétique.

D’un autre côté, si vous avez déposé un article dans une catégorie et que vous n’avez pas créé de modèle pour cette catégorie, WordPress reviendra au modèle par défaut single.php de votre thème.

Création de modèles de publication uniques personnalisés pour des auteurs spécifiques

Suppose you want articles written by a specific author to look different on your website. You can do this using code following the same technique we showed for categories.

First, you need to add this code to your theme’s functions.php file or to a

code snippets plugin.

1

2

3

4

5

6

seven

8

9

ten

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

/**

* Define a constant path to our single template folder

*/

define(SINGLE_PATH, TEMPLATEPATH.’/single’);

  

/**

* Filter the single_template with our custom function

*/

add_filter(‘single_template’, ‘my_single_author_template’);

  

/**

* Single template function which will choose our template

*/

function my_single_author_template( $single ) {

global $wp_query, $post;

  

/**

* Checks for single template by author

* Check by user nicename and ID

*/

$curauth = get_userdata( $wp_query ->post->post_author);

  

if ( file_exists (SINGLE_PATH . ‘/single-author-‘ . $curauth ->user_nicename . ‘.php’ ))

return SINGLE_PATH . ‘/single-author-‘ . $curauth ->user_nicename . ‘.php’ ;

  

elseif ( file_exists (SINGLE_PATH . ‘/single-author-‘ . $curauth ->ID . ‘.php’ ))

return SINGLE_PATH . ‘/single-author-‘ . $curauth ->ID . ‘.php’ ;

  

}

Next, you should connect to your website using FTP or cPanel file manager in cPanel and then go to /wp-content/themes/your-theme-folder/. If you haven’t already created a folder called /single/ inside it, then go ahead and create it now.

Inside this folder, you need to create a template using the author’s username in the template name. For example, single-author-johnsmith.php.

This template will be empty, so you can copy and paste the contents of your theme’s single.php template and use it as a starting point.

You can now visit your website to view a post created by a specific author. It will use the template you created.

We hope this article helped you learn how to create custom single post templates in WordPress. You may also want to learn how to track website visitors to your WordPress site, or see our list of must have WordPress plugins to grow your site.

If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

Comparte 1k Cuota Pío Cuota Facebook Messenger WhatsApp Correo electrónico

How to Create Custom Single Post Templates in WordPress

Last updated on September 1st, 2022 by Editorial Staff | Reader DisclosureDisclosure: Our content is reader-supported. This means if you click on some of our links, then we may earn a commission. See how WPBeginner is funded, why it matters, and how you can support us.

Comparte 1k Cuota Pío Cuota Facebook Messenger WhatsApp Correo electrónico

Do you want to create a custom single post template in WordPress?

Custom single post templates allow you to use different layouts for your individual blog posts. Many WordPress themes come with a few different page templates, and you can also create your own if needed.

In this article, we’ll show you how to easily create custom single post templates in WordPress. We’ll share multiple methods, so you can choose one that works best for your needs.

How to Create Custom Single Post Templates in WordPress How to Create Custom Single Post Templates in WordPress

When Do You Need a Custom Single Post Template?

Sometimes you may want a different look and feel for certain posts on your WordPress website. For instance, you may want to use a different layout for featured articles or stories in a particular category.

This is where you need a custom single post template in WordPress.

By default, WordPress uses the single post template based on the WordPress template hierarchy. All themes come with a single.php template, and this is used by default for all of your single posts.

Some themes may also include additional templates or layout choices that you can use.

It is very much like creating a custom page template. Most WordPress themes also come with page templates that you can use while editing a post or page in WordPress.

Choosing a Page Template Choosing a Page Template

Having said that, let’s take a look at how to easily create custom single post templates in WordPress. We’ll show you multiple methods, so you can use the one that works best for you.

  • Creating single post templates using the block editor
  • Creating custom single post templates using SeedProd
  • Using theme settings to create single post layouts
  • Manually creating custom single post templates with code
  • Creating custom single post templates by category
  • Creating custom single post templates for specific authors

Creating Single Post Templates Using the Block Editor

This method does not really create a post template and is limited in flexibility. However, it is the easiest way to save your own single post layouts and then reuse them.

The default WordPress block editor comes with a built-in feature that allows you to save and reuse blocks. One such reusable block is the group block.

The group block allows you to put several blocks and entire post layouts into one group. You can then save this group block and reuse it in your other posts.

Let’s take a look at how to use the group block to save your custom post templates.

First, you need to create a new post in WordPress. After that, simply add a group block to the content area.

Add Group Block Add Group Block

Now you can start adding blocks into the group block to create a single post layout for your WordPress blog.

You can add any blocks you want including columns, media and text, cover images, and more.

Add Blocks to the Group Add Blocks to the Group

Once you are satisfied with the layout you have created, you need to take your mouse up and select the group block.

Simply click on the three-dot menu icon and then select the ‘Add to Reusable blocks’ option.

Add Reusable Block Add Reusable Block

Next, you need to provide a name for the reusable block and then click on the Save button. WordPress will now save your reusable block including all the blocks inside the group block.

You can then edit any existing post on your website or create a new one. On the post edit screen, simply click on the add new block button and look for your saved block under the ‘Reusable’ tab.

Reuse Block Reuse Block

Add the block to your post and WordPress will load your entire group block with all the blocks and settings as you saved them.

This method allows you to save your custom layouts. However, it does not allow you to change how your theme handles single posts.

If you would like greater flexibility, then continue reading the next step.

Creating Custom Single Post Templates Using SeedProd

The easiest way to create a custom single post template is by using SeedProd. It’s the best WordPress website builder plugin and can create beautiful website layouts and custom templates without writing any code.

You can use SeedProd’s drag-and-drop builder to create a fully custom WordPress theme, including custom single post templates.

The first thing you need to do is install and activate the SeedProd plugin. For more details, see our step by step guide on how to install a WordPress plugin.

Upon activation, you need to enter your license key. You can find this information under your account on the SeedProd website.

SeedProd license key SeedProd license key

After that, it’s time to create a custom WordPress theme. This is much simpler than it sounds.

Creating a Custom WordPress Theme

First, you need to head over to the SeedProd » Theme Builder page. Here, you’ll use one of SeedProd’s ready-made themes as a starting point. This will replace your existing WordPress theme with a new, custom design.

You can do that by clicking the ‘Themes’ button.

Create your custom theme Create your custom theme

You will be shown a list of professionally designed themes that are designed for different types of websites. For example, there are templates called ‘Modern Business’, ‘Marketing Agency’, and ‘Mortgage Broker Theme’.

Take a look through the options and select one that best matches your needs by clicking the checkmark icon.

Select a Theme That Matches Your Needs Select a Theme That Matches Your Needs

Once you have chosen a theme, SeedProd will generate all the theme templates you need, including one for single pages and another for single posts.

Each template comes set up with attractive layouts and placeholder content that’s easy to customize.

SeedProd Creates All the Templates You Need for Your Theme SeedProd Creates All the Templates You Need for Your Theme

To learn more about creating a theme with SeedProd, see our guide on how to easily create a custom WordPress theme without any code.

Customizing the Default Single Post Template

SeedProd makes it easy to customize the default ‘Single Post’ template using a drag and drop page builder.

Simply click the ‘Edit Design’ link found under the template. This will open your post template in SeedProd’s visual editor.

Click the 'Edit Design' Link Under the Single Post Template Click the 'Edit Design' Link Under the Single Post Template

SeedProd’s visual editor has a 2 column layout. On the left, you’ll find blocks and sections that you can add to your design. And on the right is a preview of the template where you can see your changes in real-time.

SeedProd Visual Editor Blocks and Sections SeedProd Visual Editor Blocks and Sections

It’s also easy to customize the layout of your post template. Simply click on any block to see its settings in the left column.

For example, if you click on the post title, then you’ll be able to see its settings. Now you can change the alignment, font size, heading level, and more.

Click on a Block to Change Its Settings Click on a Block to Change Its Settings

Clicking the Advanced tab lets you change font colors, spacing, and other styles.

You can add additional blocks by dragging them from the left column into the preview column. SeedProd uses template tags to pull in dynamic content like post titles, featured images, comments, and more. This lets you add content to the template without having to edit each post individually.

For example, you can add a Posts block at the end of your post content. This will display recent posts that your visitors may wish to read when they finish the current post. This block will be shown automatically on all posts using this template.

Add a Posts Block to the Bottom of Your Single Posts Template Add a Posts Block to the Bottom of Your Single Posts Template

Next, you can change the settings of the Posts block to customize the content that is shown.

For example, you can display content from specific categories, use a two-column layout, and change the number of posts that are shown.

SeedProd Posts Block Settings SeedProd Posts Block Settings

Feel free to spend time experimenting with different blocks and exploring their settings.

After creating something you’d like to use as your post template, it is time to save it by clicking the green ‘Save’ button in the top right corner. After that, you can close the SeedProd visual editor by clicking the ‘X’ close icon.

When You're Finished, Save the Single Post Template When You're Finished, Save the Single Post Template

You can customize the rest of your WordPress theme in the same way. But if you need a little help, then refer back to our step-by-step guide on how to create a custom WordPress theme with SeedProd.

When you’re happy with how everything looks, make sure the ‘Enable SeedProd Theme’ switch is toggled to the on position. Your WordPress site will now use your SeedProd theme and custom single post template.

Enable the SeedProd Theme Enable the SeedProd Theme

Using Theme Settings to Create Custom Single Post Layouts

Many popular WordPress themes come with built-in settings to customize the appearance of your single post template.

If your theme supports these settings, then you’ll be able to find them on the post edit screen. The options available may change depending on the theme you are using.

For instance, the Astra theme offers customization options when editing a single post. Using these options, you can change sidebars, hide headers, title, menus, and more.

Astra Theme Single Post Template Customization Astra Theme Single Post Template Customization

On the other hand, many of the top WordPress themes come with ready-to-use templates that you can use.

If your theme includes single post templates, then you will find them under the ‘Template’ or ‘Post Attributes’ panel while editing a post.

Elegir una plantilla al escribir una sola publicación Choisir un modèle lors de la rédaction d'un seul article

These templates are complete layouts that you can use with no configuration required.

Manually Creating Custom Single Post Templates With Code

This method is a bit advanced as it requires you to edit theme files, copy and paste code, and optionally add custom CSS. If you haven’t done this before, then check out our tutorial on how to copy and paste code in WordPress.

First, you need to open a plain text editor on your computer like Notepad and paste the following code inside it:

1

2

3

4

5

6

7

<?php

/*

  * Template Name: Featured Article

  * Template Post Type: post, page, product

  */

   

  get_header();  ?>

This code defines a new template called ‘Featured Article’ and makes it available for post, page, and product post types.

You should save this file as wpb-single-post.php on your desktop. Next, you need to add the template to your WordPress site. To do that, you need to use an FTP client to upload the file to your current theme folder.

Now you can log in to your WordPress admin area and create or edit a post. Scroll down a little on the post edit screen, and you will notice a new ‘Template’ panel or ‘Post Attributes’ meta box with an option to select the template.

Seleccione su plantilla de publicación personalizada Sélectionnez votre modèle de publication personnalisé

You will see your ‘Featured Article’ custom template listed there.

Right now your template is essentially empty so selecting it will simply display a white screen.

Let’s fix this.

The easiest way to do that is by copying the code from your theme’s single.php file and using it as a starting point. You’ll have to open the single.php file and then copy everything after the get_header() line.

Next, you need to paste this code at the end of your wpb-single-post.php file. Now you can save this file and upload it back to your server.

However, this will look exactly the same as your current single post template. You can now start making changes to your custom single post template.

You can add your own custom CSS classes, remove sidebars, create a full width template, or anything you want.

Creating Custom Single Post Templates by Category

Would you like to use a custom single post template based on categories? For example, you can give posts in the travel category a different layout to posts in the photography category.

You can do that using either the SeedProd Theme Builder or code.

Creating Custom Single Post Templates by Category Using SeedProd

Earlier we covered how to customize the SeedProd Theme Builder’s default single post template. But it doesn’t stop there. With SeedProd you can add as many custom post templates as you like, such as a different layout for every post category.

To add a new single post template, just click the ‘Duplicate’ link under the original post template. A new template called ‘Single Post – Copy’ will be created and added to the top of the theme templates page.

Cree una nueva plantilla de publicación duplicando la plantilla de publicación predeterminada Créer un nouveau modèle de publication en dupliquant le modèle de publication par défaut

You can customize the new template in the same way you customized the default Single Post template earlier. Simply click the template’s ‘Edit Design’ link and make any changes you like using SeedProd’s visual editor.

When you’ve finished customizing the template, you will need to add some conditions so that SeedProd will know which posts should use this template. In this case, we want it displayed when viewing posts within a single category.

Haga cliquez sur el enlace 'Modifier les conditions' Cliquez sur le lien "Modifier les conditions"

You can do that by clicking the template’s ‘Edit Conditions’ link and a new window will pop up.

Here you can give the template a name and priority. The default Single Post template has a priority of 0, so make sure you give this template a higher priority so it will be displayed on matching categories.

Agregar condiciones para mostrar la plantilla para una determinada categoría Add conditions to display the model of a certain category

Under ‘Conditions’, select ‘Has Category’ from the second drop down menu, then type the name of the category in the last field. For example, if you only want posts from the photography category to use this layout, then type ‘photography’.

When you’re finished, click the ‘Save’ button and now this template will be used for all posts in the matching category.

This is the easiest way to create multiple custom post templates in WordPress. It doesn’t require any knowledge of code and won’t accidentally mess up any theme files.

Creating Custom Single Post Templates by Category Using Code

This is another method for those who are comfortable adding code to their theme files.

First, you need to add this code to your theme’s functions.php file or a code snippets plugin.

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

/*

* Define a constant path to our single template folder

*/

define(SINGLE_PATH, TEMPLATEPATH . ‘/single’ );

  

/**

* Filter the single_template with our custom function

*/

add_filter( ‘single_template’ , ‘my_single_template’ );

  

/**

* Single template function which will choose our template

*/

function my_single_template( $single ) {

global $wp_query , $post ;

  

/**

* Checks for single template by category

* Check by category slug and ID

*/

foreach (( array )get_the_category() as $cat ) :

  

if ( file_exists (SINGLE_PATH . ‘/single-cat-‘ . $cat ->slug . ‘.php’ ))

return SINGLE_PATH . ‘/single-cat-‘ . $cat ->slug . ‘.php’ ;

  

elseif ( file_exists (SINGLE_PATH . ‘/single-cat-‘ . $cat ->term_id . ‘.php’ ))

return SINGLE_PATH . ‘/single-cat-‘ . $cat ->term_id . ‘.php’ ;

  

endforeach ;

}

This code first checks to see if WordPress is requesting a single post. If it is, then it tells WordPress to look for the template in the /single/ folder of your WordPress theme.

Now you need to add template files defined by this code.

Connect to your WordPress hosting using an FTP client or File Manager in cPanel and go to /wp-content/themes/your-theme-folder/.

Inside your current theme folder, you need to create a new folder called ‘single’. Next, you need to open this folder and create a new file inside it. Go ahead and name this file single-cat-{category-slug}. Replace {category-slug} with your actual category slug.

For example, if you have a category called ‘News’, then you will create single-cat-news.php file. If you have a category called ‘Travel Tips’, then create a template single-cat-travel-tips.php, and so on.

Creating a Single Post Plant for Categories Creating a Single Post Template for Categories

Ahora, estos archivos de plantilla estarán totalmente vacíos. Como punto de partida, puede copiar el contenido de su archivo single.php de la carpeta de su tema y pegarlo dentro de cada una de estas plantillas. Después de eso, deberá editar estas plantillas para realizar los cambios deseados.

Una vez que haya terminado, puede ir a su sitio web y ver una publicación. Utilizará la plantilla que ha creado para la categoría en la que está archivada esta publicación.

Ahora supongamos que tiene una publicación archivada en dos categorías Noticias y Consejos de viaje. WordPress mostrará automáticamente la plantilla para ‘Noticias’ porque aparece primero en orden alfabético.

Por otro lado, si archivó una publicación en una categoría y no creó una plantilla para esa categoría, WordPress volverá a la plantilla single.php predeterminada de su tema.

Creation of personalized plantillas of publication única para specíficos authors

Supongamos that desea that the publicaciones escritas por un specífico autor se vean diferentes in su sitio web. Puede hacerlo usando código siguiendo la misma técnica que mostramos para las categories.

Primero, debe agregar ise código al archivo functions.php of its theme or a complement of fragments of código.

1

2

3

4

5

6

seven

8

9

ten

11

12

13

14

15

dieciseis

17

18

19

20

21

22

23

24

25

26

27

28

29

/**

* Set a constant path to our unique templates folder

*/

set(SINGLE_PATH, TEMPLATEPATH. ‘/single’);

  

/**

* Filter the single_template with our custom function

*/

add_filter(‘single_template’, ‘my_single_author_template’);

  

/**

* Unique pattern function which will choose our pattern

*/

function my_single_author_template( $single ) {

global $wp_query, $post;

  

/**

* Checks unique model per author

* Check by username and ID

*/

$curauth = get_userdata( $wp_query ->post->post_author);

  

if (file_exists(SINGLE_PATH.’/single-author-‘.$curauth->user_nicename.’.php’))

returns SINGLE_PATH . ‘/single-author-‘ . $curauth->user_nicename . ‘.php’;

  

elseif(file_exists(SINGLE_PATH.’/single-author-‘.$curauth->ID.’.php’))

returns SINGLE_PATH . ‘/single-author-‘ . $curauth->ID . ‘.php’;

  

}

Then, debe conectarse su site web mediante FTP o el administrador de archivos cPanel en cPanel y luego ir a /wp-content/themes/your-theme-folder/. If aún no ha creado una carpeta llamada /single/ dentro de ella, continue y creado la ahora.

Dentro de esta carpeta, debe crear una plantilla utilizando el nom de usuario del autor en el nom de la plantilla. For example, single-author-johnsmith.php.

Esta plantilla estará vacía, por lo que puede copie y pegar el contenido de la plantilla single.php de su tema y usarla como point de partida.

Ahora can visit his website to see a publication created by a specific author. Use the plant you created.

Hope that is articulated the haya ayudado a learn how to create personalized seedlings of individual publications in WordPress. It is also possible that you want to learn how to carry out a seguimiento de los visitors del site web sur site de WordPress, over nuestra lista de complementos de WordPress que debe tener para hacer crecer sur site.

If you like this article, submit to a new YouTube channel for WordPress video tutorials. Also puede encontrarnos on Twitter and Facebook .

Comparte 1k Cuota Pío Cuota Facebook Messenger WhatsApp Correo electrónico


Video WordPress single post templates

Related Posts

Free chat room code for my website

Contents1 How to set up a free chat room on the website.2 3 comentarios2.1 Trackbacks/Pingbacks2.2 Submit a Comment Cancel reply3 How to Create a Chat Room Website…

Background image full screen css

Contents1 Cómo – Full Page Image1.1 Example1.2 Example2 CSS background image tamaño tutorial: how to codify a complete page background image3 Perfect Full Page Background Image3.1 Méthode CSS géniale,…

WordPress leverage browser caching

Contents1 Aproveche el almacenamiento in hidden del navegador1.1 Will it works for my website?1.2 Where are plugin options1.3 Some JavaScript files still display under Leverage Browser Caching1.4…

WordPress post to facebook page

Contents1 How to Automatically Post to Facebook from WordPress1.1 Download Now: How to Launch a WordPress Website [Free Guide + Checklist]1.2 1. Create an IFTTT account.1.3 2….

Download images from wordpress media library

Contents1 How to export your WordPress media library1.1 Download maintenant : How to launch a WordPress website [Free Guide + Checklist]1.2 How to export your WordPress media…

WordPress single post template

Contents1 How to Create Custom Unique Post Templates in WordPress2 Post Template Files2.1 author.php2.2 Fecha.php3 Handbook navigation4 How to Create Custom Single Post Templates in WordPress5 Video…