There are three basic content types in WordPress: posts, pages and comments. Each and every one of these content types has certain features, and comments enable additional interaction with your visitors. If you want to utilize the full power of WordPress, then it is important to understand what each of these types can do. Besides these ones, there are additional content types that can be added through plugins.
Posts
They are the main content type of your blog and one of the most common ways for visitors to come across your website. Each post is associated with a specific category, and a creation date is assigned. Posts can be manually assigned to different categories that you have created, and there is no limit in how much content can be created in a day or within one category. By default, all posts are chronologically shown on your blog’s homepage.
Post are making your website more dynamic, since you can easily change the content by using them. Besides this, visitors can engage through comment on your posts, creating additional content on your website.
Tag for post queries
Template tag query_posts ($args) is used for listing posts.
This tag has a lot of arguments that can be used. For complete list of arguments that can be used with this tag, check out this link:
http://codex.WordPress.org/Template_Tags/query_posts
Tag query_posts is used together with The Loop (http://codex.WordPress.org/The_Loop), which represents a simple loop that goes through every post and returns data to the query_posts tag. The code that you can add in a template file looks like this:
<?php if (have_posts()) : ?>; <?php while (have_posts()) : the_post(); ?> // Display the post and its content here <?php endwhile; ?>
Important tricks with query_posts tag
How to show certain posts from a specific category on your homepage?
All themes are showing posts sorted chronologically on their homepage, regardless of the category they are in. If you want to show posts from only one category, i.e. “Projects”, you need to make the following changes in the index.php file:
query_posts(‘category_name=Projects’);
And, after that, use the loop. This change will show only posts from the category “Projects”.
How to show posts with a specific tag?
If you want to show only posts with a certain tag, i.e. “Programming”, you can change the following in the index.php file:
query_posts(‘tag=Programming’);
Now, only posts with the tag “Programming” will be shown.
You can also show only posts from a specific author. Here are changes that will enable this:
query_posts(‘author_name=Admin’);
How to display sticky post on the homepage?
If you want to show a sticky post on your homepage, the following option will achieve that:
The sticky post will be shown above other posts and, what is important, there can be more than one sticky posts.
If you want to show only sticky posts on your homepage, then change the following in your theme’s index.php file:
query_posts(array(‘post__in’=>get_option(‘sticky_posts’)));
This change will make your homepage show only sticky posts.
Pages
At the beginning, WordPress was used as an efficient blogging platform. However, as the platform grew, a need for expanding WordPress’ functionalities to match other CMS solutions appeared, since its usage shifted from blogging to development of other website types. From that need came to life a page creation feature.
Pages are static posts. They are located in the database in the same way as posts.
They can have comments, as well as pinback and trackback options.
The main difference from posts is that pages are not shown chronologically, but they can be shown in a tree structure, where one page can be parent to another etc.
Also, additional templates can be made for pages.
Tag for page query
Template tag wp_list_pages( $args ) is being used for listing pages as links.
This tag can also take a lot of arguments, of which the complete list can be found here:
http://codex.WordPress.org/Template_Tags/wp_list_pages
Below is a part of the code used in sidebar.php file where this tag has been used:
<ul role=”navigation”> <?php wp_list_pages(‘title_li=<h2>Pages</h2>’ ); ?> <li><h2>Archives</h2> <ul> <?php wp_get_archives(‘type=monthly’); ?> </ul> </li> <?php wp_list_categories(‘show_count=1&title_li=<h2>Categories</h2>’); ?> </ul>
Important tricks with wp_list_pages
Here are some small tricks that you can make with this useful tag.
How to change the title of the page list?
First, you need to find the wp_list_pages tag in your theme. In Twenty Ten theme it is located in the sidebar.php file.
Replace the line:
<?php wp_list_pages(’title_li=<h2>Pages</h2>’ ); ?> with this one: <?php wp_list_pages(’title_li=<h2>Documents</h2>’ ); ?>
The title_li argument is defining what title will be shown at the top of every page list in your WordPress. By default it is Pages, but you can change it to anything.
How to change sorting in pages list?
By default, the pages list is shown in ascending order. If you want to list your pages in descending order, then use the sort_order argument. Here is the code for that:
wp_list_pages(’title_li=<h2>Documents</h2>&sort_order=DESC’);
Pages can be sorted by publishing date also. So, if you want to sort pages in descending order by publishing date, the following code will be quite useful:
wp_list_pages(’title_li=<h2>Documents</h2>&sort_order=DESC&sort_column= post_date&show_date=created’ );
How to remove certain page from the list?
If you want to remove a certain page from the list, i.e. “About us” page, then look at the admin panel for the page’s ID. After that, if the page ID is for example 3, then the next code will remove it from the view:
wp_list_pages(’title_li=<h2>Documents</h2>&exclude=3′);
After this change, the “About us” page will not be visible in the sidebar.
Comments
Comments are one of the most interesting features in WordPress. When they are on, they can create a fully pledged community directly on your blog. It is often the case that the content in the comments is more interesting than in the post itself.
Tag for listing comments
Template tag wp_list_comments ($args); is used for listing WordPress comments.
As in previous cases, this tag also can take a number of arguments. Their list can be found in this link:
http://codex.WordPress.org/Template_Tags/wp_list_comments
The tag is in the comments.php theme file; part of the code from this file can be seen here:
<?php if ( have_comments() ) : ?> <h3><?php comments_number(‘No Responses’, ‘One Response’, ‘% Responses’ );?> to “<?php the_title(); ?>”</h3> <div> <div><?php previous_comments_link() ?></div> <div><?php next_comments_link() ?></div> </div> <ol> <?php wp_list_comments(); ?> </ol> <div> <div><?php previous_comments_link() ?></div> <div><?php next_comments_link() ?></div> </div> <?php else : // this is displayed if there are no comments so far ?> <?php if ( comments_open() ) : ?> <!– If comments are open, but there are no comments. –> <?php else : // comments are closed ?> <!– If comments are closed. –> <p>Comments are closed.</p> <?php endif; ?> <?php endif; ?>
Important tricks with wp_list_comments
How to change the order of comments?
By default, comments are being shown by date, in ascending order. Therefore, the oldest comment is being shown first, with newer ones shown below.
However, if you want to display the newest comments first, so you could show your visitors the latest content right away, you need to change the wp_list_comments tag which resides in the comments.php file:
wp_list_comments(array(’reverse_top_level’ => true));
This change will display the latest post first. Besides this, WP dashboard has an option within the discussion settings section where you can set that all new comments are shown on several pages.
Tag for comment pop-up display
Template tag comments_popup_link(‘zero’,’one’,’more’,’CSSclass’,’none’); is being used for showing the link for the comment pop-up.
The list of arguments for this tag can be found on this link:
http://codex.WordPress.org/Template_Tags/comments_popup_link
As usual, the code is located in the index.php file of your theme.
How to change the link text when to post has no comments?
When the post hasn’t got any comments yet, a “No comments” text appears in the pop-up link.
Of course, this text can be changed to any other text. You need to change the following:
comments_popup_link(‘Postavite komentar »’, ’1 Comment »’, ‘% Comments »’);
How to hide a link if a post doesn’t allow comments?
As you can turn on comments, you can also turn them off on the whole website or just on a certain post. If you turn off the comments in a post, then it is not a good idea to show the comments pop-up link.
So, if you don’t want to show link when comments are turned off on a post we should change the following in a comments_popup_link() tag within index.php file:
<?php if ( comments_open() ){comments_popup_link(‘No Comments »’, ’1 Comment »’, ‘% Comments »’);} ?>
After this change, the link will show only on posts where comments are turned on:
Categories
Categories are not a content type in WordPress, but they are very important because they help you organize posts. Not only will you be able to separate posts, but you can also group similar post by theme or content type. This will significantly ease the process of finding content for your visitors.
Tag for category list display
Template tag wp_list_categories( $args ); is used for listing categories as links.
List of all arguments for this tag can be found on the following link:
http://codex.WordPress.org/Template_Tags/wp_list_categories
The following code is a part of the sidebar.php file:
<ul role=”navigation”> <?php wp_list_pages(‘title_li=<h2>Pages</h2>’ ); ?> <li><h2>Archives</h2> <ul> <?php wp_get_archives(‘type=monthly’); ?> </ul> </li> <?php <strong>wp_list_categories(‘show_count=1&title_li=<h2>Categories</h2>’);</strong> ?> </ul>
Important tricks from the wp_list categories
How to show or remove the number of posts within the category?
When you list all categories on your WordPress site, you can set to display the number of posts within that category. This feature is controlled by the show_count argument.
If the parameter is set like this show_count=1 the number of posts within the categories will be shown.
wp_list_categories(’show_count=1&title_li=<h2>Categories</h2>’);
wp_list_categories(‘show_count=0&title_li=<h2>Categories</h2>’);
How to limit the number of categories in the wp_list_categories?
Within the wp_list_categories parameter you can limit how many categories will be shown. This is especially useful if you have a lot of categories, but you want to show only a few of them in the sidebar.
The maximum number of categories that will be shown depends on the “number” argument in the wp_list_categories tag.
If you want to limit the number of categories in the list, you can use:
wp_list_categories(’show_count=0&title_li=<h2>Categories</h2>&number=2′);
How to remove a certain category?
If you want to remove a certain category from the list of categories, you need to look for the category id in the admin panel. After that you need to change the following in the wp_list_categories tag:
wp_list_categories(’show_count=0&title_li=<h2>Categories</h2>&exclude=3′);
After this change, the category with ID:3 will be removed from the list.
Conclusion
These are the basic content types in WordPress. Small changes that we’ve shown here can significantly change the look of your blog, and enable visitors to navigate with more ease as well to find what they are looking for. This gives you a better website structure which will be rewarded with more visits and increased loyalty from your visitors.
Source:wpwebhost
0 Comments