Forums

List posts in a category on horizontal navigation (1 post)

  1. MarjWyatt
    Member
    Posted 1 year ago #

    The Development Site URL: http://creativeconundrum.com/mdsc/

    I've written this custom function to display the posts within the Audio/Video Resources category from the horizontal navigation tab.

    <?php
        function mdsc_avposts() {
    	global $wpdb, $post_link;
    	$sort_code = 'ORDER BY name ASC, post_date DESC';
    	$the_output = '';
    
        $mdsc_post_list = (array)$wpdb->get_results("
            SELECT DISTINCT ID, post_title, post_date, post_name
            FROM wp_posts, wp_term_relationships, wp_term_taxonomy
            WHERE wp_posts.ID = wp_term_relationships.object_id
            AND wp_term_relationships.term_taxonomy_id = '13'
            AND wp_term_taxonomy.taxonomy = 'category'
            AND wp_posts.post_status = 'publish'
            AND wp_posts.post_type = 'post'	");
    
    	if ( empty($mdsc_post_list) )
    		return NULL;
    
    	$mdsc_post_list = array_values($mdsc_post_list);
    
    	$the_output .= '<ul>';
    	foreach ($mdsc_post_list as $post_link) {
            $class = 'post-item post-item-' . $mdsc_post_list->ID;
            $current_post = get_the_ID();
            if ( isset($current_post) && $current_post && is_singular() && ($mdsc_post_list->ID == $current_post) )
                $class .=  ' current-post';
                $the_output .= '<li class="' . $class . '"><a class="" href="' . get_permalink($mdsc_post_list->ID) . '">' . apply_filters('the_title', $mdsc_post_list->post_title) . '</a></li>';
    		$the_output .= '</li>';
    	}
    	$the_output .= '</ul>';
    	echo $post_link;
    }
    ?>

    The SQL extracts the data I want when I run it from phpMyAdmin.

    How do I make the part work that will actually display the post/s in that category from the navigation list?

    I'm aware there are many plugins for displaying "latest posts" in a sidebar widget but that isn't what is needed here.

    If anyone has any ideas, please enlighten me.

    Thanks in advance!

Topic Closed

This topic has been closed to new replies.

About this Topic