WordPress.org

Ready to get started?Download WordPress

Forums

Custom Post Type UI
[resolved] How to target specific categories within a custom post type? (2 posts)

  1. alittlereddress
    Member
    Posted 1 year ago #

    Hi,
    I'm using a custom post type, ie. books and have a range of categories within this post type, ie. history, childrens, fiction, non-fiction.

    Just wondering if anyone has a way (not sure how to tackle the php) of accessing the the categories? I have this php on my single page template that says the following:

    <?php if (get_post_type() == 'books') { ?>
    					<?php if ( has_post_thumbnail() ) { ?>
    						<div class="thumbfloat">
    				         <?php the_post_thumbnail(); ?>
    						</div>
    					<?php } ?>
    				<?php } else { ?>
    					<?php if ( has_post_thumbnail() ) { ?>
    				         <?php the_post_thumbnail('single-hero'); ?>
    					<?php } ?>
    				<?php } ?>

    Basically what this is doing is checking to see if the post type is 'books' and if it is, checking that there is an image, and making it a thumbnail size. Otherwise, if the post type is something else, ie. 'magazines' and there is an image, make the image a larger size.

    I wanted to add an extra bit of code into the if statement so that if my post type is books and my category is 'fiction', give it a larger image, otherwise carry on as usual.

    I'm not sure what the variables are that I need to access though...

    <?php if (get_post_type() == 'books' && category_type() ! 'fiction') { ?>
    					<?php if ( has_post_thumbnail() ) { ?>
    						<div class="thumbfloat">
    				         <?php the_post_thumbnail(); ?>
    						</div>
    					<?php } ?>
                                    <?php } elseif (get_post_type() == 'books') { ?>
                                            <?php if ( has_post_thumbnail() ) { ?>
    				           <?php the_post_thumbnail('single-hero'); ?>
    					<?php } ?>
    				<?php } else { ?>
    					<?php if ( has_post_thumbnail() ) { ?>
    				         <?php the_post_thumbnail('single-hero'); ?>
    					<?php } ?>
    				<?php } ?>

    Any help would be incredibly fabulous!
    Thanks all!

    http://wordpress.org/extend/plugins/custom-post-type-ui/

  2. Michael Beckwith
    Member
    Plugin Author

    Posted 11 months ago #

    Looks like this issue is more related to the display of your Custom Post Type, which this UI plugin doesn't have a hand in. Hopefully you found a solution somehow to the issues above though.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic