0

I have created a custom post type "Highlights"

function create_post_type_highlights() {  
    register_post_type( 'highlights',  
        array(  
            'labels' => array(  
                'name' => __( 'Community News' ),  
                'singular_name' => __( 'highlights' ) ,
                'add_new'            => _x( 'Add New News', 'Community News' ),
                'add_new_item'       => __( 'New Community News' )

            ),  
        'public' => true,  
        'menu_icon' => 'dashicons-megaphone', 
        'taxonomies'  => array( 'category' ),
        'rewrite' => array('slug' => 'highlights'),
        'hasArchive' => true,
        'supports' => array( 'title','editor')  
        )  
    ); 
    flush_rewrite_rules(); 
}  
add_action( 'init', 'create_post_type_highlights' );

In the Custom Loop Template in want it to show only the post with category "Featured" and a sidebar with other categories listed

    <div class="contain_area">

<?php query_posts( array('post_type'=> 'highlights','category_name'=> 'featured') );?>

<?php if (have_posts()) : ?>

<?php while (have_posts()) : the_post(); ?> 

    <div class="communitybox">

        <h1><a href="<?php the_permalink(); ?>"><?php the_title();?></a></h1>

        <div class="block_img"><a href="<?php the_permalink(); ?>"><img src="<?php the_field('the_image');?>" alt="<?php the_title();?>"/></a></div>

        <div class="block_det">

            <?php echo substr(get_the_excerpt(), 0,405); ?>

            <div class="hightlight_more"><a href="<?php the_permalink(); ?>">READ MORE</a></div>

        <div class="clr"></div>

        </div>

    <div class="clr"></div>

    </div>

<?php endwhile; ?>

<?php endif; ?>

<?php wp_reset_query(); ?>
    </div>
    <div class="sidebar_area">

        <?php dynamic_sidebar('news-sidebar');?>

    </div>

the sidebar showing the categories list

But when I click on the category menu it showing all the post instead of the particular category page

<div class="contain_area">

<?php query_posts( array('post_type'=> 'highlights','category' => $category->slug,) );?>
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?> 
    <div class="communitybox">

        <h1><a href="<?php the_permalink(); ?>"><?php the_title();?></a></h1>

        <div class="block_img"><a href="<?php the_permalink(); ?>"><img src="<?php the_field('the_image');?>" alt="<?php the_title();?>"/></a></div>

        <div class="block_det">

            <?php echo substr(get_the_excerpt(), 0,405); ?>

            <div class="hightlight_more"><a href="<?php the_permalink(); ?>">READ MORE</a></div>

        <div class="clr"></div>

        </div>

    <div class="clr"></div>

    </div>
<?php endwhile; ?>
<?php endif; ?>
<?php wp_reset_query(); ?>
    </div>
    <div class="sidebar_area">
        <?php dynamic_sidebar('news-sidebar');?>
    </div>

Appreciate your help

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.