WordPress for Beginners » Tutorials http://www.wpbeginner.com Beginner's Guide for WordPress Thu, 02 Sep 2010 17:40:55 +0000 en hourly 1 http://wordpress.org/?v=3.0.1 How to Make a Separate RSS Feed for Each Custom Post Type in WordPress http://www.wpbeginner.com/wp-tutorials/how-to-make-a-separate-rss-feed-for-each-custom-post-type-in-wordpress/ http://www.wpbeginner.com/wp-tutorials/how-to-make-a-separate-rss-feed-for-each-custom-post-type-in-wordpress/#comments Thu, 02 Sep 2010 17:40:55 +0000 Editorial Staff http://www.wpbeginner.com/?p=2264 How to Make a Separate RSS Feed for Each Custom Post Type in WordPress is a post from: WPBeginner which is not allowed to be copied on other sites.

Related posts:
  1. How to Make Separate RSS Feed for Each Category in WordPress
  2. How to use Custom Post Types in WordPress 3.0
  3. How to Create a Custom Post Types Archive Page in WordPress
]]>
Everyone is utilizing Custom Post Types in their new WordPress sites because this is a very powerful feature. One of our users asked us how can they create a separate RSS feed for a specific custom post type in WordPress. In this article, we will be answering that question.

You would think that it require a lot of coding, but it doesn’t. It works just like creating a separate RSS feed for each category in WordPress. You can simply type this URL:

http://www.yoursite.com/feed/?post_type=book

Just change the post_type name to the one that you want to create a separate RSS feed for. Are you looking to take it to the next level and make it for a specific custom post type and custom taxonomy? Well that is not hard at all either:

http://www.yoursite.com/feed/?post_type=book&genre=romance

As you can see in the code above, that genre would be the custom taxonomy, and romance would be the tag if you may call it that. You can create a button in your sidebar to link to that. You may also link this feed and create a separate feedburner feed for it.

How to Make a Separate RSS Feed for Each Custom Post Type in WordPress is a post from: WPBeginner which is not allowed to be copied on other sites.

Related posts:

  1. How to Make Separate RSS Feed for Each Category in WordPress
  2. How to use Custom Post Types in WordPress 3.0
  3. How to Create a Custom Post Types Archive Page in WordPress

]]>
http://www.wpbeginner.com/wp-tutorials/how-to-make-a-separate-rss-feed-for-each-custom-post-type-in-wordpress/feed/ 0
How to Create a Custom Post Types Archive Page in WordPress http://www.wpbeginner.com/wp-tutorials/how-to-create-a-custom-post-types-archive-page-in-wordpress/ http://www.wpbeginner.com/wp-tutorials/how-to-create-a-custom-post-types-archive-page-in-wordpress/#comments Tue, 31 Aug 2010 15:57:54 +0000 Editorial Staff http://www.wpbeginner.com/?p=2225 Custom Post Types, but it wasn't explained thoroughly. So in this article, we will show you a step by step guide on creating a custom post types archive page in WordPress.

How to Create a Custom Post Types Archive Page in WordPress is a post from: WPBeginner which is not allowed to be copied on other sites.

Related posts:
  1. How to Create a Page that Displays a Random Post in WordPress
  2. How to use Custom Post Types in WordPress 3.0
  3. How to Create a Custom Page in WordPress
]]>
Custom Post Types was one of the awesome features included in WordPress 3.0. One of our users asked us a question on twitter (@wpbeginner), how to create a custom post types archive page. We covered it in our initial article about Custom Post Types, but it wasn’t explained thoroughly. So in this article, we will show you a step by step guide on creating a custom post types archive page in WordPress.

1. Creating a Custom Page Template

First step would be creating a custom page template in WordPress. All we will do is add the following code at the top of our new .php file which we will call (custompt-archives.php).

<?php /* Template Name: Custom Post Type Archive */ ?>

2. Adding the Necessary Template Codes

Next, you will need to add the necessary template codes including but not limited to header, footer, sidebar etc. This area will vary for each site, but for basics it would look like this:

<?php get_header(); ?>
This is where our Loop codes will go in the next step.
<?php get_sidebar(); ?>
<?php get_footer();?>

3. Creating our Custom Archive Loop

The loop is explained in details at the WordPress Codex, and we will be using different aspects of it to create our custom archives loop. Our loop will simply list posts with the necessary information surrounding it. You will be responsible for adding styling around it. Our loop:

<?php
global $query_string;
query_posts($query_string . "post_type=YOUR-CUSTOM-POST-TYPE&post_status=publish&posts_per_page=10");
if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

<h2><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h2>
<?php the_excerpt(); ?>

<?php endwhile;
endif; ?>
<div class="navigation">
	<div class="alignleft"><?php next_posts_link('Previous entries') ?></div>
	<div class="alignright"><?php previous_posts_link('Next entries') ?></div>
</div>
<?php wp_reset_query(); ?>

You can change the number of posts being displayed on the page by changing posts_per_page variable value.

Final Code

Your final code for the custom page should look like this:

<?php /* Template Name: Custom Post Type Archive */
get_header(); ?>

<?php
global $query_string;
query_posts($query_string . "post_type=YOUR-CUSTOM-POST-TYPE&post_status=publish&posts_per_page=10");
if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

<h2><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h2>
<?php the_excerpt(); ?>

<?php endwhile;
endif; ?>
<div class="navigation">
	<div class="alignleft"><?php next_posts_link('Previous entries') ?></div>
	<div class="alignright"><?php previous_posts_link('Next entries') ?></div>
</div>
<?php wp_reset_query(); ?>

<?php get_sidebar(); ?>
<?php get_footer();?>

Now upload this file in your theme’s directory. After you have done that, you need to go to your WordPress admin panel, and create a new page. Call it “Your Custom Post Type” Archives (or whatever you like to call it) and change the page template to “Custom Post Type Archive” as shown here. Do not add anything in the page content area, and simply publish the page. You should now have a custom post types archive page in WordPress.

How to Create a Custom Post Types Archive Page in WordPress is a post from: WPBeginner which is not allowed to be copied on other sites.

Related posts:

  1. How to Create a Page that Displays a Random Post in WordPress
  2. How to use Custom Post Types in WordPress 3.0
  3. How to Create a Custom Page in WordPress

]]>
http://www.wpbeginner.com/wp-tutorials/how-to-create-a-custom-post-types-archive-page-in-wordpress/feed/ 4
How to Add Twitter’s Official Tweet Button in WordPress http://www.wpbeginner.com/wp-tutorials/how-to-add-twitters-official-tweet-button-in-wordpress/ http://www.wpbeginner.com/wp-tutorials/how-to-add-twitters-official-tweet-button-in-wordpress/#comments Thu, 12 Aug 2010 21:16:29 +0000 Editorial Staff http://www.wpbeginner.com/?p=2146 Tweet Button. In this article, we will share how you can add twitter's official tweet button in WordPress.

How to Add Twitter’s Official Tweet Button in WordPress is a post from: WPBeginner which is not allowed to be copied on other sites.

Related posts:
  1. Official Facebook Share Count Button for your WordPress
  2. How to Add a Retweet Button on Your Blog
  3. How to Add Twitter @anywhere in WordPress
]]>
Earlier today, Twitter announced their official Tweet Button which does the exact same thing as the Tweetmeme buttons except it is made by twitter. A lot of people are already switching (this include top corporates and small bloggers that follow @wpbeginner on twitter) because this button offers additional customization plus it has the option to recommend account following. In this article, we will share how you can add twitter’s tweet button in WordPress.

Official Tweet Button

This code can be installed in single.php, loop.php, index.php, page.php, category.php, and archive.php as long as it is placed within the post loop.

<script src="http://platform.twitter.com/widgets.js" type="text/javascript"></script>
   <a href="http://twitter.com/share" class="twitter-share-button"
      data-url="<?php the_permalink(); ?>"
      data-via="wpbeginner"
      data-text="<?php the_title(); ?>"
      data-related="syedbalkhi:Founder of WPBeginner"
      data-count="vertical">Tweet</a>

Demo


Try tweeting using the button above.

If you notice in the code above, we are using the data-attribute of anchor tag to tell twitter exactly what we want it to do. Below is the explanation of what each property means:

  • data-url – This fetches the URL that you want to share (You do not need to change this).
  • data-via – This tells twitter who was the original tweeter by adding via @wpbeginner (Make sure you change it to your twitter account).
  • data-text – This fetches the title of your post (You do not need to change this).
  • data-related – This adds recommended users to follow. You are allowed up to two Twitter accounts for users to follow after they share content from your website. These accounts could include your own, or that of a contributor or a partner. The first account is the one that is shared in data-via property. (Make sure you change it to one of your other twitter accounts, or remove it). If you don’t, then you will be recommending @syedbalkhi (Founder of WPBeginner). The correct format to enter data in this variable is twitterusername:Description of the User
  • data-count – This tells twitter’s script which style of button you want to show. You have three option (vertical, horizontal, none).
  • data-lang – This variable tells twitter which language it should be in. Default value is ‘en’ for English, and we have left it at that.

We recommend users to use the data-attribute of anchor tag method because it keeps the code clean and short. Even though query string parameters are a convenient way to share your page, they can make your anchor tag very long, and a long URL is difficult to maintain especially when you have to URL encode parameters. Below is the query method for those who choose to use it:

<script src="http://platform.twitter.com/widgets.js" type="text/javascript"></script>
<a href="http://twitter.com/share?url=<?php echo urlencode(get_permalink($post->ID)); ?>&via=wpbeginner&count=horizontal" class="twitter-share-button">Tweet</a>

If you just want to add a tweet button on a static page, then you can use Twitter’s Tweet Button Generator.

Thanks to Otto for notifying us in the comment below that his plugin, Simple Twitter Connect, fully supports the official tweet button.

Additional Resources:

Supplemental Documentation for Tweet Button

How to Add Twitter’s Official Tweet Button in WordPress is a post from: WPBeginner which is not allowed to be copied on other sites.

Related posts:

  1. Official Facebook Share Count Button for your WordPress
  2. How to Add a Retweet Button on Your Blog
  3. How to Add Twitter @anywhere in WordPress

]]>
http://www.wpbeginner.com/wp-tutorials/how-to-add-twitters-official-tweet-button-in-wordpress/feed/ 17
How WordPress Plugins Affect Your Site’s Load Time http://www.wpbeginner.com/wp-tutorials/how-wordpress-plugins-affect-your-sites-load-time/ http://www.wpbeginner.com/wp-tutorials/how-wordpress-plugins-affect-your-sites-load-time/#comments Wed, 04 Aug 2010 18:21:56 +0000 Editorial Staff http://www.wpbeginner.com/?p=2042 How WordPress Plugins Affect Your Site’s Load Time is a post from: WPBeginner which is not allowed to be copied on other sites.

Related posts:
  1. Most Wanted Twitter Hacks and Plugins for WordPress
  2. Recommended Plugins for WordPress
  3. How to Install WordPress on Your Site
]]>
Have you heard from developers that the more plugins you use, the slower your WordPress site gets? Well that is partially true. Some plugins add just a small query which has little to no impact on your site’s load time. Where as other plugins add jQuery and CSS on each page load (in your site’s <head></head> area). So for example if each plugin adds one jQuery file and one CSS stylesheet and you have 8 plugins like that, you just added 16 HTTP Requests. This can get really out of control when plugins start adding more than one stylesheet or jQuery files. In this article, we will show you how you can still use all the WordPress plugins you want without the additional HTTP Requests.

Note: We recommend that you at least know some PHP before diving into this tutorial.

Our Goal: Disable all Additional Scripts and Stylesheets that plugins add on each page load.

Wait a minute, Why do these plugins add these scripts and styles? Isn’t it necessary for the plugins to function properly? Glad you asked. Most likely those CSS and JavaScript codes are important to the functionality of the plugin, but we will remove it anyways to have more control on our WordPress site and make it run faster. By disabling the CSS files and JavaScripts, we can:

But, we want to take control of these files and make our sites run faster. Disabling these scripts and styles will allow us to do a few things:

  • Combine multiple files into a single file (Sprite Technique).
  • Load the files only on the pages we’re using the script or style.

Disable Scripts and Styles in WordPress

The best part about WordPress is that it has a built-in system that allows us to deregister scripts and styles that are added by the plugins. The “bad part” in this situation about WordPress is that it is open-source, so the plugins are created by people in the community (Expert developers and new developers). This means that not all plugins use the correct methods for loading scripts and styles which makes our job harder. The correct method is by registering the stylesheet or scripts with the following WordPress functions: wp_enqueue_script() and wp_enqueue_style(). If your plugin author isn’t using these functions, then send them a kind email asking them to update the plugin. This is not hard, it is just a matter of a learning curve.

To figure out what scripts or styles you want to disable, you might have to dig deeper and gets your hand dirty. This means looking in the code of your plugins.

Disabling CSS (Stylesheets)

In this example, we will use a plugin called Cleaner Gallery which adds its own CSS file on each page load. First, you have to check whether the plugin is using the correct method for adding stylesheets. To do so, you would need to open the plugin file: gallery.php (for this plugin). In there, you should run a search for “wp_enqueue_style”. You will find results like this:

wp_enqueue_style( 'cleaner-gallery', CLEANER_GALLERY_URL . 'cleaner-gallery.css', false, 0.8, 'all' );

Now you know the name of the handle for the style which is ‘cleaner-gallery’. Then you would need to open your theme’s functions.php file and add the following code:

    add_action( 'wp_print_styles', 'my_deregister_styles', 100 );
    function my_deregister_styles() {
    wp_deregister_style( 'cleaner-gallery' );
    }

You can deregister as many style handles you want within this function. So if you have more than one plugin to deregister the stylesheet for, you would do it like this:

    add_action( 'wp_print_styles', 'my_deregister_styles', 100 );

    function my_deregister_styles() {
    wp_deregister_style( 'cleaner-gallery' );
    wp_deregister_style( 'Plugin Style Handle' );
    wp_deregister_style( 'Plugin Style Handle' );
    }

Now once you have removed the stylesheets from being loaded on every page, it will affect plugin’s functionality. For example, your gallery will be BROKEN in terms of styling and organization. To fix this, you should open your theme’s style.css file, and all the way at the bottom paste the CSS codes from the plugin(s). In our example, we removed cleaner gallery stylesheet from loading, so you will now open cleaner-gallery.css which can be found in that plugin’s folder. Copy the code and paste it in your theme’s style.css file. This way not only that you would be able to customize the display of your gallery, but you will also reduce one HTTP request.

The Ideal Way

A plugin known as WP-PageNavi gives its users an option to remove the stylesheet from the Dashboard Settings Page.

WP-PageNavi Options

Most of the time, you would need to customize the display of this plugin to match your site’s color scheme. Because of that most users, ended up pasting the codes on their style.css anyways. Now the plugin author lets you deregister the stylesheet with a simple check box.

We are hoping that more and more plugin developers follow this step to make the job easier :)

Disabling JavaScripts

Some plugins also add the JavaSscript on the page for the sake of functionality. In our example, we will use the plugin Contact Form 7.

You will need to dig deeper in the Plugin files to find the script handle just like we did with the Styles. For this plugin, the script handle is ‘contact-form-7′. You will need to copy and paste the function below in your theme’s functions.php file:

    add_action( 'wp_print_scripts', 'my_deregister_javascript', 100 );

    function my_deregister_javascript() {
    wp_deregister_script( 'contact-form-7' );
    }

You can deregister multiple scripts within one function if you so desire. Once you remove the JavaScript, it will certainly affect the plugin’s functionality. You can combine JavaScripts together, but sometimes it does not work, so you must know what you are doing. You can learn from Trial and Error (like a lot of us do), but we recommend you do not do that on a live site.

Load Scripts Only on Specific Pages

Lets say that you know the Contact Form Script is necessary, and you cannot merge it with other scripts for some reason. You can load it only on the contact page if you so desire with the following function:

    add_action( 'wp_print_scripts', 'my_deregister_javascript', 100 );

    function my_deregister_javascript() {
    if ( !is_page('Contact') ) {
    wp_deregister_script( 'contact-form-7' );
    }
    }

By doing this, you will save the unnecessary script load on all the other pages that does not have the Contact Form. This is an extremely useful technique to improve site’s load time. You can use other parameters such as !is_single etc.

If you are using a lot of plugins on your site, we recommend that you open FireFox and View the Source file of your main page (Ctril + U). Then look above this area </head> and see how many plugins are adding HTTP Requests such as stylesheets and JavaScripts. Also install the YSlow Plugin on Firefox to see what can be fixed and what is your current Site Grade. Follow this tutorial above, and report back to us how much did you improve your site grade by. Have fun.

Additional Resources

Justin Tadlock
YSlow
WordPress Codex: Scripts / Styles

How WordPress Plugins Affect Your Site’s Load Time is a post from: WPBeginner which is not allowed to be copied on other sites.

Related posts:

  1. Most Wanted Twitter Hacks and Plugins for WordPress
  2. Recommended Plugins for WordPress
  3. How to Install WordPress on Your Site

]]>
http://www.wpbeginner.com/wp-tutorials/how-wordpress-plugins-affect-your-sites-load-time/feed/ 15
How to Display a Read More link in WordPress Excerpts http://www.wpbeginner.com/wp-tutorials/how-to-display-a-read-more-link-in-wordpress-excerpts/ http://www.wpbeginner.com/wp-tutorials/how-to-display-a-read-more-link-in-wordpress-excerpts/#comments Mon, 02 Aug 2010 09:13:22 +0000 Editorial Staff http://www.wpbeginner.com/?p=2035 categories. But if you notice, our read more button is added on a separate line from the excerpt text. In this article, we will show you how to automatically add a read more link in WordPress Excerpts.

How to Display a Read More link in WordPress Excerpts is a post from: WPBeginner which is not allowed to be copied on other sites.

Related posts:
  1. How to Display Post Excerpts in WordPress Themes
  2. Add Excerpts to Your Pages in WordPress
  3. How to Display Link Description with Blogroll in WordPress
]]>
This post is supported by Managed Hosting from Hosting.com

To prevent duplicate content, improve site load time, and for better SEO many bloggers have started to use post excerpts. Excerpts are mini-descriptions of the posts shown on the main blog page, category pages, and archive pages. You can see a live example by visiting any of our categories. But if you notice, our read more button is added on a separate line from the excerpt text. In this article, we will show you how to automatically add a read more link in WordPress Excerpts.

First open your functions.php file, and paste the following code inside the php tags:

 // Changing excerpt more
    function new_excerpt_more($more) {
    global $post;
    return '… <a href="'. get_permalink($post->ID) . '">' . 'Read More &raquo;' . '</a>';
    }
    add_filter('excerpt_more', 'new_excerpt_more');

In this function, you are telling WordPress to remove the default more which looks like this: [...], and replace it with a link. This short and simple tutorial was requested via our suggestion form. You can suggest article ideas as well by using our suggestion form or our twitter @wpbeginner.

How to Display a Read More link in WordPress Excerpts is a post from: WPBeginner which is not allowed to be copied on other sites.

Related posts:

  1. How to Display Post Excerpts in WordPress Themes
  2. Add Excerpts to Your Pages in WordPress
  3. How to Display Link Description with Blogroll in WordPress

]]>
http://www.wpbeginner.com/wp-tutorials/how-to-display-a-read-more-link-in-wordpress-excerpts/feed/ 0
Video: Adding a Second Menu to the WordPress Twenty Ten Theme http://www.wpbeginner.com/wp-tutorials/adding-a-second-menu-to-the-twenty-ten-theme/ http://www.wpbeginner.com/wp-tutorials/adding-a-second-menu-to-the-twenty-ten-theme/#comments Mon, 26 Jul 2010 14:40:13 +0000 Editorial Staff http://www.wpbeginner.com/?p=2022 register_nav_menus(). Here's a quick tip on how to take advantage of this function and add a second menu to the Twenty Ten theme.

Video: Adding a Second Menu to the WordPress Twenty Ten Theme is a post from: WPBeginner which is not allowed to be copied on other sites.

Related posts:
  1. Adding Additional Default Headers to the WordPress Twenty Ten Theme
  2. How to Create a WordPress Child Theme (Video)
  3. WordPress 3.0 – Thelonious Features (Video)
]]>
The Twenty Ten theme only comes with one default menu, which is included in the header. However the theme also supports multiple menus, thanks to the use of  register_nav_menus(). Here’s a quick tip on how to take advantage of this function and add a second menu to the Twenty Ten theme.

Watch the Screencast

Functions.php

Open the functions.php file and look for:

// This theme uses wp_nav_menu() in one location.

The next line is where we see the register_nav_menus() being used. As you can see this function accepts an array.

register_nav_menus( array(
'primary' =&gt; __( 'Primary Navigation', 'twentyten' ),
) );

primary: this is a key, or name of the menu, this name should be unique within the array

__( ‘Primary Navigation’): this is the vaule of the key, or description of the menu

To add the second menu simply add another key (menu name) and assign a value (enter description) into the array. Here’s an example of what it can look like when adding your second menu:

register_nav_menus( array(
'primary' =&gt; __( 'Primary Navigation', 'twentyten' ),
'secondary' =&gt; __( 'Secondary Navigation', 'twentyten' ),
) );

This technique can be used in creating other free themes or child themes as well. If you have any questions, feel free to ask in the comment.

Video: Adding a Second Menu to the WordPress Twenty Ten Theme is a post from: WPBeginner which is not allowed to be copied on other sites.

Related posts:

  1. Adding Additional Default Headers to the WordPress Twenty Ten Theme
  2. How to Create a WordPress Child Theme (Video)
  3. WordPress 3.0 – Thelonious Features (Video)

]]>
http://www.wpbeginner.com/wp-tutorials/adding-a-second-menu-to-the-twenty-ten-theme/feed/ 6
How to Exclude Pages from WordPress Search Results http://www.wpbeginner.com/wp-tutorials/how-to-exclude-pages-from-wordpress-search-results/ http://www.wpbeginner.com/wp-tutorials/how-to-exclude-pages-from-wordpress-search-results/#comments Mon, 12 Jul 2010 08:16:35 +0000 Editorial Staff http://www.wpbeginner.com/?p=2000 How to Exclude Pages from WordPress Search Results is a post from: WPBeginner which is not allowed to be copied on other sites.

Related posts:
  1. How to Disable the Search Feature in WordPress
  2. How to Exclude Pages from the Menu in WordPress
  3. Display Search Term and Result Count in WordPress
]]>
By default, WordPress Search feature displays published posts and published pages in search results. Often when users are looking for something in a blog, it is most likely a post rather than a page. In this article, we will show you how to make your search more relevant and less crowded by excluding pages from WordPress search results.

First open your theme’s functions.php file and paste this code:

function SearchFilter($query) {
if ($query->is_search) {
$query->set('post_type', 'post');
}
return $query;
}

add_filter('pre_get_posts','SearchFilter');

Explanation: This code just searches for posts through setting the post_type. You can also make it do the opposite by setting the post_type to pages, so it only return pages in the search result.

Source: Bavotasan

How to Exclude Pages from WordPress Search Results is a post from: WPBeginner which is not allowed to be copied on other sites.

Related posts:

  1. How to Disable the Search Feature in WordPress
  2. How to Exclude Pages from the Menu in WordPress
  3. Display Search Term and Result Count in WordPress

]]>
http://www.wpbeginner.com/wp-tutorials/how-to-exclude-pages-from-wordpress-search-results/feed/ 3
Adding Additional Default Headers to the WordPress Twenty Ten Theme http://www.wpbeginner.com/wp-themes/adding-additional-default-headers-to-the-wordpress-twenty-ten-theme/ http://www.wpbeginner.com/wp-themes/adding-additional-default-headers-to-the-wordpress-twenty-ten-theme/#comments Wed, 07 Jul 2010 12:33:37 +0000 Editorial Staff http://www.wpbeginner.com/?p=1974 Adding Additional Default Headers to the WordPress Twenty Ten Theme is a post from: WPBeginner which is not allowed to be copied on other sites.

Related posts:
  1. How to Enable Custom Header Images Panel in WordPress 3.0
  2. Video: Adding a Second Menu to the WordPress Twenty Ten Theme
  3. Speaky, A Free Twenty Ten Child Theme for WordPress
]]>
The Twenty Ten theme comes with eight default headers. Any default header that you set is replaced with the “featured image” of a post. You can only see the new header when viewing that post. In this week’s WordPress Quick Tip we’ll see how simple it is to add additional headers to the Header’s Panel.

Watch the Screencast

Functions.php

Open up the functions.php file of the Twenty Ten theme. Locate the following section:

// Default custom headers packaged with the theme. %s is a placeholder for the theme template directory URI.

What follows is an array listing the current default headers and their location. To add your own, add a comma after the last parenthesis of the array of sunset header. Here’s an example of what it can look like after adding two more headers:

register_default_headers( array(
‘berries’ => array(
‘url’ => ‘%s/images/headers/berries.jpg’,
‘thumbnail_url’ => ‘%s/images/headers/berries-thumbnail.jpg’,
/* translators: header image description */
‘description’ => __( ‘Berries’, ‘twentyten’ )
),
‘cherryblossom’ => array(
‘url’ => ‘%s/images/headers/cherryblossoms.jpg’,
‘thumbnail_url’ => ‘%s/images/headers/cherryblossoms-thumbnail.jpg’,
/* translators: header image description */
‘description’ => __( ‘Cherry Blossoms’, ‘twentyten’ )
),
‘concave’ => array(
‘url’ => ‘%s/images/headers/concave.jpg’,
‘thumbnail_url’ => ‘%s/images/headers/concave-thumbnail.jpg’,
/* translators: header image description */
‘description’ => __( ‘Concave’, ‘twentyten’ )
),
‘fern’ => array(
‘url’ => ‘%s/images/headers/fern.jpg’,
‘thumbnail_url’ => ‘%s/images/headers/fern-thumbnail.jpg’,
/* translators: header image description */
‘description’ => __( ‘Fern’, ‘twentyten’ )
),
‘forestfloor’ => array(
‘url’ => ‘%s/images/headers/forestfloor.jpg’,
‘thumbnail_url’ => ‘%s/images/headers/forestfloor-thumbnail.jpg’,
/* translators: header image description */
‘description’ => __( ‘Forest Floor’, ‘twentyten’ )
),
‘inkwell’ => array(
‘url’ => ‘%s/images/headers/inkwell.jpg’,
‘thumbnail_url’ => ‘%s/images/headers/inkwell-thumbnail.jpg’,
/* translators: header image description */
‘description’ => __( ‘Inkwell’, ‘twentyten’ )
),
‘path’ => array(
‘url’ => ‘%s/images/headers/path.jpg’,
‘thumbnail_url’ => ‘%s/images/headers/path-thumbnail.jpg’,
/* translators: header image description */
‘description’ => __( ‘Path’, ‘twentyten’ )
),
‘sunset’ => array(
‘url’ => ‘%s/images/headers/sunset.jpg’,
‘thumbnail_url’ => ‘%s/images/headers/sunset-thumbnail.jpg’,
/* translators: header image description */
‘description’ => __( ‘Sunset’, ‘twentyten’ )
),
‘waterfall’ => array(
‘url’ => ‘%s/images/headers/waterfall.jpg’,
‘thumbnail_url’ => ‘%s/images/headers/waterfall-thumbnail.jpg’,
/* translators: header image description */
‘description’ => __( ‘Waterfall’, ‘twentyten’ )
),
‘mountain’ => array(
‘url’ => ‘%s/images/headers/mountain.jpg’,
‘thumbnail_url’ => ‘%s/images/headers/mountain-thumbnail.jpg’,
/* translators: header image description */
‘description’ => __( ‘Mountain’, ‘twentyten’ )
)
) );

Lets dissect the code a little bit.

register_default_headers : This is the function that creates and displays our default headers. It accepts an array of parameters.

name: Sets a value with our headers name. We can then set an array of additional values and keys.

url: Relative path to the header image. Notice that the current path is /images/headers/image_name.jpg

thumbnail_url: Relative path to a thumbnail of the header image. Current path is /images/headers/image_name-thumbnail.jpg

description: A description of the image. This would be display upon hovering over the image inside the Headers Panel.

Things to Note

The Twenty Ten header is 940×198, anything bigger than that would be resized; anything smaller would be stretch to fit those dimensions. The thumbnail images can be set to any dimensions, 230×48 is the default. The images can only be .jpg or they will be ignored and won’t be displayed.

Adding Additional Default Headers to the WordPress Twenty Ten Theme is a post from: WPBeginner which is not allowed to be copied on other sites.

Related posts:

  1. How to Enable Custom Header Images Panel in WordPress 3.0
  2. Video: Adding a Second Menu to the WordPress Twenty Ten Theme
  3. Speaky, A Free Twenty Ten Child Theme for WordPress

]]>
http://www.wpbeginner.com/wp-themes/adding-additional-default-headers-to-the-wordpress-twenty-ten-theme/feed/ 9
Useful WordPress Configuration Tricks That You May Not Know http://www.wpbeginner.com/wp-tutorials/useful-wordpress-configuration-tricks-that-you-may-not-know/ http://www.wpbeginner.com/wp-tutorials/useful-wordpress-configuration-tricks-that-you-may-not-know/#comments Mon, 28 Jun 2010 19:15:12 +0000 Editorial Staff http://www.wpbeginner.com/?p=1947 functions.php is the single most important file in your WordPress theme, then wp-config.php is the single most important file in your entire WordPress installation. In this article, we will share some of the most useful WordPress configuration tricks that you may not know yet.

Useful WordPress Configuration Tricks That You May Not Know is a post from: WPBeginner which is not allowed to be copied on other sites.

Related posts:
  1. What, Why, and Hows of WordPress Security Keys
  2. How to Disable Post Revisions in WordPress and Reduce Database Size
  3. 18 Useful Tricks To Speed Up WordPress & Boost Performance
]]>
If functions.php is the single most important file in your WordPress theme, then wp-config.php is the single most important file in your entire WordPress installation. This file can be used to configure database functionalities, enhance performance, and improve security on all WordPress powered websites and blogs. In this article, we will share some of the most useful WordPress configuration tricks that you may not know yet.

By default, WordPress installation does not come with a file wp-config.php. The default install comes with a sample file known as wp-config-sample.php. You must use this file as a sample to create the actual wp-config.php before you can setup your blog. Most users never do this manually because WordPress lets you do it automatically from their installation setup. In that setup, you are adding/modifying key WordPress configurations. So first, we will walk you through what the default setup lets you do.

When you upload WordPress via FTP and access the site, you see a screen like this:

WordPress Installation Setup

The setup basically tells you to use the wp-config-sample.php because it may not work on all hosts. Most of which we tried it with, it works. If you are using one of the popular hosts, then it will work. The next step would be something like this:

WordPress Installation Setup

There you enter some of the key information. The info there lets WordPress connect with a database. Anything you enter in the setup will be added in your wp-config.php as:

define('DB_NAME', 'database-name');
define('DB_USER', 'database-username');
define('DB_PASSWORD', 'database-password');
define('DB_HOST', 'localhost');

By default, the database host is localhost because it works with most hosts. But there are hosts that has different configuration, so you will need to modify this if you are using the following hosts:

  • 1and1 Hosting — db12345678
  • DreamHost — mysql.example.com
  • GoDaddy — h41mysql52.secureserver.net
  • ICDSoft — localhost:/tmp/mysql5.sock
  • MediaTemple (GS) — internal-db.s44441.gridserver.com
  • Pair Networks — dbnnnx.pair.com
  • Yahoo — mysql

One of the coolest trick for wp-config.php in Digging into WordPress eBook was the ability to detect the database host.

define('DB_HOST', $_ENV{DATABASE_SERVER});

Paste the code above, and it will most likely grab the database server. For this, you would have to manually edit the wp-config.php file though.

Security Keys

WordPress Security Keys is a set of random variables that improve encryption of information stored in the user’s cookies. Prior to WordPress 3.0, you had to install this in your wp-config.php file manually. In WordPress 3.0 if you use the install wizard, then it automatically adds the security keys in your wp-config.php. Also prior to WordPress 3.0, there were only 4 security keys, but with 3.0 there are 8 security keys available.

These can be added in the wp-config.php as so:

define('AUTH_KEY', 'put your unique phrase here');
define('SECURE_AUTH_KEY', 'put your unique phrase here');
define('LOGGED_IN_KEY', 'put your unique phrase here');
define('NONCE_KEY', 'put your unique phrase here');
define('AUTH_SALT', 'put your unique phrase here');
define('SECURE_AUTH_SALT', 'put your unique phrase here');
define('LOGGED_IN_SALT', 'put your unique phrase here');
define('NONCE_SALT', 'put your unique phrase here');

You can grab the unique keys by going to this page. We did an article on What, Why, and Hows of Security Keys that might interest you.

Database Prefix

When you are installing WordPress using the wizard, one of the options is to select the Table prefix. That is stored in wp-config.php file as:

$table_prefix = 'wp_';

We recommend that you use something other than wp_ to add extra work for the hackers. Although if you already have WordPress setup, then don’t just change the prefix like this. There is a set of steps here that you should take.

Language Configuration

By default, English is the localized language of WordPress, but it can be changed to your native language with these:

define('WPLANG', '');
define('LANGDIR', '');

The language translation file (.mo) must be placed in the default location which is assumed to be wp-content/languages (first) and then wp-includes/languages (second). As you can see in the function above, you can define your own language directory if you like. To find WordPress in your language, please check out the official WordPress Codex page.

Debugging WordPress

For developers, WordPress has this awesome debugging feature which allows them to find errors, and deprecated functions. By default, this function is set to false, but in the development mode, developers should have it enabled.

define(‘WP_DEBUG’, false); // disable debugging mode by default
define(‘WP_DEBUG’, true); // enable debugging mode

Blog/Site Address

In your WordPress Settings, you specify the WordPress address and the site address. Those are added in your database, and every time the developer calls it in the template, it is running a database query. In WordPress 2.2, these two settings were introduced to override the database values without changing them:

define('WP_HOME', 'http://www.wpbeginner.com');
define('WP_SITEURL', 'http://www.wpbeginner.com');

By adding these in your wp-config.php, you are reducing the number of database queries thus increasing your site’s performance.

Override File Permissions

You can override file permissions, if your host has restrictive permissions for all user files. Most of you do not need this, but it exists for those who need it.

define('FS_CHMOD_FILE', 0755);
define('FS_CHMOD_DIR', 0644);

Post Revisions

In the recent versions of WordPress, there is a super awesome feature called Post Revisions. This function auto-saves posts just incase if your browser crash, or something else happen. It also allows users to restore back to previous versions if they don’t like the changes and so on. While a lot of us love this feature, some of us really hate it with a passion. This function has numerous configuration, so you can make it work just right for you.

The Auto-Save Configuration

By default WordPress saves post every 60 seconds, but if you think that is way too much, then you can modify it to your likings with this configuration:

define('AUTOSAVE_INTERVAL', 120); // in seconds

Some posts have 10s, 20s, or even 100 post revisions depending on the blog owner. If you think that feature annoys you, then you can limit the number of revisions per post.

define('WP_POST_REVISIONS', 5);

You can use any integer you like there.

If none of the settings above satisfies you, then you can simply disable the post revisions feature by adding this function:

define('WP_POST_REVISIONS', false);

WordPress Trash Feature

In WordPress 2.9, there was a new “Trash” feature added to the core. This feature works just like the recycling bin, so instead of deleting the post permanently, you would send it to the trash. This helped those users who accidently click on Delete button, and it can be any of us. The bad part about this trash feature is that you have to empty the trash regularly. By default the trash empties itself every 30 days. You can modify that by using the following function:

define('EMPTY_TRASH_DAYS', 7 ); //Integer is the amount of days

If you do not like this feature, then you can disable it by adding the function below:

define('EMPTY_TRASH_DAYS', 0 );

But remember, if you keep the value to 0, then WordPress would not ask for confirmation when you click on Delete Permanently. Any accidental click could cost you…

FTP/SSH Constants

By default, WordPress allow you to upgrade plugins, and WordPress core versions from within the backend. There are some hosts that requires an FTP or SSH connection everytime you try to upgrade, or install a new plugin. By using the codes below, you can set the FTP or SSH constants and never have to worry about it again.

// forces the filesystem method: "direct", "ssh", "ftpext", or "ftpsockets"
define('FS_METHOD', 'ftpext');
// absolute path to root installation directory
define('FTP_BASE', '/path/to/wordpress/');
// absolute path to "wp-content" directory
define('FTP_CONTENT_DIR', '/path/to/wordpress/wp-content/');
// absolute path to "wp-plugins" directory
define('FTP_PLUGIN_DIR ', '/path/to/wordpress/wp-content/plugins/');
// absolute path to your SSH public key
define('FTP_PUBKEY', '/home/username/.ssh/id_rsa.pub');
// absolute path to your SSH private key
define('FTP_PRIVKEY', '/home/username/.ssh/id_rsa');
// either your FTP or SSH username
define('FTP_USER', 'username');
// password for FTP_USER username
define('FTP_PASS', 'password');
// hostname:port combo for your SSH/FTP server
define('FTP_HOST', 'ftp.example.org:21');

Auto Database Optimization

In WordPress 2.9, there was a feature added called Automatic Database Optimization. To enable this feature, you would need to use the following function:

define('WP_ALLOW_REPAIR', true);

Once activated, you can see the settings on this page: http://www.yoursite.com/wp-admin/maint/repair.php

WordPress Automatic Database Repair

The user does not need to be logged in to access this functionality when this define is set. This is because its main intent is to repair a corrupted database, Users can often not login when the database is corrupt. So once you are done repairing and optimizing your database, make sure to remove this from your wp-config.php.

Increase PHP Memory Limit

There is a common WordPress Memory Exhausted Error that users have seen when activating some plugin. You can increase the PHP Memory Limit through wp-config.php file. Simply paste the code below:

define('WP_MEMORY_LIMIT', '64M');

Note: This feature may not work with some web hosts, so you would have to ask them (beg them) to increase your PHP Memory limit.

WordPress Error Log

For developers, it is useful to have an error log for a site. You can easily create a simple error log for a WordPress powered website by using wp-config.php file. First create a file called “php_error.log”, make it server-writable, and place it in the directory of your choice. Then edit the path in the third line of the following code:

@ini_set('log_errors','On');
@ini_set('display_errors','Off');
@ini_set('error_log','/home/path/domain/logs/php_error.log');

Move your wp-content Directory

Starting from WordPress 2.6, you can move your wp-content directory. It helps with site security. You can do move your wp-content directory by adding the following code in your wp-config.php file:

define( 'WP_CONTENT_DIR', $_SERVER['DOCUMENT_ROOT'] . '/blog/wp-content' );
define( 'WP_CONTENT_URL', 'http://example/blog/wp-content');
define( 'WP_PLUGIN_DIR', $_SERVER['DOCUMENT_ROOT'] . '/blog/wp-content/plugins' );
define( 'WP_PLUGIN_URL', 'http://example/blog/wp-content/plugins');

We have the plugin directory defined because some plugins might not work if you do not define it specifically.

Custom User / UserMeta Tables

By default, WordPress saves all user data in the tables wp_users and wp_usermeta. By using the function below, you can specify the table where you want your user information stored.

define('CUSTOM_USER_TABLE', $table_prefix.'my_users');
define('CUSTOM_USER_META_TABLE', $table_prefix.'my_usermeta');

Enable Multi-Site Network

In WordPress 3.0, WPMU was merged into WordPress core. To enable the multi-site network functionality, you have to add the following code in your wp-config.php file.

define('WP_ALLOW_MULTISITE', true);

Once you add this code, there will be a new page in your wp-admin called “Network” located in Tools » Network.

You will have to follow the directions on that page to continue the setup of the MU Network.

Securing Your WP-Config File

As you can see, this file is SUPER IMPORTANT therefore it needs extra security. By default it is located in the root WordPress folder, but you can move it. It can be moved outside your public_html directory, so users cannot access it. WordPress knows by default to look in other directories, if the files is not found in the WordPress root folder. You can also use .htaccess file to limit access to this file.

Add the following code:

# protect wpconfig.php
<files wp-config.php>
order allow,deny
deny from all
</files>

If you have other tips that we can add, surely let us know and we will add it in the article.

Sources

WordPress Codex
Digging into WordPress

Useful WordPress Configuration Tricks That You May Not Know is a post from: WPBeginner which is not allowed to be copied on other sites.

Related posts:

  1. What, Why, and Hows of WordPress Security Keys
  2. How to Disable Post Revisions in WordPress and Reduce Database Size
  3. 18 Useful Tricks To Speed Up WordPress & Boost Performance

]]>
http://www.wpbeginner.com/wp-tutorials/useful-wordpress-configuration-tricks-that-you-may-not-know/feed/ 15
How to Create a Separate Page for Blog Posts in WordPress http://www.wpbeginner.com/wp-tutorials/how-to-create-a-separate-page-for-blog-posts-in-wordpress/ http://www.wpbeginner.com/wp-tutorials/how-to-create-a-separate-page-for-blog-posts-in-wordpress/#comments Mon, 21 Jun 2010 22:50:18 +0000 Editorial Staff http://www.wpbeginner.com/?p=1916 custom home page in WordPress. What if you want to use WordPress to run your entire static site, and also use it as a blog? Well in this article, we will show you how to create a separate page for blog posts in WordPress.

How to Create a Separate Page for Blog Posts in WordPress is a post from: WPBeginner which is not allowed to be copied on other sites.

Related posts:
  1. How to Create a Custom Home Page in WordPress
  2. Create Custom Single Post Templates for Specific Posts or Sections in WordPress
  3. How to Create a Custom Post Types Archive Page in WordPress
]]>
By default WordPress display your content in a blog format on the homepage. Users often modify for their needs by creating a custom home page in WordPress. What if you want to use WordPress to run your entire static site, and also use it as a blog? Well in this article, we will show you how to create a separate page for blog posts in WordPress.

There are few different methods you can use to create a separate page for blog posts. It all depends on which method you used to create the custom home page. If you created the homepage by creating a file called home.php, then you want to follow the method below:

1. First copy your index.php file and save it as blog.php.
2. Make it a Custom WordPress Page Template.
3. Create a new WordPress page in your WP-Admin panel. Title the page Blog, and before you hit publish, make sure you select the custom page template as shown in Step 2.
4. Publish the Page.

Next you need to edit blog.php file. Find the Loop, which should look something like this:

<?php if (have_posts()) : while (have_posts()) : the_post(); ?>

Replace this top part with the code below:

<?php
$temp = $wp_query;
$wp_query= null;
$wp_query = new WP_Query();
$wp_query->query('posts_per_page=5'.'&paged='.$paged);
while ($wp_query->have_posts()) : $wp_query->the_post();
?>

The posts_per_page variable does exactly what it sounds like. It tells WordPress to display X amount of posts on each page. You may change the number from 5 to whatever you like.

Find a line that looks like this:

<?php else : ?>

Remove this code and any else code such as the 404 content etc. You should already have a 404.php file in place for that.

Next you need to find this code:

<?php endif; ?>

Replace it with:

<?php $wp_query = null; $wp_query = $temp;?>

Ladies and gentleman, you now have a separate page for blog posts. Depending on your permalink structure, you can link it in other sites such as twitter, facebook etc. You can also list it in your navigation bar with the WordPress 3.0 Custom Menus.

Method 2

If you want to use the built-in Static / Blog page method, then you can do so as well. This method is less code intensive, but it does not allow for customizations that some developers might want.

Create two new pages, one can be called “Welcome” or whatever you want to call your homepage. The next should be called “Blog” or whatever you want to call your blog page.

If you already have a file called home.php in your theme, then you will need to rename it to welcome.php and make it a Custom WordPress Page Template by adding the codes at the top. Then in your Welcome page, select the Welcome Template.

Go to Settings » Reading:

Settings / Reading in WordPress

Choose the Static options and select your two pages.

Once you do this, you are good to go. If you have any questions, feel free to ask in the comments.

Sources

Nathan Rice
Michael Fields

How to Create a Separate Page for Blog Posts in WordPress is a post from: WPBeginner which is not allowed to be copied on other sites.

Related posts:

  1. How to Create a Custom Home Page in WordPress
  2. Create Custom Single Post Templates for Specific Posts or Sections in WordPress
  3. How to Create a Custom Post Types Archive Page in WordPress

]]>
http://www.wpbeginner.com/wp-tutorials/how-to-create-a-separate-page-for-blog-posts-in-wordpress/feed/ 17