Category Archives: wpbeginner

How to Remove the Sidebar in WordPress

Do you want to remove the sidebar from your WordPress site? A sidebar is the widget-ready area in your WordPress theme. It often appears at the right or left side or below the content area on every page. In this article, we will show you how to easily remove the sidebar in WordPress.

read more

10 Best Social Media Plugins for WordPress (2017)

Are you looking for the best social media plugins for your WordPress site? There are so many social media plugins available for WordPress that it becomes overwhelming for beginners to choose the best plugin. In this article, we will show you some of the best social media plugins for WordPress that you can install right away.

Best Social Media Plugins for WordPress

What to Look for in a WordPress Social Media Plugin?

The main problem with most social media plugins for WordPress is performance. Since these plugins have to load additional stylesheets and scripts, they often slow down your website. For more on this topic, see our article on how WordPress plugins affect your site’s load time.

read more

26 Best Sales Page WordPress Themes for Marketers (2017)

Are you looking for the best sales page WordPress theme for your marketing campaign? Sales page or landing page WordPress themes help marketers convert visitors into paying customers. In this article, we have hand-picked some of the best sales page WordPress themes for marketers.

Best sales page WordPress themes

Creating a Sales Page Website with WordPress

Studies conducted by MarketingSherpa show that 48% marketers create new landing pages for each campaign and 68% of online businesses use multiple landing pages to generate leads.

If you are a business trying to sell products and services online, then you need a landing page designed to generate sales and leads.

read more

How to Create Custom Single Post Templates in WordPress

Do you want to create a custom single post template in WordPress? Custom single post templates allow you to easily select different templates for your posts. In this article, we will show you how to easily create custom single post templates in WordPress.

How to create custom single post template in WordPress

Note: This tutorial requires you to edit WordPress theme files. If you haven’t done this before, then check out our tutorial on how to copy and paste code 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 website. For example, you may want to use a different template for featured articles or stories in a particular category.

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

It is very much like creating a custom page template. You would be able to select your template from the post edit screen.

Having said, let’s take a look at how to easily create custom single post templates in WordPress.

Creating Custom Single Post Templates in WordPress

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

<?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 can save this file as wpb-single-post.php on your desktop.

Next, you need to upload it to your current WordPress theme folder using an FTP client.

After that you can login to your WordPress admin area and create or edit a post. Scroll down a little on the post edit screen, and you will notice the new Post Attributes meta box with an option to select the template.

Select your custom single 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 use it as a starting point.

Open the single.php file and then copy everything after the get_header() line.

Paste this code in your wpb-single-post.php file at the end. 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.

Create Custom Single Post Templates Based on Category

Want to use custom single post template based on categories? For example, posts in travel category can have a different layout, than posts in photography.

Here is how you can do that.

First you need to add this code to your theme’s functions.php file or a site-specific plugin.

/*
* 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;
}

read more