Forums

Page template with a grid showing post thumbs in a certain category (4 posts)

  1. glitterdroid
    Member
    Posted 1 year ago #

    Hi,
    Im´m trying to create a new page template for my WP blog. I want it to show all my posts in a certain category, as thumbs in a grid.

    I would like to have a grid with 8 rows and 4 columns showing the featured images of these posts. And the images should link to the posts. All my featured images are 125x125px so this would be a kind of visual gallery of my posts in that category.

    I started with at copy of another page template with full width, as in the code further down. I understand that I need to put the code somewhere close to the loop, but I´m new to PHP and I don´t know how such code should look like. I´ve been reading the WP documentation here for a few nights now and it´s fantastic, but I don´t really get it - yet.

    Styling this in the style.css will be no problem, I know html and css but I really need help with the code that selects the posts in a certain category and then presents them in a grid, showing their featured images.

    Can I do all this in a page template or do I need some kind of function code in the functions.php and then call it from the page template?

    I know there are widgets showing the latest posts with both the excerpt and the post thumb (like this one in the sidebar at http://fthemes.com/demo/Dominate/) so I guess this should be something similar, but I don´t understand how to put it on a page.

    I could get the same result using a NextGen gallery on the page, or perhaps find a widget that can be placed on a page, but I would really lika to use PHP code to do this on a page template.

    <?php
    /**
    * Template Name: Postgrid
    */
    ?>
    
    <?php get_header(); ?>
    
        <div id="main-fullwidth" class="span-24">
    
        <div class="content">
    
            <?php get_template_part('loop', 'page'); ?>
    
        </div><!-- .content -->
    
        </div><!-- #main-fullwidth-->
    
    <?php get_footer(); ?>
  2. alchymyth
    The Sweeper
    Posted 1 year ago #

    the way your template is set up, it would make sense to create a loop-grid.php and do the looping with the linked thumbnails in there.

    the code that selects the posts in a certain category

    in your template, you would simply provide a custom query; something like:

    <?php
    $args = array(
    'posts_per_page' => 32,
    'paged' => get_query_var('page'),
    'category__in' => array(27), //the id of your certain category
    'meta_query' => array(array('key' => '_thumbnail_id')) //to get only posts with thumbnails
    );
    query_posts( $args ); ?>
    <?php get_template_part('loop', 'grid'); ?>
    <? wp_reset_query(); ?>

    the above would replace this line:
    <?php get_template_part('loop', 'page'); ?>

    http://codex.wordpress.org/Function_Reference/query_posts
    http://codex.wordpress.org/Function_Reference/WP_Query#Category_Parameters
    http://codex.wordpress.org/Function_Reference/WP_Query#Custom_Field_Parameters

    presents them in a grid, showing their featured images

    in loop-grid.php, you would simply set the loop, with the neccessary html tags and css classes needed to style the grid;
    and with the output of the linked thumbnail;

    http://codex.wordpress.org/The_Loop
    http://codex.wordpress.org/Function_Reference/the_post_thumbnail
    http://codex.wordpress.org/Function_Reference/the_permalink

    see how you are getting on with all these new links to the codex;
    and report back with a link to your site, when you need a bit more input.

  3. coolbuddy
    Member
    Posted 5 months ago #

    i also need help to show posts in grid view on my custom page.
    i'm using the following codes for custom page to show posts in grid view.

    [code moderated - please use the pastebin for any code over 10 lines long]

  4. coolbuddy
    Member
    Posted 5 months ago #

    the page link is this punjabgold.com

Topic Closed

This topic has been closed to new replies.

About this Topic