WPBeginner » wordpress tutorial http://www.wpbeginner.com Beginner's Guide for WordPress Fri, 08 May 2015 16:04:17 +0000 en-US hourly 1 http://wordpress.org/?v=4.2.2 How to Display the Latest Sticky Posts in WordPress http://www.wpbeginner.com/wp-tutorials/how-to-display-the-latest-sticky-posts-in-wordpress/ http://www.wpbeginner.com/wp-tutorials/how-to-display-the-latest-sticky-posts-in-wordpress/#comments Wed, 30 Nov -0001 00:00:00 +0000 http://www.wpbeginner.com/?p=1034 WordPress has this very cool feature called sticky posts. Think of sticky posts as featured posts for your blog. When you mark a post as sticky, it shows up above your new posts, but only if your theme permits it. In this tutorial we will… Read More »

To leave a comment please visit How to Display the Latest Sticky Posts in WordPress on WPBeginner.

]]>
WordPress has this very cool feature called sticky posts. Think of sticky posts as featured posts for your blog. When you mark a post as sticky, it shows up above your new posts, but only if your theme permits it. In this tutorial we will show you how to display the latest sticky posts in WordPress.

Latest Sticky Posts Demo

Note: This is an intermediate level tutorial and requires basic HTML / CSS knowledge + WordPress themes knowledge.

Video Tutorial

If you don’t like the video or need more instructions, then continue reading.

First thing you need to do is copy and paste this code snippet in your theme’s functions.php file or in a site-specific plugin.


function wpb_latest_sticky() { 

/* Get all sticky posts */
$sticky = get_option( 'sticky_posts' );

/* Sort the stickies with the newest ones at the top */
rsort( $sticky );

/* Get the 5 newest stickies (change 5 for a different number) */
$sticky = array_slice( $sticky, 0, 5 );

/* Query sticky posts */
$the_query = new WP_Query( array( 'post__in' => $sticky, 'ignore_sticky_posts' => 1 ) );
// The Loop
if ( $the_query->have_posts() ) {
	$return .= '<ul>';
	while ( $the_query->have_posts() ) {
		$the_query->the_post();
		$return .= '<li><a href="' .get_permalink(). '" title="'  . get_the_title() . '">' . get_the_title() . '</a><br />' . get_the_excerpt(). '</li>';
		
	}
	$return .= '</ul>';
	
} else {
	// no posts found
}
/* Restore original Post Data */
wp_reset_postdata();

return $return; 

} 
add_shortcode('latest_stickies', 'wpb_latest_sticky');

The code above queries the WordPress database to retrieve the 5 latest sticky posts. It then displays each sticky post’s title with a link in a list format. We have wrapped all that in a function and created a shortcode.

Now to display your latest sticky posts, you can use the shortcode [latest_stickies] in any WordPress post, page, or even a text widget.

If you would like to use shortcodes inside a text widget, then you will need to add this extra line of code in your theme’s functions.php or site-specific plugin.

add_filter('widget_text', 'do_shortcode');

This snippet and function can very well be used in featured slider, or any other advanced feature that you would like to display on your site. This snippet is mostly geared toward a WordPress site that has a custom homepage or a magazine style look.

That’s all, we hope this article helped you display latest sticky posts on your WordPress blog. You may also want to checkout our tutorial on how to add an expiration date to sticky posts in WordPress.

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

To leave a comment please visit How to Display the Latest Sticky Posts in WordPress on WPBeginner.

]]>
http://www.wpbeginner.com/wp-tutorials/how-to-display-the-latest-sticky-posts-in-wordpress/feed/ 3
10 Most Wanted Category Hacks and Plugins for WordPress http://www.wpbeginner.com/wp-tutorials/10-most-wanted-category-hacks-and-plugins-for-wordpress/ http://www.wpbeginner.com/wp-tutorials/10-most-wanted-category-hacks-and-plugins-for-wordpress/#comments Wed, 01 Oct 2014 11:30:11 +0000 http://www.wpbeginner.com/?p=410 Categories provide an easy way to sort your WordPress content. However, there is so much more that you can do with categories to make your site more user and search engine friendly. In this article, we will show you some of the most wanted category… Read More »

To leave a comment please visit 10 Most Wanted Category Hacks and Plugins for WordPress on WPBeginner.

]]>
Categories provide an easy way to sort your WordPress content. However, there is so much more that you can do with categories to make your site more user and search engine friendly. In this article, we will show you some of the most wanted category hacks and plugins for WordPress.

1. Category RSS Feeds

Did you know that each category on your WordPress site has its own RSS feed? Just add feed at the end of your category URL like this:

http://www.wpbeginner.com/category/news/feed/

That’s all, you can add this link on category templates. Don’t worry we will show you how to create category templates later in this article.

Another great benefit of category feeds is that you can allow your users to subscribe to categories. This gives your users a chance to only subscribe topics that interest them.

2. Category list with RSS Feed Links

The default categories widget in WordPress does not allow you to display an RSS feed link next to category names. If you would like to display feed links next to category names, then add this code in your theme’s functions.php file or a site-specific WordPress plugin.

function wpb_categories_with_feed() { 
$string .= '<ul>';
$string .= wp_list_categories('orderby=name&feed=RSS'); 
$string .= '</ul>'; 
return $string; 
}
// add shortcode
add_shortcode('categories-feed', 'wpb_categories_with_feed'); 
// Add filter to execute shortcodes in text widgets
add_filter('widget_text', 'do_shortcode'); 

You need to add [categories-feed] shortcode inside a text widget to list categories with feed links next to them.

3. Adding Category Icons in WordPress

Images make the web more interesting. You can use images to make your category pages stand-out. To associate images with your categories you need to install and activate the Taxonomy Images plugin. Upon activation you need to visit Settings » Taxonomy Images to enable images for categories.

Enabling images for categories in WordPress

To associate images with categories simply visit Post » Categories and click on the thumbnail icon to upload category images.

Adding category icons

See our guide on how to add taxonomy images in WordPress for more details.

4. Enable Categories for Pages

By default categories are only available for posts in WordPress. However, you can associate them to any post type including pages. Simply install and activate Post Tags and Categories for Pages plugin. It works out of box and there are no settings for you to configure. Simply click on pages and you will see categories and tags under the pages menu. Take a look at our tutorial on how to add categories and tags for WordPress pages for more information.

Categories for pages in WordPress

5. Enable Sticky Posts for Category Archives

In WordPress you can make posts sticky to feature them on your home page. To add sticky posts for your category pages, simply install and activate Category Sticky Posts plugin. Upon activation, the plugin adds a category sticky metabox on the post edit screen. See our tutorial on how to add sticky posts for WordPress categories for detailed instructions.

Category sticky metabox on post edit screen in WordPress

6. Creating Category Templates in WordPress

WordPress comes with a powerful theme engine. By default it looks for templates with specific names in your theme to display certain pages. For example, the category.php template in a theme is used to display all category pages.

Similarly, you can create templates for specific categories by naming the template with category name. For example, to create a template for movies category, you will name the template file category-movie.php.

Use your theme’s category.php file as the starting point for your single category template and then make the changes you need. For more detailed instructions take a look at our tutorial on how to create category templates in WordPress.

7. Exclude Specific Categories from RSS Feed

By default all your posts appear in your site’s RSS feed. If you would like to hide certain categories from site’s main RSS feed, then simply install and activate the Ultimate Category Excluder plugin. Upon activation, simply visit Settings » Category Exclusion to select categories you want to hide from your RSS feeds.

Exclude specific categories from RSS feed in WordPress

8. Show Recent Posts from Specific Categories

The main use of categories is to help you sort your content and help your users find content easily. If a user finds a post in a specific category interesting, then they are likely to read similar posts in the same category. To display recent posts from a category use this code in your theme where you want recent posts from a category to appear.

$query = new WP_Query( 'category_name=news' );

if ( $the_query->have_posts() ) {
	echo '<ul>';
	while ( $the_query->have_posts() ) {
		$the_query->the_post();
		echo '<li>' . get_the_title() . '</li>';
	}
	echo '</ul>';
} else {
	// no posts found
}
/* Restore original Post Data */
wp_reset_postdata();

Replace the value of category_name with the name of category you want to use.

9. Assign Author to Specific Categories

When managing a multi-author WordPress site you may want to assign authors to only post into specific categories assigned to them. Simply install and activate the Restrict Author Posting plugin. Upon activation, go to Users and edit the user you want to assign a category. On the user edit screen you will see a Restrict author post to a category section, where you can select the category assigned to that particular user.

Restrict author to a category

10. Show Excerpts on Category Pages

We recommend our users to display excerpts on archive and category pages. Displaying excerpts only cuts down your page load time which is good for SEO. Apart from that it also protects you from duplicate content issue on your site. To replace full content with excerpts on category pages, simply add this code to your theme’s functions.php file or a site specific plugin.


function my_excerpts($content = false) {
if(is_category()) :
	global $post;
	$content = $post->post_excerpt;
// If the post has explicitly set excerpt use that
	if($content) :
		$content = apply_filters('the_excerpt', $content);
// If no excerpt is set
	else :
		$content = $post->post_content;
		$excerpt_length = 55;
		$words = explode(' ', $content, $excerpt_length + 1);
		if(count($words) > $excerpt_length) :
			array_pop($words);
			array_push($words, '...');
			$content = implode(' ', $words);
		endif;
		$content = '<p>' . $content . '</p>';
	endif;
endif;
return $content;
}
add_filter('the_content', 'my_excerpts');

You can also replace content with excerpt by editing your theme’s category.php file and replacing the_content with the_excerpt. For more instructions see this tutorial on how to display post excerpts in WordPress themes.

We hope this article helped you learn some new category hacks and plugins for WordPress. For more best practice tips, see our guide on Categories vs. Tags (Best Practices).

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

To leave a comment please visit 10 Most Wanted Category Hacks and Plugins for WordPress on WPBeginner.

]]>
http://www.wpbeginner.com/wp-tutorials/10-most-wanted-category-hacks-and-plugins-for-wordpress/feed/ 9
How to Schedule Your Posts in WordPress http://www.wpbeginner.com/beginners-guide/schedule-your-posts-in-wordpress/ http://www.wpbeginner.com/beginners-guide/schedule-your-posts-in-wordpress/#comments Fri, 09 May 2014 10:00:25 +0000 http://www.wpbeginner.com/?p=215 WordPress has a really cool hidden feature that allows you to schedule your post. This is a very useful feature that many beginners don’t know about. In this article, we will show you how to schedule your posts in WordPress. Why Schedule Posts in WordPress?… Read More »

To leave a comment please visit How to Schedule Your Posts in WordPress on WPBeginner.

]]>
WordPress has a really cool hidden feature that allows you to schedule your post. This is a very useful feature that many beginners don’t know about. In this article, we will show you how to schedule your posts in WordPress.

Why Schedule Posts in WordPress?

There is a certain time in a day when each site gets the peak of their users. Now if you live in a different time zone than your readers, then it can be a problem. Imagine having your peak time as 3 a.m. Scheduling posts can be very handy for this.

The other situation is if you are going for a vacation, but you don’t want to abandon your blog. How do you fix that problems?

Simple, You schedule your posts in WordPress. This function allows you to stay ahead of yourself by finishing up articles in advance and have them ready. You can prepare for a busy week ahead of time and schedule articles to be published automatically.

How Do You Schedule a Post in WordPress?

If you don’t want to watch the video, then continue reading.

Once you are done writing the post, before hitting publish you need to look at the option right above the publish button which reads “Publish immediately”.

Schedule Your Posts in WordPress

Follow the steps above and you can now schedule posts in WordPress.

Consistent timing is what some users prefer. So if you write a blog post at 7:30 a.m, so users can read it with their coffee in the morning, then continue to do so because it will keep that user loyal to your website. If you decide to change times around, they might have to find another coffee read blog. Also sometimes users are eager to read your new post, so it gives them a time to expect new post.

To leave a comment please visit How to Schedule Your Posts in WordPress on WPBeginner.

]]>
http://www.wpbeginner.com/beginners-guide/schedule-your-posts-in-wordpress/feed/ 11