• Hello all-

    I design my themes starting with the classic template since it’s not inundated with code and CSS I may not use, and then I usually add to it as needed. One problem I am facing however, is that I would like to have 3 posts total on the homepage — each one with different styling/positioning.

    Right now I have modified the index file’s post div so that I could target the first post. That has worked, but it does nothing for the other 2 posts (obviously). I could target their specific post IDs but they’d eventually get pushed off the page with each new post added.

    In some themes you can target individual posts with stuff like:
    body.home #content .p2 {style}

    but this isn’t an option in the classic theme.

    So my question is, how can I add a function that allows me to style individual posts? I’m fine with doing away with the current addition to the base-code which looks like this:

    <?php $firstClass = 'firstpost'; ?>
    
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    
    <div id="post-<?php the_ID(); ?>" class="post <?php echo $firstClass; ?>"><?php $firstClass = ""; ?>

    Thanks so much!

    ~Deirdre

Viewing 8 replies - 1 through 8 (of 8 total)
  • Try:

    <?php $class = 'posn';
    $c = 0;?>
    <?php if (have_posts()) : while (have_posts()) : the_post();
    $c++;
    $class .= $c;
    ?>
    <div id="post-<?php the_ID(); ?>" class="post <?php echo $class; ?>"

    That should give you unique classes on an unlimited number of posts (posn1, posn2 etc)

    Thread Starter DeirdreBunny

    (@deirdrebunny)

    I will give this a try – thanks so much for your prompt response!

    ~Deirdre

    Thread Starter DeirdreBunny

    (@deirdrebunny)

    Hi Esmi –

    Thanks again for your help =)

    I am getting a syntax error when I use the above code, though.

    I tried adding a “>” at the end of this line:

    <div id="post-<?php the_ID(); ?>" class="post <?php echo $class; ?>"

    But still received an error.

    Here is the full index.php file with the code inserted:

    <?php
    /**
     * @package WordPress
     * @subpackage Classic_Theme
     */
    get_header();
    ?>
    
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    
    <?php the_date('','<h2>','</h2>'); ?>
    
    <?php $class = 'posn';
    $c = 0;?>
    <?php if (have_posts()) : while (have_posts()) : the_post();
    $c++;
    $class .= $c;
    ?>
    <div id="post-<?php the_ID(); ?>" class="post <?php echo $class; ?>">
    
    	 <h3 class="storytitle"><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h3>
    	<div class="meta"><?php _e("Filed under:"); ?> <?php the_category(',') ?> — <?php the_tags(__('Tags: '), ', ', ' — '); ?> <?php the_author() ?> @ <?php the_time() ?> <?php edit_post_link(__('Edit This')); ?></div>
    
    	<div class="storycontent">
    		<?php the_content(__('(more...)')); ?>
    	</div>
    
    	<div class="feedback">
    		<?php wp_link_pages(); ?>
    		<?php comments_popup_link(__('Comments (0)'), __('Comments (1)'), __('Comments (%)')); ?>
    	</div>
    
    </div>
    
    <?php comments_template(); // Get wp-comments.php template ?>
    
    <?php endwhile; else: ?>
    <p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
    <?php endif; ?>
    
    <?php posts_nav_link(' — ', __('&laquo; Newer Posts'), __('Older Posts &raquo;')); ?>
    
    <?php get_footer(); ?>

    What error are you getting?

    Thread Starter DeirdreBunny

    (@deirdrebunny)

    This is the error:

    Parse error: syntax error, unexpected $end in /hermes/bosweb/web032/b325/sl.alluramo/public_html/hideoutmagazine/HideOutMag2010/wp-content/themes/HideoutRetro/index.php on line 43

    You’ve got a repeated line from when you added the new code in. Change:

    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    
    <?php the_date('','<h2>','</h2>'); ?>
    
    <?php $class = 'posn';
    $c = 0;?>
    <?php if (have_posts()) : while (have_posts()) : the_post();
    $c++;
    $class .= $c;
    ?>
    <div id="post-<?php the_ID(); ?>" class="post <?php echo $class; ?>">

    to:

    <?php $class = 'posn';
    $c = 0;?>
    <?php if (have_posts()) : while (have_posts()) : the_post();
    $c++;
    $class .= $c;
    ?>
    <?php the_date('','<h2>','</h2>'); ?>
    
    <div id="post-<?php the_ID(); ?>" class="post <?php echo $class; ?>">
    Thread Starter DeirdreBunny

    (@deirdrebunny)

    Oh! I see. I made the correction. Thank you — it is working just as you said.

    If you are ever in Portland, OR, I’ll make you dinner.

    =)

    Thanks!

    Deirdre

    Thanks ??

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Alternate Post styles (not pages)’ is closed to new replies.