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.

You may find my index.php code below. I'm trying to get posts from categories.

<?php get_header(); 
$style = gplab_get_option('home_display');
if (isset($_GET['style'])) {
    $style = $_GET['style'];
}?>
<div id="main-content" class="container">
<?php
if ( gplab_get_option('breaking_enable') ) {
    echo gplab_breaking();
} ?>

<div class="content">
<?php if ( gplab_get_option('slider_enable') ) { ?> 
    <div class="slider-container">
        <?php echo gplab_flexslider(); ?>
    </div>
<?php } 
if($style == 'custom'){ 
echo gplab_box_cat();
} elseif($style == 'blog') {
    $getPosts = new WP_Query();
    $getPosts->query("paged=$paged"); ?>
    <div class="post-list blog"> 
    <?php if ($getPosts->have_posts()) : while ($getPosts->have_posts()) : $getPosts->the_post(); 
        $metaID = $post->ID; $meta = get_post_meta($post->ID,'gplab_post_meta',TRUE); ?>
            <div id="post-<?php the_ID(); ?>" <?php post_class('page'); ?>>
                    <div class="post-header">
                        <h2><a href="<?php the_permalink() ?>" title="<?php the_title(); ?>" rel="bookmark"><?php the_title(); ?></a></h2>
                    </div>
                <article class="post-item">
                    <p class="post-meta"><?php _e('Written on ', 'gplab'); the_time('F j, Y'); _e(', by ', 'gplab'); the_author_posts_link(); ?></p>
                    <div class="post-thumbnail">
                        <?php echo gplab_thumbnail('post'); ?>      
                    </div>
                    <div class="post-content">
                        <?php the_excerpt(__('Read more', 'gplab'));?>
                    </div>
                    <div class="post-footer">
                        <p><?php comments_popup_link(__('No Comments', 'gplab'), '1 ' . __('Comment', 'gplab'), '% ' . __('Comments', 'gplab')); ?></p>
                        <p><?php _e('Categories: ', 'gplab'); the_category(', ') ?></p>
                    </div>
                    <div class="clear"></div>
                </article>
            </div>
    <?php endwhile; endif; ?>
    </div><?php 
    if (function_exists("pagination")) {
        pagination($getPosts->max_num_pages);
    } ?>
<?php } elseif($style == '' || $style == 'box'){?>

    <ul> <?php
    global $paged;
    if(empty($paged)) $paged = 1;

    $news_counter_1 = 0;
    $two_counter_1 = 0;
    $two_counter_2 = 0;
    $gPosts = new WP_Query();
    $gPosts->query("paged=$paged");
    if ($gPosts->have_posts()) : while ($gPosts->have_posts()) : $gPosts->the_post(); $two_counter_1 ++ ;
        $metaID = $post->ID;

    if($two_counter_1 % 2 != 0) : ?>
        <section class="normal-column"> <?php 
    elseif ($two_counter_1 % 2 == 0): ?>    
        <section class="normal-column last"> <?php 
    endif; ?>       
            <div class="normal-box">
                <div class="normal-thumbnail">
                    <?php echo gplab_thumbnail('box'); ?>       
                    <?php if(gplab_get_meta($metaID ,'post_format') == 'review'){ ?>
                    <div class="star"><img src="<?php echo GPLABIMG . '/stars/star' . gplab_get_meta($metaID ,'overall_rating') . '.png'?>" alt="<?php echo gplab_get_meta($metaID ,'overall_rating'); ?>"/></div>
                    <?php } elseif(gplab_get_meta($metaID ,'post_format') == '' || gplab_get_meta($metaID ,'post_format') == 'default') { ?>
                    <?php } else { ?>
                    <div class="icon"><img src="<?php echo GPLABIMG . '/' . gplab_get_meta($metaID ,'post_format') . '.png'?>" alt="<?php echo gplab_get_meta($metaID ,'post_format'); ?>"/></div>
                    <?php } ?>
                    <div class="comment"><?php echo gplab_getcomment_count(get_the_ID(), 'index');?></div>
                </div>
                <div class="normal-header">
                    <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
                    <div class="glow-border"></div>
                </div>
                <div class="normal-container">
                    <div class="normal-content">
                        <div class="normal-news">
                            <div class="normal-excerpt">
                                <?php //the_excerpt();
                                gplab_excerpt_box(); //275 260?>
                            </div>
                        </div>
                    <div class="clearfix"></div>
                    </div>
                    <div class="normal-footer">
                        <div class="date"><?php the_time('F j, Y'); _e(' at ', 'gplab'); the_time(); ?></div>
                        <div class="cat"><?php _e('Category:', 'gplab'); ?> <?php echo gplab_getCategory(get_the_ID());?></div>
                        <div class="normal-readmore">
                            <a href="<?php the_permalink(); ?>" title="<?php the_title();?>"><?php _e('Read More', 'gplab'); ?></a>
                        </div>
                    <div class="clearfix"></div>
                    </div>
                </div>
            </div>
        </section>  
        <?php endwhile; else:?>         
        <div class="no-results">
            <p><strong><?php _e('There has been an error.', 'gplab'); ?></strong></p>
            <p><?php _e('We apologize for any inconvenience, please hit back on your browser or use the search form below.', 'gplab'); ?></p>
            <?php get_search_form(); ?>
        </div>
        <?php endif; ?>
    <div class="clear"></div> <?php
    wp_reset_query(); ?>
    </ul> <?php
    if (function_exists("pagination")) {
        pagination($gPosts->max_num_pages);
    } 
} ?>
</div><!-- .content -->

What should I change to get posts from categories?

share|improve this question
2  
"Here is a lump of code how do I make it do X?" is not a very good question. Please narrow this down to the relevant section and explain what you've tried. –  s_ha_dum Mar 22 at 23:34

Your Answer

 
discard

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

Browse other questions tagged or ask your own question.