Trying to show category of post
-
https://laurietonhotel.com.au/whats-on/
If you visit the link I’ve provided, you will see a black bar at the bottom of each post where I’m trying to show an icon based on the category the custom post is coming from.
I have the following page template that I’ve customised:
<?php /* Template Name: Cr3ativPortfolio-4ColumnFilterable */ ?> <?php get_header(); ?> <div id="content" class="clearfix fullwidth"> <div id="left-area"> <?php get_template_part('includes/top_info'); ?> <?php if(have_posts()) : while(have_posts()) : the_post(); ?> <!-- Start of wrapper --> <div class="cr3ativeportfolio_wrapper"> <?php the_content(' '); ?> <?php endwhile; ?> <?php else: ?> <p> <?php _e( 'There are no posts to display. Try using the search.', 'cr3atport' ); ?> </p> <?php endif; ?> <ul id="cr3ativeportfolio_portfolio-filter"> <li><a href="#bistro-deals" title="" rel="bistro-deals" id="bistro-deals">Bistro<br />Deals</a></li> <li><a href="#gig-guide" title="" rel="gig-guide" id="gig-guide">Gig<br />Guide</a></li> <li><a href="#special-events" title="" rel="special-events" id="special-events">Special<br />Events</a></li> <li><a href="#weekly-events" title="" rel="weekly-events" id="weekly-events">Weekly<br />Events</a></li> <li id="showallright"><a href="#all" title="" id="show-all"> Show All</a></li> </ul> <?php $loop = new WP_Query(array('post_type' => 'cr3ativportfolio', 'posts_per_page' => -1, 'showposts' => 9999999 )); $count =0; ?> <!-- Start of cr3ativeportfolio_portfolio-wrapper --> <div id="cr3ativeportfolio_portfolio-wrapper"> <!-- Start of cr3ativeportfolio_portfolio-list --> <ul id="cr3ativeportfolio_portfolio-list"> <?php if ( $loop ) : while ( $loop->have_posts() ) : $loop->the_post(); ?> <?php $terms = get_the_terms( $post->ID, 'cr3ativportfolio_type' ); if ( $terms && ! is_wp_error( $terms ) ) : $links = array(); foreach ( $terms as $term ) { $links[] = $term->name; } $links = str_replace(' ', '-', $links); $tax = join( " ", $links ); else : $tax = ''; endif; ?> <li class="cr3ativeportfolio_portfolio-item <?php echo strtolower($tax); ?> all"> <div class="cr3ativeportfolio_thumb"> <div class="cr3ativeportfolio_mask"> <?php the_post_thumbnail('slide'); ?> </div> </div> <span class="cr3ativeportfolio_title"><?php the_title (); ?></span> <div class="cr3ativeportfolio_port_date"> <strong><?php echo get_post_meta($post->ID, 'cr3ativportfolio_leftintrotext', $single = true); ?></strong> </div> <div class="cr3ativeportfolio_content"> <?php the_content(); ?> </div> <div class="cr3ativeportfolio_footer"> <?php if(in_category('weekly-events')) { echo esc_html('<i class="icon-weeklyevents"></i>'); } elseif(in_category('special-events')) { echo esc_html('<i class="icon-specialevents"></i>'); } elseif(in_category('gig-guide')) { echo esc_html('<i class="icon-gigguide"></i>'); } elseif(in_category('bistro-deals')) { echo esc_html('<i class="icon-bistrodeals"></i>'); } else { echo esc_html(''); } ?> </div> </li> <?php endwhile; else: ?> <?php endif; ?> </ul> <div class="cr3ativeportfolioclear"></div> </div> <!-- end #portfolio-wrapper--> </div> <!-- end #left-area --> </div> <!-- end #content --> <!-- Start of clear fix --> <div class="cr3ativeportfolioclear"></div> </div> <!-- End of page wrap --> <?php get_footer (); ?>
You will notice I’ve created a new section down the bottom called “cr3ativeportfolio_footer” and here I’m trying to determine what the category is. Should I be looking for a custom taxonomy instead? I think I’m almost there but can’t get it to work.
I’m not the strongest when it comes to php coding so any help would be terrific.
Viewing 6 replies - 1 through 6 (of 6 total)
Viewing 6 replies - 1 through 6 (of 6 total)
- The topic ‘Trying to show category of post’ is closed to new replies.