0

thanks for your attention.

I have a custom post type I've built called "Portfolio Items". These posts layout a nice 6 column grid and are contained within 4 different categories.

I've created 4 separate pages and each page will have its own page template.

The page template will be different for each page. Depending on the page and category I setup in each template should change the style of a post and remove the hyperlink.

<?php 
$items = new WP_Query(array(
    'post_type' => 'portfolio', 
    'posts_per_page' => -1
)); 
while ( $items->have_posts() ) : 
   $items->the_post();
   $categories = get_the_category($post->ID);
 ?>

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

<?php 
if ( in_category( 'print' )) { ?>

    <a href="#port-<? the_ID(); ?>" data-toggle="modal">
    <div class="span2" id="square" style="background: url(<?php echo $src[0]; ?>); background-size:100%;  background-repeat:no-repeat; background-position:center;">
    <span>
      <h3>
        <?php the_title();?>
      </h3>
    </span>
   </div>
    </a>

<?php } else { ?>

    <div class="span2" id="square" style="background:#000;">
    <span>
      <h3>
        <?php the_title();?>
      </h3>
    </span>
   </div>

<?php } ?>

( Pastebin of the same code: http://pastebin.com/NnpW24AY )

I'm trying to tell it that if the post is in a certain category, then it should display as it was intended, else, it should not have a hyperlink and the background should be black.

All this does right now is duplicates the post, leaving the original. So what I have is the regular post, then a black box post without a hyperlink next to it.

Any ideas what I am doing wrong here?

  • Your code seems to work for me. The output toggles by category as I would expect. If there is a problem I don't think it is in the code you posted on the pastebin. – s_ha_dum May 12 '13 at 15:32
0

You're missing the

endwhile

Maybe you didn't copy/paste it in, but if it's not in your file you'll want to add it.

  • While you may be right, this is not really an asnwer to the question. Once you get a little bit of rep you can post comments. – s_ha_dum May 12 '13 at 17:17

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.