• Resolved rcriche

    (@rcriche)


    The Facts :
    I’m using a theme itself , developed in bootstrap .
    I have a Custom Post Type called Business that has only , title and text ( for now ) .

    The presentation of this page has the CPT ‘s sequinte code:

    < ? php
    $ newsArgs = array (
    ' post_type ' = > array ( 'business' )
    ' showposts ' => -1,
    'order ' = > ' ASC ' ) ;
    query_posts ( $ newsArgs ) ;
    if ( have_posts ( ))
    while ( have_posts ( )) the_post (); ? >
    <div class="col-lg-4 pad25">
    <div class="efx"> < / div >
    ???????????????<h3> < ? php the_title ( ) ; ? > < / h3 >
    ???????????????< ? php echo the_content ( ) ; ? >
    < / div >
    < ? php endwhile ;
    else: ? >
    <h4> soon ... < / h4 >
    < ? php endif ; ? >

    The Need :
    Must then, on this page , so the color of the title as a class to alternate efx . Ex: Post 1 (blue ); Post 2 (green ); Post 3 (blue ), and so on.

    Some time ago I read an article about post count and include the number of the post in the class … but do not think this article more . Also I did not find anything related to it .

    Some help ? ?

    *sorry by my english

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter rcriche

    (@rcriche)

    well.. i did’t

    <?php
    					$oddpost = 'alt_post';
    
    					if(have_posts()): while(have_posts()): the_post(); ?>
    					<h2><?php the_title(); ?></h2>
    					<?php the_content();
    					endwhile; endif;
    				?>	
    
    				<?php
    					$newsArgs = array(
    					'post_type' => array('negócio'),
    				    'showposts' => -1,
    				    'order' => 'ASC');
    					query_posts( $newsArgs );
    					if ( have_posts() ) :
    						while (have_posts()) : the_post(); ?>
    						<div class="col-lg-4 pad25">
                   				<h3 class="<?php echo $oddpost; ?>"><?php the_title(); ?></h3>
                   				<?php echo the_content(); ?>
    						</div>
    					<?php
    						if ('alt_post' == $oddpost) $oddpost = '';
    						else $oddpost = 'alt_post';
    
    						endwhile;
    					else: ?>
    					<h4>Em breve...</h4>
    					<?php endif; ?>

    and CSS

    .chamadas h3 {color: #8fbe7a; border-top: 4px solid #8FBE7A; padding-top:10px}
    .alt_post  {color: #02568a!important; border-top: 4px solid #02568a!important}

    Something like this should work. It will add the efx class for even-numbered posts in the loop. Notice that I defined $count as 0 before the loop, then incremented it after the_post(); with $count++

    <?php
    $newsArgs = array (
    	'post_type' => array ( 'business' ),
    	'showposts' => -1,
    	'order' => 'ASC'
    );
    query_posts ( $newsArgs);
    $count = 0;
    if ( have_posts ( ))
    	while ( have_posts ( )) the_post(); $count++; ?>
    <div class="col-lg-4 pad25">
    	<?php $class = 0 == ( $count % 2 ) ? 'efx' : ''; ?>
    	<div class="<?php echo $class; ?>"></div>
    	<h3> <?php the_title(); ?></h3>
    	<?php echo the_content(); ?>
    </div>
    <?php endwhile;
    else: ?>
    	<h4> soon ... </h4>
    <?php endif; ?>

    This bit:

    0 == ( $count % 2 )

    Checks if the value of $count is divisible by two (even-numbered).

    Hope that helps.

    please share website link

    Thread Starter rcriche

    (@rcriche)

    the site still in localhost Shadez..

    Drew, two minutes before your reply I found a solution and post here!

    Your tips will be very useful for me in another problem.. LOL.. Thank you!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Switch colors the title of each post’ is closed to new replies.