• Resolved sschmitt

    (@sschmitt)


    Hello!

    I am trying to build an archive page for a custom post type. It is 4-column and using thumbnail image and post title. I have managed to make it look correct but it is not pulling in my posts correctly. I copied the code from a 2 column grid and added two more columns. The code had a counter in there. I think that is what needs to be adjusted and I can’t figure out how. I am supplying link and archive template code. It repeats the left hand column post 3 times. There should only be 5 posts in this category.

    Any help would be very much appreciated.

    Thanks!
    Sandra ??

    Link:
    https://sandraschmitt.com/cavdesign/blog/project-type/project-before-after/

    Archive.php code:

    <?php
    $counter = 1; //start counter
    
    $grids = 2; //Grids per row
    
    global $query_string; //Need this to make pagination work
    
    /*Setting up our custom query (In here we are setting it to show 12 posts per page and eliminate all sticky posts) */
    query_posts($query_string . '&caller_get_posts=1&posts_per_page=12');
    
    if(have_posts()) :	while(have_posts()) :  the_post();
    ?>
    
    <?php
    //Show the left hand side column
    if($counter == 1) :
    ?>
    			<div class="griditemleft">
    				<div class="postimage">
    					<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_post_thumbnail('category-thumbnail'); ?></a>
    					</div>
                    		<h2><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
    			</div>
    
                            <div class="griditemleft">
    				<div class="postimage">
    					<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_post_thumbnail('category-thumbnail'); ?></a>
    					</div>
                    		<h2><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
    			</div>
    
                             <div class="griditemleft">
    				<div class="postimage">
    					<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_post_thumbnail('category-thumbnail'); ?></a>
    					</div>
                    		<h2><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
    			</div>
    
    <?php
    //Show the right hand side column
    elseif($counter == $grids) :
    ?>
    			<div class="griditemright">
    				<div class="postimage">
    					<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_post_thumbnail('category-thumbnail'); ?></a>
    					</div>
                    		<h2><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
    			</div>
    
    		<div class="clear"></div>
    
    <?php
    $counter = 0;
    endif;
    ?>
    
    <?php
    $counter++;
    endwhile;
    //Pagination can go here if you want it.
    endif;
    ?>
Viewing 6 replies - 1 through 6 (of 6 total)
  • hello,

    I’m having the same problem as you, still trying to nut it out. This might work though.

    After your code at the bottom $counter++;

    place this code

    endwhile;?>
        <div class="clr"></div>
    
        <div class="artist-navigation">
    							<div class="alignleft"><?php next_posts_link('&laquo; Older Entries'); ?></div>
    							<div class="alignright"><?php previous_posts_link('Newer Entries &raquo;'); ?></div>
    						</div>
    
    <? endif; ?>

    Goodluck!

    Actually should be this sorry.

    endwhile;?>
    		<div class="clear"></div>
    
        <div class="artist-navigation">
    							<div class="alignleft"><?php next_posts_link('&laquo; Older Entries'); ?></div>
    							<div class="alignright"><?php previous_posts_link('Newer Entries &raquo;'); ?></div>
    						</div>
    
    <? endif; ?>
    Thread Starter sschmitt

    (@sschmitt)

    I actually got it to work. My code above was complicated because of the grid I was trying to use. I simplified my grid and got it to work. The code below will give you an archive page of a custom post type with featured image grid of it’s child post types underneath.

    CODE:

    <?php get_header(); ?>
    
    <div id="main-content">
    
    <h2><?php single_cat_title(); ?></h2>
    
    <div id="gridcontainer">
    
    <?php
    global $query_string; //Need this to make pagination work
    
    /*Setting up our custom query (In here we are setting it to show 12 posts per page and eliminate all sticky posts) */
    query_posts($query_string . '&caller_get_posts=1&posts_per_page=12');
    
    if(have_posts()) :	while(have_posts()) :  the_post();
    ?>
    
    			<div class="griditemleft">
    				<div class="postimage">
    					<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_post_thumbnail('category-thumbnail'); ?></a>
    					</div>
                    		<h2><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
    			</div><!--griditemleft-->
    
    <?php
    endwhile;
    //Pagination can go here if you want it.
    endif;
    ?>
    
    </div><!--gridcontainer-->
    
    </div><!--main-content-->
    
    <?php get_footer(); ?>
    Thread Starter sschmitt

    (@sschmitt)

    I hope this helps ??

    oh yes I see. Taking out the code that repeated 3 times in your original example.

    I ended up with this

    <div id="artist_maincontent">
    <div id="gridContainer">
    
    <?php
    $c = 1; //init counter
    $bpr =3; //boxes per row
    global $query_string; //Need this to make pagination work
    // we add this, to show all posts in our
    // Glossary sorted alphabetically
    $posts = query_posts($query_string .
    '&orderby=title&order=asc&posts_per_page=15');
    // here comes The Loop!
    if(have_posts()) :  while(have_posts()) :  the_post();
    ?>
                				<div class="post" id="post-<?php the_ID(); ?>">
    
                    <div class="postImage">
        <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_post_thumbnail('grid-post-image'); ?></a>
        <h5 class="title"><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h5>
    				</div>
    
                                </div>
    <?php
    if($c == $bpr) :
    ?>
    <div class="clr"></div>
    <?php
    $c = 0;
    endif;
    ?>
    <?php
            $c++;
        endwhile;?>
        <div class="clr"></div>
    
        <div class="artist-navigation">
    							<div class="alignleft"><?php next_posts_link('<span class="arrow_left">Previous Artists</span>'); ?></div>
    							<div class="alignright"><?php previous_posts_link('<span class="arrow_right">More Artists</span>'); ?></div>
    						</div>
    
    <? endif; ?>
    
    <div class="clr"></div>
    </div><!--End Grid -->
    </div><!--End artist_maincontent -->

    A test example can be found here. I still need to check pagination works but getting there.

    Thank you for your response and help! =)

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Custom category archive page’ is closed to new replies.