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

Listing One Taxonomy from a Custom Post Type WordPress

  • SOLVED

Howdy!

I want to set up a page template (I know this part) to query through a specific taxonomy from a custom post type.

Here's my project's example:

The site I'm working on has a product category. I created a custom post type called Products. I then created a taxonomy called Product Line. I have a page template called Product Page.

On this template I want to list all the Product Lines (taxonomies) from the Product custom post type.

I've used this plugin to add an image to taxonomies: [[LINK href="http://wordpress.org/extend/plugins/taxonomy-images/"]]http://wordpress.org/extend/plugins/taxonomy-images/
[[/LINK]]
I would like it if you could explain to me how to use that here as well. The image and the title of the taxonomy to click to that specific taxonomy page. Showing all the products under that product line.

Make sense? I've attached a picture of what the end result should look like.

To sum it up, I should have a custom page that lists all the terms in my Product Line taxonomy, with descriptions (native WP feature for terms) and images (from the above plugin). Clicking on any term or image would then take you to the taxonomy archive page, listing all products in that Line.

Answers (4)

2011-12-14

Hai Bui answers:

Hi,
Please try this:
$terms = apply_filters( 'taxonomy-images-get-terms', '', array(
'taxonomy' => 'product-line'
) );
if ( ! empty( $terms ) ) {
echo '<ul>';
foreach( (array) $terms as $term ) {
$termlink=esc_url( get_term_link( $term, $term->taxonomy ) );
echo '<li>';
echo '<a href="' . $termlink . '">' . wp_get_attachment_image( $term->image_id, 'detail' ) . '</a>;
echo '<a href="' . $termlink . '">' . $term->name . '</a>;
echo $term->description;
echo '</li>';
}
echo '</ul>';
}


Let me know if you have any questions/problems.


David Becerra comments:

You're on to something!

There were some syntax apostrophes missing, but those are an easy fix.

The page is linking to the single template instead of showing all of the products

I'm trying to get the image bigger too. I have registered a image size: 'thumb280x150'

Here's the code:

$terms = apply_filters( 'taxonomy-images-get-terms', '', array(
'taxonomy' => 'productline',
'image_size' => 'thumb280x150'

));

if ( ! empty( $terms ) ) {

echo '<ul>';

foreach( (array) $terms as $term ) {

$termlink=esc_url( get_term_link( $term, $term->taxonomy ) );

echo '<li>';

echo '<a href="' . $termlink . '">' . wp_get_attachment_image( $term->image_id, 'detail' ) . '</a>';

echo '<a href="' . $termlink . '">' . $term->name . '</a>';

echo $term->description;

echo '</li>';

}

echo '</ul>';

}


Any the result is in the image attached.