Custom Field for post Backgrounds
-
Hey there, i am trying to use the custom fields within wordpress to make different background colors for each post kind of like this website here
as of right now on my localhost, as a test i have the custom field name as abc123 and then the value as yellow
and here is the code
<section> <div class="container"> <div class="row"> <div class="col-lg-12 text-center"> <h2 class="section-heading">Check out our blog</h2> <hr class="light"> </div> <div class="col-lg-8 col-lg-offset-2 text-center" > <?php // Get the last 3 posts. global $post; $args = array( 'posts_per_page' => 3 ); $myposts = get_posts( $args ); $bgcolor1 = get_post_meta($post->ID, "abc123", true); foreach( $myposts as $post ) : setup_postdata($post); ?> <div style="background-color:<?php echo $bgcolor1; ?>"> <h2 class="section-heading"><a class="link" href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2> <p><?php the_excerpt();?></p> <a class="link" href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>">Read More!</a> <hr class="blight"> </div> <?php endforeach; ?> </div> </div> </div> </section>
its doing all the posts as the latest color added from latest post, wondering how to fix that
also its showing the colors on my localhost webserver but not online
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Custom Field for post Backgrounds’ is closed to new replies.