• hi, i’m desperate for some help. i’m trying to get my homepage to only display posts & images tagged one specific category. this is the index.php file, part i added in to restrict to one category (40) is bolded. but it doesn’t seem to be working (all new posts are appearing on the homepage). what am i missing? any help would be SO appreciated – thanks!

    <?php get_header(); ?>
    <!– Content Wrap –>
    <div id=”galleryWrap”>
    <!– Gallery –>
    <div id=”gallery”>
    <?php $posts = get_posts(“category=40&numberposts=6”); ?>
    <?php if(have_posts()) : ?><?php while (have_posts()) : the_post(); ?>
    <!– Thumbs –>
    <div id=”site-<?php the_ID(); ?>” class=”thumbs”>
    ID, “Url”, true); ?>” title=”<?php the_title();?>”><img src=”<?php echo get_post_meta($post->ID, “small”, true); ?>” alt=”<?php the_title();?>” class=”thumbnail” />
    </div><!– [END] thumbs –>
    <?php endwhile;?>
    <?php if(function_exists(‘wp_pagenavi’)) { wp_pagenavi(); } ?>
    <?php endif; ?>
    </div><!– [END] gallery –>
    <?php get_sidebar();?>
    </div><!– [END] galleryWrap –>
    <?php get_footer(); ?>

Viewing 3 replies - 1 through 3 (of 3 total)
  • If this is your index.php then change that line to this:

    <?php query_posts($query_string . ‘&cat=40’); ?>

    Thread Starter vschimel2

    (@vschimel2)

    thanks SO much! one more quick question. i want to do a similar thing on a blog page – is this the coding i’d use?

    <php
    /*
    Template Name: Page 2
    */
    ?>

    <?php get_header(); ?>

    <!– Content Wrap –>
    <div id=”galleryWrap”>
    <!– Gallery –>
    <div id=”gallery”>

    <?php if (is_page ()){ ?>

    <? } ?>

    <div class=”content”>

    <?php $posts = get_posts(“category=33&numberposts=10”); ?>

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

    <div class=”entry”>
    <?php the_content(”); ?>
    </div>

    <?php endwhile;?>
    <?php endif; ?>

    </div>
    </div><!– [END] gallery content –>
    <?php get_sidebar();?>

    </div><!– [END] galleryWrap

    Probably better to use the foreach/setup_postdata construct rather than the if(have_posts()) : ?><?php while (have_posts()) : the_post(); ..... endwhile thing.

    See this example:
    https://www.daobydesign.com/blog/2007/07/modifying-wordpress-front-page/

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘loop help please!’ is closed to new replies.