Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have a CPT registered that is called lessons with a custom taxonomy (category) that is called courses. I want the /courses page (archive-courses.php?) to display the individual courses (i.e. "online marketing", "paid advertising") and not the individual posts (lessons).

Would this mean I'd just customize the loop, or a complete custom WP_Query?

share|improve this question

2 Answers 2

up vote 3 down vote accepted

If you'd like to list the individual courses, i.e. the taxonomy terms, you'd use neither WP_Query nor the WP standard Loop.

Instead, make use of the get_terms function to retrieve the courses. It returns an array of term objects (if the taxonomy does exist and has terms matching the function arguments). Iterate over that and do something with it, such as displaying a list of links to the lessons:

$courses = get_terms( 'courses' );

if ( $courses ) {
    echo '<ul class="course-list">';

    foreach ( $courses as $course ) {

        echo '<li>' .
            '<a href="/courses/' . $course->slug . '" ' .
                'title="' . sprintf( 'View lessons of %s', $course->name ) . '">' .
                    $course->name .
            '</a>' .
        '</li>';

    }

    echo '</ul>';
}
share|improve this answer
    
That makes complete sense. Thank you so much! –  Zach Russell Apr 6 '13 at 22:07

Its look like you calling Custom Post (archive-courses.php) not taxonomy. Try this taxonomy-courses.php also have a look Custom_Taxonomies_display

share|improve this answer
    
That would work for me if the courses page was a taxonomy archive page, it's not though. It is the archive of my custom post type. –  Zach Russell Apr 6 '13 at 22:19
    
yes! you are right. my mistake! –  Furqan Apr 6 '13 at 22:25
    
I appreciate the feedback though! –  Zach Russell Apr 6 '13 at 22:29

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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