0

i'm making modifications to a portfolio theme. the theme has the blog and portfolios. the portfolios are custom post types with their respective taxonomies. the theme homepage only displays one portfolio. that is, it only shows the posts for one custom post type. the theme displays the most recent posts for each category of the custom post type and creates a filter menu that is populated with the categories. this way a user can filter the displayed posts by category like "graphic design" and a JS script hides the posts that are not of that category. i need to mix the posts of all portfolios and the blog on the homepage. so i need to query all the recent posts from all portfolios and the blog, populate the filter menu with post types, and then pass that over to the JS script to hide the posts that are not of the selected post type.

i've managed to query all the recent posts from all portfolios and the blog, and populate the filter menu with post types using the code below: THE COMMENTED CODE IS THE ORIGINAL CODE, e.g. $terms

 <?php 
$args=array(
    'post_type' => array('post', 'test-bscm', 'test-btum', 'test-other', ),
    'posts_per_page' => 16
);
$temp = $wp_query; 
$wp_query = null;
$wp_query = new WP_Query();
$wp_query->query($args);
/*$terms = get_terms($pcat);*/
?>

//populate the filter with post types
<?php 
$args=array(  'show_in_menu' => true);
$output = 'names';
$terms = get_post_types($args);
?>

<!-- Portfolio Filters
================================================== -->

<?php if ($home_portfoliolayout=="No Categories") { 
    echo '<div class="sixteen columns row portfolio_filter" style="display: none;">';
} else if ($home_portfoliolayout=="Categories") {
    echo '<div class="sixteen columns row portfolio_filter">';
} ?>
    <ul>
        <?php
        echo '<li><a class="portfolio_selector" data-group="all-group" href="#">'.__('All Projects', 'apex').'</a><span>|</span></li>';
        foreach ( $terms as $term ) {
            $filter_last_item = end($terms);
            if($term!=$filter_last_item){
                echo '<li><a class="portfolio_selector" data-group="'.str_replace(' ', '-', $term).'" href="#">'.ucwords(str_replace('-', ' ', $term)).'</a><span>|</span></li>';
            }else{
                echo '<li><a class="portfolio_selector" data-group="'.str_replace(' ', '-', $term).'" href="#">'.ucwords(str_replace('-', ' ', $term)).'</a></li>';
            }
        }
        ?>
    </ul>
</div><div class="clear"></div>

i am able to see a 16 posts that represent the most recent posts to the blog, test bscm portfolio, test bum portfolio, and the test other portfolio. the filter shows: All Projects, Post, Pages, Test Bscm, Test Btum, and Test Other. i need to remove Pages from the results because it is not needed. here's the code to how the results are displayed and so how the JS script hides posts...

    <!-- Portfolio Teasers
================================================== -->

<div class="sixteen columns row <?php echo $folioteasers ?> portfolio">

    <?php if ($wp_query->have_posts()) : ?>
    <?php while ( $wp_query->have_posts() ) : $wp_query->the_post(); ?>

    <?php   
        $custom = get_post_custom($post->ID);
        $foliocatlist = get_the_term_list( $post->ID, $pcat, '', ', ', '' );
        $entrycategory = get_the_term_list( $post->ID, $pcat, '', '_', '' );
        $entrycategory = strip_tags($entrycategory);
        $entrycategory = strtolower($entrycategory);
        $entrycategory = str_replace(' ', '-', $entrycategory);
        $entrycategory = str_replace('_', ' ', $entrycategory);
        $entrytitle = get_the_title();
        $blogimageurl = wp_get_attachment_url( get_post_thumbnail_id($post->ID) );
        if($blogimageurl==""){
            $blogimageurl = $templateurl.'/images/demo/460x272.jpg';
        }
    ?>

    <div class="<?php echo $foliocolumns ?> columns teaser all-group <?php echo $entrycategory ?>">
       <a href="<?php the_permalink(); ?>" data-text="&raquo; <?php _e('Visit Project', 'apex'); ?>" class="hovering"><?php echo '<img src="'.get_template_directory_uri().'/functions/thumb.php?src='.$blogimageurl.'&amp;h=272&amp;w=460&amp;zc=1" alt="" class="scale-with-grid" />'; ?></a>
       <div class="pluswrap">
           <a href="<?php the_permalink(); ?>" class="bigplus"></a>
           <div class="topline"><a href="<?php the_permalink(); ?>"><?php echo $entrytitle ?></a></div>
           <div class="subline"><?php echo $foliocatlist ?></div>
       </div>
    </div>

    <?php endwhile; ?>
    <?php else : ?>
    <div class="eleven columns row alpha">
        <p><?php _e('Oops, we could not find what you were looking for...', 'apex'); ?></p>
    </div>
    <?php endif; ?>

    <?php 
    $wp_query = null; 
    $wp_query = $temp;
    wp_reset_query();
    ?>

    <div class="clear"></div>
</div><div class="clear"></div>

as you can see it's based on the post category. so of course when i try to filter by one of the listed post types all results are hidden. so the solution is to associate the post id with its post type. i know it comes after the $custom = get_post_custom($post->ID); and i'll replace all that code for foliocatlist and entrycategory i just haven't found it in the codex. thanks.

1 Answer 1

0

If there's no significant reason that you can't do the queries separately (putting each type into its own div), then show and hide the divs based on the user input, then that might be a significantly simpler solution to code. That way, you'd be doing simple queries, not trying to bunch them all together and remove the pages).

2
  • thanks, Jon. i have to say stay within the code as written. i figured this out. $$foliocatlist = get_post_type( $post->ID ) and $entrycategory = get_post_type( $post->ID ); Commented Aug 4, 2012 at 10:14
  • Glad you got it! Commented Aug 4, 2012 at 23:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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