Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Here's my code to generate a two columm blog index page. I want to modify it so that I can use it as an index page for my portfolio custom post type- query_posts('post_type=portfolio').

I know that I need to modify the first quater of the code, but I just don't know what to change. Can you please help me?

Code:

 <?php
/*
Template Name: 2 Column Blog Template
*/
get_header();
?>
<section class="container">
<!-- 960 Container -->
    <?php
    $counter = 1; //start counter
    $grids = 2; //Grids per row
    global $query_string; //Need this to make pagination work
    $paged = get_query_var('paged');
             $offset = 0;
                if ($paged != 0 ) {
                    $offset = ($paged-1) * get_query_var('posts_per_page') ;
                }
                query_posts('offset=' . $offset);
                if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php
global $more;
$more = 0;
?>
<?php
//Show the first post
if($counter == 1) :
?>
    <article class="eight columns" id="entry-<?php the_ID(); ?>"> <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
        <?php the_post_thumbnail(); ?>
        </a>
        <h2><a href="<?php the_permalink() ?>">
            <?php the_title(); ?>
            </a></h2>
        <p class="blog_meta">
            By <em><?php the_author() ?></em> on:<?php the_time('F jS, Y') ?>
        </p>
        <p class="blog_preview">
            <?php the_excerpt(); ?>
        </p>
    </article>
<?php
//Show the last post
elseif($counter == $grids) :
?>
    <article class="eight columns" id="entry-<?php the_ID(); ?>"> <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
        <?php the_post_thumbnail(); ?>
        </a>
        <h2><a href="<?php the_permalink() ?>">
            <?php the_title(); ?>
            </a></h2>
        <p class="blog_meta">
            By <em><?php the_author() ?></em> on:<?php the_time('F jS, Y') ?>
        </p>
        <p class="blog_preview">
            <?php the_excerpt(); ?>
        </p>
    </article>
    <hr class="clear"><?php $counter = 0; endif;?><?php $counter++; endwhile; //sets a clear:both and resets counter for next row of posts ?>
    <nav id="pagination">
        <hr class="pagination_margin">
        <div id="pagination_previous">
            <?php previous_posts_link('Previous'); ?>
        </div>
        <div id="pagination_next">
            <?php next_posts_link('Next'); ?>
        </div>
    </nav>
    <?php endif; ?>
</div>
</section>
<?php
get_footer();
?>
share|improve this question
    
Use query_posts('post_type=portfolio&offset=' . $offset); –  keatch Jul 31 '12 at 16:55
    
@keatch that did it! Thank you! –  James Banks Jul 31 '12 at 16:58
    
@keatch, add that as an answer so it can be accepted. –  mrwweb Jul 31 '12 at 17:47
    
I did it. Check below! –  keatch Jul 31 '12 at 19:01

1 Answer 1

up vote 0 down vote accepted

Modify your code to use the correct query_posts call. Use

query_posts('post_type=portfolio&offset=' . $offset);

instead of

query_posts('offset=' . $offset);

Below is your code modified:

<?php
/*
Template Name: 2 Column Blog Template
*/
get_header();
?>
<section class="container">
<!-- 960 Container -->
    <?php
    $counter = 1; //start counter
    $grids = 2; //Grids per row
    global $query_string; //Need this to make pagination work
    $paged = get_query_var('paged');
             $offset = 0;
                if ($paged != 0 ) {
                    $offset = ($paged-1) * get_query_var('posts_per_page') ;
                }
                query_posts('offset=' . $offset);
                if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php
global $more;
$more = 0;
...

The complete codex manual for query_posts is here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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