I want to style the first element of the blog different and i need a possibility to find it in php. I used the coming expression, but it shows only the first element: $postID=$wp_query->current_post;
The post of this Variable is always 0.
Here my Code, i hope someone have a solution for me. I use the Astra Theme with a Child Theme… and its the content-blog.php
<?php
/**
* Template part for displaying posts.
*
* @link https://codex.wordpress.org/Template_Hierarchy
*
* @package Astra
* @since 1.0.0
*/
?>
<?php astra_entry_before(); ?>
<?php
$postID=$wp_query->current_post;
$marginPosition = '';
if ($postID != 0 && !is_paged()) :
if($postID % 2 == 0 || $postID % 3 == 0) {
$marginPosition = 'left-margin';
}
if($postID % 3 == 0){
$marginRightPosition = "no-right-margin";
}
if($postID % 4 == 0){
$marginPosition = '';
}
if($postID % 5 == 0){
$marginPosition = 'left-margin';
}
endif;
echo $postID;
?>
<article
<?php
echo astra_attr(
'article-blog',
array(
'id' => 'post-' . get_the_id(),
'class' => join( ' ', get_post_class() ).' '.$marginPosition. ' '.$marginRightPosition,
)
);
?>
>
<div class="article-holder <?php if( $postID == 0 && !is_paged() ) : ?>firstarticle<?php else: ?>standard-article<?php endif; ?>">
<?php if( $postID == 0 && !is_paged() ) : ?>
<div class="left">
<div class="featured-image">
<a href="<?php the_permalink();?>">
<?php the_post_thumbnail( 'featured-blog-size' ); ?>
</a>
</div>
</div>
<div class="right">
<div class="title"><h2><a href="<?php the_permalink();?>"><?php echo get_the_title( ); ?></a></h2></div>
<div class="latest-banner"><span>latest article</span></div>
<?php echo do_shortcode( '[molongui_author_box]' ); ?>
</div>
<?php else: ?>
<div class="top">
<div class="standard-image">
<a href="<?php the_permalink();?>">
<?php the_post_thumbnail( 'standard-blog-size' ); ?>
</a>
</div>
</div>
<div class="bottom">
<div class="title"><h2><a href="<?php the_permalink();?>"><?php echo get_the_title( ); ?></a></h2></div>
<div class="written-by-content">
<div class="right-wb">
<span>by <a href="#">Josephine Choo</a>, PhD<br></span>
<span>Consultant</span>
<div class="date"><?php echo get_the_date( 'F dS Y' ); ?></div>
</div>
</div>
</div>
<?php endif; ?>
</div>
</article><!-- #post-## -->
<?php astra_entry_after(); ?>