• Lee

    (@dartisan)


    Hi all,

    I am currently building a wordpress site for a university project that offers maximum control of content through the admin pannel. There will be a lot of content so i am trying to find a way of organising them efficiently so it wont be hard to find the relevant posts in regards to what need to be edited etc.

    What i want to do ideally is create a page and category with the same name e.g home, about, contact ect and assign posts to each category accordingly. I then want to then call all of the posts from category relating to the page we are on. I have got this far and this is my code:

    <?php
    /*
    Template Name: ListPostsInCategoryThatHasSameNameAsPage
    */ ?>
    
    <?php get_header(); ?>
    <div class="maincontainer">
    		<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    
    	<div class="innercontainer">
    		<div class="contentnavcontainer">
    			<div class="contentnav">
    				<h1><?php the_title(); ?></h1>
    			</div><!-- end .contentnav -->
    		</div><!-- end .contentnavcontainer -->
    	<?php endwhile; else: endif; ?>
    
    		<?php query_posts('category_name='.get_the_title().'&post_status=publish,future&order=ASC');?>
    		<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    
    		<div class="largeslidercontainer">
    			<div class="slider">
    				<?php the_title(); ?>
    				<?php the_content(); ?>
    		<?php endwhile; else: endif; ?>
    
    			</div>
    		</div><!-- end.largeslidercontainer -->
    
    		<div class="boxnavcontainer">
    			<div class="boxnav">
    			</div><!-- end .box nav -->
    
    		</div><!-- end box nav container -->
    	</div><!-- end of inner container -->
    <div class="clearfix"></div>
    
    </div>
    </div>
    
    <?php get_footer(); ?>

    [Please post code & markup between backticks or use the code button. Your posted code may now have been permanently damaged by the forum’s parser.]

    Currently, the second loop is pulling all the content from the category named home and showing them on the page named home.

    The problem im having is, if there is more than one post in the category, it lists all of them with just one set of <?php the_title();?> and <?php the_content(); ?> hooks. What I want to do is be able to put the second/third set of posts in a different div than the first, for example “boxnav”. I dont want the second/third posts coming straight under the first, i want to be able to control each post separately from that category.

    Can any body help with this please 🙂

    Thanks

    Lee

    [Please don’t bump here – two deleted – it’s been one hour – and these forum are entirely staffed by volunteers. If you need faster help, you could consider hiring someone – http://jobs.wordpress.net/ ]

Viewing 1 replies (of 1 total)
  • vtxyzzy

    (@vtxyzzy)

    I think you can do what you want by using a counter. The code should look something like this:

    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    	<?php if (++$post_counter == 1) : ?>
    
    		<div class="largeslidercontainer">
    			<div class="slider">
    			   <?php the_title(); ?>
    			   <?php the_content(); ?>
    
    			</div>
    		</div><!-- end.largeslidercontainer -->
    
    	<?php else : ?>
    
    		<div class="boxnavcontainer">
    		   <div class="boxnav">
    		   </div><!-- end .box nav -->
    		</div><!-- end box nav container -->
    
    	<?php endif; ?>
    <?php endwhile; endif; ?>
Viewing 1 replies (of 1 total)
  • The topic ‘Query all posts from category, how to control the posts further?’ is closed to new replies.