How to create a side blog with WordPress 3.0

Getting ready

So, what are custom post types? That’s simple, custom post types are like a blog post or page, but of a custom defined type.
As an example, I decided to list some promo codes on my other blog CatsWhoBlog. I could have used a good old static page, but updating it and adding new promo codes would have been a pain.

So I created a custom post type, named coupon and a page template to list all coupons. It’s as simple as that, and now managing coupons & promo codes is extremely easy:

Creating the post type

Ok, let’s code. The first thing to do is to create a custom post type. To do so, pick up your theme functions.php file, and add the following:

function create_my_post_types() {
    register_post_type('coupons',
        array(
            'label' => __('Coupons'),
            'singular_label' => __('Coupon'),
            'public' => true,
            'supports' => array(
                'title',
                'excerpt',
                'comments',
                'custom-fields'
	    ),
	    'rewrite' => array(
	        'slug' => 'coupons',
	        'with_front' => false
	    ),
        )
    );
}
add_action( 'init', 'create_my_post_types' );

Once you saved functions.php, you should notice that a new tab appeared in your WordPress dashboard, as shown in the picture below:

So what does this code do?
First, I have created a function which registers a new post type, named coupons. I gave the following parameters to the register_post_type() function:

  • label: Nicename of your post type.
  • singular_label: Pretty self explanatory, the singular label of your post type.
  • public: Allows post type to be seen publicly.
  • supports: Array of data of what the post type supports (editor, excerpt, comments, custom fields, etc…)
  • rewrite: Parameters for url rewriting and general post type display.

The complete parameter list can be found on WordPress Codex.

Then, I “hooked” this function to WordPress init() function using add_action().

Adding data

Now that the post type has been created, you can add data by clicking on the “Add Coupon” (Or whatever you named it) link in WordPress dashboard menu.

You should see the following:

Creating a page template to list custom post types

Now that we have created a custom post type and added some custom posts, we still have to display it. To do so, I have used a page template. You can easily reuse the following code, or adapt it to display in your blog sidebar, for example.
If you want to see a demo of the page template, just click here.

<?php
/*
Template Name: Promo codes Page
*/
?>
<?php get_header() ?>

	<div id="container">
		<div id="content" class="coupons">
			<h1 class="entry-title"><?php the_title(); ?></h1>
			<?php the_content(); ?>

			<?php global $wp_query;
			$page_num = $paged;
			if($pagenum='') $pagenum=1;

			$wp_query = new WP_Query("showposts=20&post_type=coupons&post_status=publish&paged=".$page_num);

			while ($wp_query->have_posts()) : $wp_query->the_post(); ?>

				<div class="post" id="post-<?php the_ID(); ?>">
					<h2><?php the_title(); ?></h2>
					<div class="exerpt"><?php the_excerpt(); ?></div>
				</div><!-- .post -->

			<?php endwhile; ?>

			<div class="navigation"><p><?php posts_nav_link(); ?></p></div>

		</div><!-- #content -->
	</div><!-- #container -->

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

As you can see, the code I’ve used is definitely easy and self-explanatory. In order to fetch a specific post type, you have to specify the parameter post_type=coupons.

That’s all for today, hope you enjoyed this tutorial!

Like CatsWhoCode? If yes, don’t hesitate to check my other blog CatsWhoBlog: It’s all about blogging!

How to create a side blog with WordPress 3.0

JAVA expert be able to install script and customize DBmysql2 by baywatch101

1) Install script 2) I will need to have a new design merged. 3) I will need to connect with any system out there that is open api and add it to this script. like facebook. 4) Some features may be needed to be upgraded… (Budget: $30-250, Jobs: Java, Javascript, JSP, Linux, MySQL)


Tech Writing for blog-$1/500w article by webarticle71

U need to write 500 word articles for a tech blog. Requirements: 1. Acknowledged about current tech world and changes 2. Need to write a sample article before start 3. Very strict about deadline.If u miss deadline,i will not work with u… (Budget: $30-250, Jobs: Articles, Blog, Forum Posting, Research, Technical Writing)


Googleblocking The Site

Hi there,
i have a site which when i try to open in firefox it gives the following warning

Reported Attack Page!

This web page at www.xxxxxxx.com has been reported as an attack page and has been blocked based on your security preferences.

Attack pages try to install programs that steal private information, use your computer to attack others, or damage your system.

Some attack pages intentionally distribute harmful software, but many are compromised without the knowledge or permission of their owners.

i need someone to fix the problem. it should be quick work for someone who has already done this.

Thanks

Need Guaranteed Signups – 1000 per day by keyuria

The winner will have to ensure that our site gets 1000 unique signups per day for a genuine ptc site and remain active for atleast 30 days. The winner will be paid $10 per signup only after the members remain active for 30 days or more… (Budget: $3000-5000, Jobs: Advertising, BPO, Bulk Marketing, Classifieds Posting, Internet Marketing)


20100624 vtiger reports needed – php mysql by adrian078

I need a programmer to either set up about 20 reports within vtiger(preferred) or use an application like php report maker to generate the code and make a report page for vtiger. The reports are all basic things such as: Number of quotes sent (per week, month, quarter, per year)… (Budget: $30-250, Jobs: HTML, MySQL, PHP, vTiger)