• Resolved Aimee

    (@greatdanemaniac)


    Hi!
    I got this code off of WP, and it’s awesome.

    <?php
    /**
     * Template Name: Page for the tutorials
     *
     * Selectable from a dropdown menu on the edit page screen.
     */
    ?>
    
    <?php get_header(); ?>
    
    		<div id="container">
    			<div id="content">
    <?php
    $type = 'tutorial';
    $args=array(
      'post_type' => $type,
      'post_status' => 'publish',
      'paged' => $paged,
      'posts_per_page' => 10,
      'caller_get_posts'=> 1
    );
    $temp = $wp_query;  // assign orginal query to temp variable for later use
    $wp_query = null;
    $wp_query = new WP_Query($args);
    ?>
    
    <?php
    
     get_template_part( 'loop', 'index' );?>
    			</div><!-- #content -->
    		</div><!-- #container -->
    
    <?php get_sidebar(); ?>
    <?php get_footer(); ?>

    However, I do not know on how to display the taxonomies there, for my custom post type. I got it to work before by using this type of code, and that worked awesome as well, except for the fact that the metadata (posted in, by author etc.) wasn’t displayed.

    <?php
    /*
    Template Name: Tutorials
    */
    ?>
    
    <?php get_header(); ?>
    
        <div id="container">
    
          <div id="content">
    
    <?php
    $tutorial = new WP_Query( array( 'post_type' => 'tutorial', 'posts_per_page' => 10, 'orderby' => 'rand' ) );
    
    while ( $tutorial->have_posts() ) : $tutorial->the_post();
    
    	the_title( '<h2><a href="' . get_permalink() . '" >', '</a></h2>' );
    	?>
    	<div class="entry-content">
    		<?php the_content(); ?>
    
    <?php echo get_the_term_list( $post->ID, 'language', '<p>Language: ', ', ', '</p>' ); ?>    
    
        </div>
    
    <?php endwhile; ?>
    
          </div><!-- #content -->
    
        </div><!-- #container -->
    
    <?php get_sidebar(); ?>
    
    <?php get_footer(); ?>

    Also I’d like to know how to get the CPT’s displayed within the loop. Justin Tadlock’s recipe for that isn’t working anymore…

    add_filter('pre_get_posts','my_get_posts');
    
    function my_get_posts($query ){
    
    	if ( is_home())
    		$query->set('post_type', array('post', 'page', 'album', 'movie', 'quote', 'attachment'));
    
    	return $query;

    Thanks a lot!

    [sig moderated]

Viewing 6 replies - 16 through 21 (of 21 total)
  • I have a custom post type of book. That custom post type has a taxonomy called genre. As an example, using the TwentyTen theme, in single.php, after this line
    <?php the_content(); ?>

    I put this:

    <php
    echo get_the_term_list( $post->ID, 'genre', '<p>Genre: ', ', ', '</p>' );
    ?>

    And I see the Genre terms for the Book I am viewing.

    Thread Starter Aimee

    (@greatdanemaniac)

    Yes, I’ve tried that and it works, but not if I put several in there, then it stops working. Like this:

    <php
    echo get_the_term_list( $post->ID, 'language', '<p>Language: ', ', ', '</p>' );
    ?>
    
    <php
    echo get_the_term_list( $post->ID, 'subject', '<p>Subject: ', ', ', '</p>' );
    ?>

    etc.
    One works fine, but not more… that’s the whole problem…

    Same scenario I just described with additional taxonomy of writer and it works:

    <?php echo get_the_term_list( $post->ID, 'genre', '<p>Genre: ', ', ', '</p>' ); ?>
    <?php echo get_the_term_list( $post->ID, 'writer', '<p>Writer: ', ', ', '</p>' ); ?>
    Thread Starter Aimee

    (@greatdanemaniac)

    What?

    Then something must be terribly wrong with my theme and blog! That just does not work for me, even though it should!

    I’m gonna try and get this to work until my fingers bleed and I’ll get back to you with the results… this is insane!

    Thread Starter Aimee

    (@greatdanemaniac)

    I’ve solved it! And I feel so F*cking stupid!

    I totally forgot that I erased all of my taxonomies for certain posts, and when I got them back, everything is working. I haven’t tried to put the code in the loop, but I’ll try. Otherwise I’ll just use several custom page templates for both single and page display… I’d like to have both.

    I’d like to send you flowers for the help you’ve got me, Michael. Thanks a bunch!

    You are welcome, glad you got it sorted out.

    I’ll mark this resolved. Happy coding!

Viewing 6 replies - 16 through 21 (of 21 total)
  • The topic ‘Display taxonomies using custom page template?’ is closed to new replies.