Quick $5 Wordpress Coding Question

Discussion in 'Programming' started by Blonde Jon, Jun 6, 2009.

  1. #1
    I want to style every other Wordpress post differently one post will have a certain background image and the other post will have a different background image. I'll give the first one that sends me the code that actually works $5.

    See the attached image to get an idea of what I'm trying to do.

    Thanks
     

    Attached Files:

    Blonde Jon, Jun 6, 2009 IP
  2. Bohra

    Bohra Prominent Member

    Messages:
    12,573
    Likes Received:
    537
    Best Answers:
    0
    Trophy Points:
    310
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #2
    Bohra, Jun 6, 2009 IP
    Blonde Jon likes this.
  3. crivion

    crivion Notable Member

    Messages:
    1,669
    Likes Received:
    45
    Best Answers:
    0
    Trophy Points:
    210
    Digital Goods:
    3
    As Seller:
    100% - 3
    As Buyer:
    100% - 0
    #3
    must this alternate only this two bg's?
     
    crivion, Jun 6, 2009 IP
  4. Blonde Jon

    Blonde Jon Active Member Affiliate Manager

    Messages:
    745
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    58
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #4
    I don't want something the end user will have to manage. I want to hard code it into the theme. I searched for several hours trying to figure it out. It seems to have something to do with querying posts. I'll give you rep for giving me a fast answer.

    Yes, for example post 1,3,5,7, and 9 will have the same background
    and post 2,4,6,8, and 10 will have the same background. The background image just alternates.
     
    Blonde Jon, Jun 6, 2009 IP
  5. Bohra

    Bohra Prominent Member

    Messages:
    12,573
    Likes Received:
    537
    Best Answers:
    0
    Trophy Points:
    310
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #5
    Well

    Offcourse you are using div for the template so you can try this


    if ($alt) {
    $alt = "classnameodd";
    } else {
    $alt = "classnameeven";
    }


    and then to the posts <div class="<?php echo $alt; ?>">

    should be in the loop try it
     
    Bohra, Jun 6, 2009 IP
  6. Blonde Jon

    Blonde Jon Active Member Affiliate Manager

    Messages:
    745
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    58
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #6
    Where exactly do I put that code?

    I'm guessing that code goes here?????:

    <?php query_posts('if ($alt) {
    $alt = "classnameodd";
    } else {
    $alt = "classnameeven";
    }
    '); ?>

    I got to go to sleep. It's 2 AM here and I have to get up in about 4 hours, but I'll get back with you tomorrow Bohra with some cash if it works. :)
     
    Blonde Jon, Jun 6, 2009 IP
  7. crivion

    crivion Notable Member

    Messages:
    1,669
    Likes Received:
    45
    Best Answers:
    0
    Trophy Points:
    210
    Digital Goods:
    3
    As Seller:
    100% - 3
    As Buyer:
    100% - 0
    #7
    This should do the trick
    Paste it on index for example
    Keep your money!
    
    	<?php if (have_posts()) : ?>
    			<?php $i = 0; ?>
    			<?php while (have_posts()) : the_post(); ?>
    			<?php $i++; ?>
    			<!-- Post -->
    			<?php if($i%1==0) { ?>
    			<!-- style background 1-->
    			<div class="post" id="post-<?php the_ID(); ?>">
    				<div class="post-title">
    					<div class="post-date">
    						<span><?php the_time('d') ?></span>
    						<?php the_time('M') ?>
    					</div>
    					<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
    					Posted by: <?php the_author() ?> &nbsp;/&nbsp; Category: <?php the_category(', ') ?>
    				</div>
    				<div class="post-entry">
    					<?php the_content('Read more...'); ?>
    				</div>
    				<div class="post-info">
    					<?php comments_popup_link('Comments (0)', 'Comment (1)', 'Comments (%)'); ?> &nbsp;/&nbsp; <a href="<?php the_permalink() ?>#respond">Add Comment</a>
    				</div>
    			</div>
    			<div class="clear"></div>
    			<?php }else{ ?>		
    			<!-- style background 2 here-->
    			<div class="post" id="post-<?php the_ID(); ?>">
    				<div class="post-title">
    					<div class="post-date">
    						<span><?php the_time('d') ?></span>
    						<?php the_time('M') ?>
    					</div>
    					<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
    					Posted by: <?php the_author() ?> &nbsp;/&nbsp; Category: <?php the_category(', ') ?>
    				</div>
    				<div class="post-entry">
    					<?php the_content('Read more...'); ?>
    				</div>
    				<div class="post-info">
    					<?php comments_popup_link('Comments (0)', 'Comment (1)', 'Comments (%)'); ?> &nbsp;/&nbsp; <a href="<?php the_permalink() ?>#respond">Add Comment</a>
    				</div>
    			</div>
    			<div class="clear"></div>
    			<?php } ?>
    			<!-- /Post -->
    
    PHP:
     
    crivion, Jun 6, 2009 IP
    Blonde Jon likes this.
  8. Blonde Jon

    Blonde Jon Active Member Affiliate Manager

    Messages:
    745
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    58
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #8
    None of these seem to be working for me. Here's the wp loop that I have going. I'm just displaying the post, no permalinks etc.:

    <?php if (have_posts()) : ?>
    
    		<?php while (have_posts()) : the_post(); ?>
    
    			
    			<div id="speechbubble">
    				<div id="entry">
    					<?php the_content('Read the rest of this entry &raquo;'); ?>
    				</div>
    			</div>
    				
    
    		<?php endwhile; ?>
    
    		<div class="navigation">
    			<div class="alignleft"><?php next_posts_link('&laquo; Older Entries') ?></div>
    			<div class="alignright"><?php previous_posts_link('Newer Entries &raquo;') ?></div>
    		</div>
    
    	<?php else : ?>
    
    		<h2 class="center">Not Found</h2>
    		<p class="center">Sorry, but you are looking for something that isn't here.</p>
    		<?php get_search_form(); ?>
    
    	<?php endif; ?>
    PHP:
     
    Blonde Jon, Jun 7, 2009 IP
  9. namd3r

    namd3r Active Member

    Messages:
    135
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    60
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #9
    This is my best attempt at this. I have not tested it, so I have no idea if it will work or not. All you would need to do is go into the css file and change the speechbubble part to have the first background image, then copy it into a speechbubble2 part right underneath and tell it to have the second background image.

    I apologise if this doesn't help at all.

    <?php if (have_posts()) : ?>
    <?php $i = "1"; ?>
            <?php while (have_posts()) : the_post(); ?>
    
               <?php if (i == "1") : ?>
                <div id="speechbubble">
                <?php $i ="2"; ?>
                <?php elseif (i=="2"): ?>
                <div id="speechbubble2">
                <?php $i = "1"; ?>
                <?php endif ?>
                
                    <div id="entry">
                        <?php the_content('Read the rest of this entry &raquo;'); ?>
                    </div>
                 </div>
                   
    
            <?php endwhile; ?>
    
            <div class="navigation">
                <div class="alignleft"><?php next_posts_link('&laquo; Older Entries') ?></div>
                <div class="alignright"><?php previous_posts_link('Newer Entries &raquo;') ?></div>
            </div>
    
        <?php else : ?>
    
            <h2 class="center">Not Found</h2>
            <p class="center">Sorry, but you are looking for something that isn't here.</p>
            <?php get_search_form(); ?>
    
        <?php endif; ?>
    Code (markup):
     
    namd3r, Jun 7, 2009 IP
    Blonde Jon likes this.
  10. crivion

    crivion Notable Member

    Messages:
    1,669
    Likes Received:
    45
    Best Answers:
    0
    Trophy Points:
    210
    Digital Goods:
    3
    As Seller:
    100% - 3
    As Buyer:
    100% - 0
  11. ghprod

    ghprod Active Member

    Messages:
    1,010
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    78
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #11
    is it closed?
     
    ghprod, Jun 7, 2009 IP