• Resolved baannng

    (@baannng)


    Hi
    I’m getting crazy with this one. I have my index redirecting to the single.php because I want to show single posts right in the website entrance. I dont know if this is in fact the best way to do this, but as it works I’m using this method.

    Index.php

    <?php
    	require('./wp-blog-header.php');
    	if (have_posts()) : the_post();
    		header("location: ".get_permalink());
    	exit;
    	endif;
    ?>

    Single.php

    <?php get_header(); ?>
    
    <div id="bcshadow"></div>
    
    <section id="ballcontent" role="main">
    
    	<div id="bpostnavigation">
    		<?php get_template_part( 'nav', 'below-single' ); ?>
    	</div>
    
    	<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    
    		<?php if ( is_front_page() ) { ?>
    			<div class="bcontent">
    			    <?php get_template_part( 'entry' ); ?>
    			</div>
    			<div class="mynewsonlyinfisrtpost">NEWS</div>
    		<?php } else { ?>
    			<div class="bcontent">
    			    <?php get_template_part( 'entry' ); ?>
    			</div>
    		<?php } ?>
    
    	<?php endwhile; endif;?>
    
    </section>
    
    <?php get_footer(); ?>

    Thank you in advanced for your help.
    AMP.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter baannng

    (@baannng)

    Need to correct the Single.php script:

    Where it says:
    <?php if ( is_front_page() ) { ?>

    There should be:
    <?php if( $wp_query->current_post == 0 && !is_paged() ) { ?>

    That’s my last try out.
    I’ve tried with is_front_page, is_home,… and no results.

    Thread Starter baannng

    (@baannng)

    I found this:

    functions.php

    //Check for First Post
    $thepost_id;
    $query_args = array();
    function current_post_is_latest_post() {
          static $latest_post_id = false;
          $thepost_id = empty( $thepost_id ) ? get_the_ID() : $thepost_id ;
    
          if( !$latest_post_id ) {
              $query_args['numberposts'] = 1;
              $query_args['post_status'] = 'publish';
              $last = wp_get_recent_posts( $query_args );
              $latest_post_id = $last['0']['ID'];
          }
    
          return $latest_post_id == $thepost_id;
    }

    single.php

    <?php get_header(); ?>
    
    <div id="bcshadow"></div>
    
    <section id="ballcontent" role="main">
    
    	<div id="bpostnavigation">
    		<?php get_template_part( 'nav', 'below-single' ); ?>
    	</div>
    
    		<?php if( current_post_is_latest_post() ) { ?>
    			<div class="bcontent">
    				<?php get_template_part( 'entry' ); ?>
    			</div>
    
    			<?php get_template_part( 'entry', 'news' ); ?>
    
    		<?php } else { ?>
    
    			<div class="bcontent">
    				<?php get_template_part( 'entry' ); ?>
    			</div>
    
    		<?php } ?>
    
    </section>
    
    <?php get_footer(); ?>

    Thanks you anyways.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Check if it's the first post’ is closed to new replies.