Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Custom Archive Template for Custom Post Types WordPress

  • SOLVED

I need help with a custom archive page template to achieve the following:

<strong>Archive for "Trustees" page </strong>where I want to display different Custom Post Types (using "Custom Post Type UI").
I have <strong>Post Type "Directors"</strong> with Taxonomies "Position" and "Location" (only two location values will be used: "USA" and "Europe") and I have <strong>Post Type "Staff" </strong>with Taxonomies "Position" as well and "Trustee".

On the Archive page I'd like the following to be displayed:
- <h2>Directors USA</h2> followed by all "director" posts tagged with "location usa"
- <h2>Directors Europe</h2> followed by all "director" posts tagged with "location europe"
- <h2>Staff</h2> followed by all "staff" posts tagged with "trustee yes"

I want all the posts on this page displayed the following way:
Thumbnail, post title and "position" (if filled out).

I can do the CSS for it, but I need help with the custom archive tempate. The site is built on Genesis and Child Theme and I want this within the standard loop.

Answers (3)

2011-08-17

Ivaylo Draganov answers:

Hello,

please try something like that in your template:
[[LINK href="http://pastebin.com/AP5QNiHK"]]http://pastebin.com/AP5QNiHK[[/LINK]]

There are some comments inside the code to make it more clear to you.

EDIT:
I've fixed some fatal errors in the code - please try the updated version above. I've also wrapped it up as a page template. You just need to adapt it to your theme.


Sonja comments:

Page template code would be fine too, but the code you provided had two errors ) was missing in two spots and it doesn't pull in the posts ( http://bit.ly/pgKSxX ). First code did but the h2 titles are stuck on the top of the page ( http://sonjaleix.com/clients/kenya/directors/ )
Also I'd like the posts sorted from oldest to newest pls.


Ivaylo Draganov comments:

Please try the updated code (it has reverse sorting by date + showing all posts + minor improvements):
[[LINK href="http://pastebin.com/jSVBCRnh"]]http://pastebin.com/jSVBCRnh[[/LINK]]

I've tested it on my sandbox install:
http://test.druuf.com/wordpress/?page_id=2

I've also used Custom Post Type UI to create the post types and taxonomies.


Sonja comments:

I had to tweak it a bit to better style it. If you could help me tweak one more thing:
I want the thumbnail to be linked to the post as well and
I don't want the Position taxonomy to be linked.


Ivaylo Draganov comments:


Ivaylo Draganov comments:

Alright :--) Glad you figured out the styling. Here comes the updated code! But I've changed something in order to avoid code repetition - the part displaying the posts is the same, so I've moved it to a separate file. Use this for the page template:
[[LINK href="http://pastebin.com/jSVBCRnh"]]http://pastebin.com/jSVBCRnh[[/LINK]]

And create a new file called <em>loop-trustees.php</em> in the themes main directory. In this file place the following code:
[[LINK href="http://pastebin.com/yaARQyqT"]]http://pastebin.com/yaARQyqT[[/LINK]]

This file will be loaded at the places were <em><?php get_template_part( 'loop', 'trustees' ); ?></em> is called.

If you wish to not use the template part approach, just copy the code back to the original place and remove <em>get_template_part</em> calls.

I hope that it all makes sense.


Sonja comments:

Thanks I patched it together.

2011-08-17

Romel Apuya answers:

have you tried this plugin?

[[LINK href="http://wordpress.org/extend/plugins/custom-post-type-archives/"]]http://wordpress.org/extend/plugins/custom-post-type-archives/[[/LINK]]


Romel Apuya comments:

or this one :

[[LINK href="http://wordpress.org/extend/plugins/simple-custom-post-type-archives/"]]http://wordpress.org/extend/plugins/simple-custom-post-type-archives/[[/LINK]]

2011-08-19

Gabriel Reguly answers:

Hi Sonja,

Don't forget to vote for the winner of the prize.

[[LINK href="http://wpquestions.com/question/pickAWinner/id/2851"]]http://wpquestions.com/question/pickAWinner/id/2851[[/LINK]]

Regards,
Gabriel