I’m fairly new to WordPress and am trying to build a custom page for blogs. Following the some examples online I have created a custom page template, and also setup a custom post type.
Now I created a page and set it to use new template. I need to add some styles to the featured post and below it have different styling for the rest (total 5 posts).
I can get the posts to show up on the page but how do I separate the featured one so I can style it differently? The post includes a media and some text.
Below is a snippet of the code I’m working with it.
<div class="post-box">
<?php // CUSTOM CODE STARTS:
$mypost=array( 'post_type'=> 'story', );
$loop = new WP_Query( $mypost ); ?>
<?php while ( $loop->have_posts() ) : $loop->the_post();?>
<div <?php post_class( 'post'); ?> id="post-
<?php the_ID(); ?>">
<div class="header-top uppercase clearfix"></div>
<div class="post-home">
<h2 class="title"><a href="<?php the_field('name_generator_link'); ?>" target="_blank" title="<?php the_title(); ?>"><?php the_title(); ?></a></h2>
<div class="post-content">
<?php the_content(); ?>
<a class="featured-logo" href="<?php the_field('name_generator_link'); ?>" target="_blank" title="<?php the_title(); ?>">
<?php the_post_thumbnail( 'full'); ?>
</a>
</div>
</div>
</div>
<!--blog post-->
<?php endwhile; ?>
<?php wp_reset_query(); // NAME GENERATOR TOOLS CUSTOM CODE ENDS ?>
</div>
Hope I explained my issue well. I really appreciate any help I can get!
This worked pretty well for me:
We can create/style the elements as needed for featured in the if block and style the rest of post in the else.
Note: To check another post as featured we have to set ‘featured’ to ‘no’ on the old featured post.
Hope this helps