WordPress.org

Ready to get started?Download WordPress

Forums

Adding multiple sections to one page, with different categories - Help! (4 posts)

  1. dannn91
    Member
    Posted 1 year ago #

    Hi there! This is my first post here!

    I'm having a problem with my current website im working on (http://www.besidebigbrother.com/) bacically, I want to add 2 more "sections" to this website on the main page, and then have seperate pages with just these posts on them.

    I'm not very great at PHP coding, but I know my way around it if I need too.

    My current page looks like this, and I was wondering if this is possible.. So I could add a "Recaps" section and a "Housemates" section..Lets say...

    <?php get_header(); ?>
    
    <!-- ---------------------- START CONTENT ------------------------- -->
    <div id="content">
      <h4>News</h4>
        <?php query_posts('category_name=news&showposts=2'); ?>
          <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    
            <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
    
    		  <h2><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h2>
    				<?php the_post_thumbnail('thumb'); ?>
    				<span class="date"><?php the_time('F jS') ?></span><?php the_excerpt(); ?>
      </div>
    
    	<?php endwhile; ?>
    
    	<?php else : ?>
    
    		<p>I think your lost...</p>
    
    	<?php endif; ?>
    
    </div>
    
    <?php get_sidebar(); ?>
    <?php get_footer(); ?>

    I'd love it if someone could help out! :)

  2. alchymyth
    The Sweeper & Moderator
    Posted 1 year ago #

    just copy and multiply this section:

    <h4>News</h4>
        <?php query_posts('category_name=news&showposts=2'); ?>
          <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    
            <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
    
    		  <h2><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h2>
    				<?php the_post_thumbnail('thumb'); ?>
    				<span class="date"><?php the_time('F jS') ?></span><?php the_excerpt(); ?>
      </div>
    
    	<?php endwhile; ?>
    
    	<?php else : ?>
    
    		<p>I think your lost...</p>
    
    	<?php endif; ?>

    just change the title and the word 'news' in this line <?php query_posts('category_name=news&showposts=2'); ?> to the different categories.
    http://codex.wordpress.org/Class_Reference/WP_Query#Category_Parameters

    and add wp_reset_query(); after the endif; in each section.

  3. dannn91
    Member
    Posted 1 year ago #

    Trying it now, thankyou so much! :) I'll let you know how it goes.

  4. dannn91
    Member
    Posted 1 year ago #

    Worked great :) Thankyou so much!

Topic Closed

This topic has been closed to new replies.

About this Topic