WordPress.org

Ready to get started?Download WordPress

Forums

Desperate help with the loop in my custom theme (3 posts)

  1. DrGizmondo
    Member
    Posted 6 years ago #

    KO im trying to put together my very first theme, but I'm having some trouble with the loop. What I would live is for each post to be wrapped in its own DIV so that i can style them according to the category there in. Ive tries to add <div class="post"id="post-">to my post DIV, but all post still end up in once single DIV called "post".

    My code is as follows:

    <?php get_header(); ?>
    
    <div id="networkcontain">
      <div id="networkbar">
    
      </div>
      <div id="tphead">
        <a href="/"><h1>Cerebral Black Hole</h1></a>
      </div>
    
    <div id="containertp">
    
     <div id="contentleft" 
    
    <div class="tf_body">
     <div class="entryContent">
    
    <div class="post"id="post-<?php the_ID(); ?>">
    
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    
    <h2 class="title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></h2>
    
    <div class="date">
    <?php the_time('F j, Y'); ?> &middot; <a href="javascript:window.print()">Print This Article</a>
    
    </div>
    
    <?php the_content(__('Read more'));?><div style="clear:both;"></div>
    
    <div class="postmeta">Written by <?php the_author(); ?> &middot; Filed Under <?php the_category(', ') ?>&nbsp;<?php edit_post_link('(Edit)', '', ''); ?>Tagged: <?php the_tags('') ?>
    
    <?php if (function_exists('sharethis_button')) { sharethis_button(); } ?>
    
    </div>
    
    <?php trackback_rdf(); ?>
    
    <?php endwhile; else: ?>
    
    <?php _e('Sorry, no posts matched your criteria.'); ?>
    <?php endif; ?>
    </div>
    
    </div>
    </div>
    
    <?php get_footer(); ?>
    <?php get_sidebar(); ?>

    Please help as im a bit lost now and dont realy know what is wrong. For an image of what my curent loop is outputting see this link http://www.flickr.com/photos/21455233@N08/2446645235/ as you can see there is no seperation between the posts. This is a mock-up of what I would like the posts to be like when Im done http://www.flickr.com/photos/21455233@N08/2447470364/ see how there formatted acording to the category there in - this is why I want each post to be in its own DIV.

    Again please help as I canot continue untill this is sorted out. Many thanks in advance.

  2. moshu
    Member
    Posted 6 years ago #

    You put that div with the id# OUTSIDE of the Loop, so there is no way that WP can retrieve it. Check out the default's index - you have the solution there.

  3. DrGizmondo
    Member
    Posted 6 years ago #

    thanks mushu I've fixed that now thanks and I now have my posts appearing inside there own div, now i would like to style those divs according to the category there in, ideally with the category slug - whats the best way to do this?

Topic Closed

This topic has been closed to new replies.

About this Topic