0

I am creating this custom post(which is some sort of image gallery). Well each custom post also have this taxonomy, which works as a category type/post type.

My question is, how do I create a custom template page, and in that loop the data, which corresponds to the taxonomy? What should the file be named?

THE CUSTOM POST

$gallery_labels = array(
    'name' => _x('Photo gallery', 'post type general name'),
    'singular_name' => _x('Gallery', 'post type singular name'),
    'parent_item_colon' => ''

);
$gallery_args = array(
    'labels' => $gallery_labels,
    'public' => true,
    'publicly_queryable' => true,
    'show_ui' => true,
    'query_var' => true,
    'capability_type' => 'post',
    'supports' => array('title','thumbnail')
);
register_post_type('gallery', $gallery_args);

REGISTER TAXONOMIE

add_action( 'init', 'gallery_taxonomies', 0);

function gallery_taxonomies(){
    register_taxonomy(
        'phototype',
        'gallery',
        array(
            'hierarchical'=> true,
            'label' => 'Photo Types',
            'singular_label' => 'Photo Type',
            'rewrite' => true
        )
    );
}

Lets say I have these taxonomies

name  descripton  slug
A         ...      a
B         ...      b
C         ...      c

and then my custom post which uses the taxonomies (category style)

thumnail    title      phototype
1.png       one a          a
2.png       two a          a
3.png       one b          b
4.png       one c          c
5.png       two c          c

so if I go to the page

myurl.com/phototype=a it should show

  • one a
  • two a
  • You should call your post type gallery. That name is used internally by Wordpress. – Pieter Goosen May 7 '15 at 12:43
  • Thanks for the little tip, just called it mygallery instead. – Sigils May 7 '15 at 12:48
  • Your talking about taxonomy archive pages? – Tom J Nowell May 7 '15 at 12:52
  • Hi Tom, I don't know what a taxonomy archive page is, but I am asking to get all the "custom post" corresponding to the selected garegory(taxonomy). But I actually believe that 'taxonomy archive pages' is what I am searching for. – Sigils May 7 '15 at 13:00
0

I figured out the answer,

since I am registering my taxonomy as phototype I simply have to create a file named taxonomy-phototype.php and inside that I will get the data by looping like I normally would in wordpress

<?php if (have_posts()): ?>
    <?php while (have_posts()) : the_post(); ?>
        <?php the_content(); ?>
    <?php endwhile; ?>
<?php endif ?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.