Custom Post Type Archives Part 3

Part 2 explained how to create a widget to show the chronological links for the sermon post type. This post will explain how I generalized the widget to show the chronological links for a custom post type specified in the the widgets administration panel.

It uses the same technique as described in the Custom Taxonomy widget post.

Widget function

Add the line $post_type = $instance['posttype']; after the line initializing the $title variable.

Change the hardcoded value of ‘sermon’ in the custom get_post_type_archives call to $post_type

Update function

Add the line $instance['posttype'] = strip_tags($new_instance['posttype']);

Form function

Add the line $post_type = strip_tags($instance['posttype']);

Copy the line for the title text field and paste it right below the original line. Modify all references to the title text field and set it to ‘posttype’. The value which should be echoed out is $post_type

Using the Widget

There will now be an extra field in the widget administration. Type in the name of the custom post type here.

Custom Post Type Archives Part 4

Advertisements

One thought on “Custom Post Type Archives Part 3”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s