2

Thanks in advance for any assistance.

I have a simple 4 page portfolio site I'm trying to build for myself. The pages consist of: Home Page, Print Design, Digital, and Identity.

I have created a custom post type called "portfolio" with categories: "Print Design", "Digital", and "Identity".

When first visiting the site a user will see a grid of ALL posts from the custom post type (5 columns, 4 rows). I am using the following code to pull the custom post type:

<?php 
$items = new WP_Query(array(
'post_type' => 'portfolio', 
'posts_per_page' => 1000
)); 
while ( $items->have_posts() ) : 
$items->the_post();
?>

Each post pulls the featured image into the grid with the following code:

<?php
$src = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), array( 5600,1000 ), false, '' );
?>

So far, all is well. I have a grid layout of 20 items all displaying nicely.

Here is my issue and what I am trying to accomplish:

The home page will always display all 20 posts just as they do now. I want the 'Print Design' page to display all 20 posts as-well BUT I want all posts outside of the "Print Design" category to be 50% opaque and not-clickable.

For example: A user clicks on "Print Design" and is taken to a new page. This page displays 20 posts of which only 3 stand out and are clickable. The other 17 are grey and can't be clicked.

This same idea would be setup for each additional page listed above.

My thoughts are that I should be able to setup a condition that says something like:

"HEY! There are 20 posts on this page! Find all the posts that aren't in category "Print Design" and use this CSS "property"!"

Thanks again! This stuff is fun but also difficult... and also frustrating when I've come so far but can't complete the idea I have.

1

Lifted straight from the codex:

<?php 
if ( in_category( 'pachyderms' )) {
    // They have long trunks...
} elseif ( in_category( array( 'Tropical Birds', 'small-mammals' ) )) {
    // They are warm-blooded...
} else {
    // & c.
}
?>

So, just use in_category to decide how to output each post - whether or not to make it a link, and what classes to use.

while ( $items->have_posts() ) :
    $items->the_post();

$in_category = in_category( 'identity' ); // this should be the slug for your category

Throughout the rest of your code you can then just check if $in_category is true or false, and if it is false skip the anchor tags, or set a specific class etc.

  • Thanks for the quick reply, however, I am not sure I understand what to do just yet. If you don't mind, I've pastebin the code here from my "identity" page, maybe you can look? pastebin.com/TPyTNzGF I may be able to figure this out on my own but I would guess it would take 20 hours before I could get it right. – minemind May 2 '13 at 23:39
  • All I see in that is a slider. – vancoder May 2 '13 at 23:43
  • Oops, it is not a slider. That is the name I gave it. I need to change the name. – minemind May 2 '13 at 23:54
  • It's still just a custom post type, just a misleading name. – minemind May 3 '13 at 0:17
  • I've elaborated slightly in my answer. There really isn't much to it. – vancoder May 3 '13 at 16:31
0

@Vancoder has the right idea. Just use those template tags in your loop and your set.

If you want to display ALL posts properly, you should change your posts_per_page argument to -1:

$query = new WP_Query( 'posts_per_page=-1' );

Just a best practice rather than choosing an unlikely high number.

  • This is not really an answer. It is more of an addendum to vancoder's answer so it would probably be best as a comment. You will need to get 50 rep for that but it shouldn't take long. – s_ha_dum May 2 '13 at 23:48
  • Gotcha. Thanks for the heads up. Learning the ropes. – sagalbot May 3 '13 at 0:44
0
sliders_category to replace your cat texonomy 
sliders to replace your custom post type
'terms' => '3' 3 is your cat id.
multiple cat for 'terms' => array('46','47','49','50','51'),
$args = array(
    'tax_query' => array(
                    array(
                            'taxonomy' => 'sliders_category',
                            'field' => 'id',
                            'terms' => '3'
                        )
                    ),
                    'post_type'=>'sliders',
                    'order'=>'ASC',
                    'posts_per_page'=>-1
);
    query_posts($args);
        while ( have_posts() ) : the_post();  ?>

            //your code here

            <?php 
                endwhile; 
                wp_reset_query();
            ?>
0

1 You could create specific CPT category archive page templates with unique body classes. The coding for this solution will be theme specific.

2 Or use conditional custom body classes.

add_action( 'body_class', 'wpsites_conditional_body_class');
function wpsites_conditional_body_class( $classes ) {
if ( is_post_type_archive() ) {
$classes[] = 'your-custom-class';
return $classes;
    }
}

You will need to add and test the correct conditional tags.

Your Answer

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

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