Forum Replies Created

Viewing 11 replies - 31 through 41 (of 41 total)
  • Thread Starter digstertron

    (@digstertron)

    The queries were both met, I added relevant HTML to both the if and else statement.

    I’ll come back to it tomorrow. Completely mind numbingly irritating, all I want to do is display the very latest post at the top of the blog page with the remaining posts in a row below. I’ve found writing HTML and CSS quite easy but this PHP is another level of nonsense ??

    Thanks ever so much for your help though.

    • This reply was modified 3 years, 2 months ago by digstertron.
    Thread Starter digstertron

    (@digstertron)

    Here is what I see:

    Screen grab

    Thread Starter digstertron

    (@digstertron)

    There is no error now only the echoed out content does not appear at all. All I see is the header and footer.

    Thread Starter digstertron

    (@digstertron)

    I realise it’s something I’ve done but this is madenning, is this code correct?

    <?php
    
    get_header('topbar'); ?>
    	
    <div class="blog_container">
    		<h2 class="blog-title">
    		Latest News
    		</h2>
    	<p>
    		News information and much more.
    	</p>
    </div>
    
    <?php 
    $posts_query = new WP_Query( $query_args );
    
    if ( $posts_query->have_posts()) { 
    
      $first_post = true;
      while ( $posts_query->have_posts() ) { 
        $posts_query->the_post();
        
        if ( $first_post ) {
         echo '<h2>This is where my latest post will appear</h2>';
        } else {
          echo '<h2>This is where all subsequent posts should appear</h2>';
    }
    
        $first_post = false;
      } 
    
    }
    
    wp_reset_postdata();
    
    ?>
    	
    
    <?php get_footer();
    
    ?>
    Thread Starter digstertron

    (@digstertron)

    Tried both options the problem persists.

    Thread Starter digstertron

    (@digstertron)

    Thank you.

    Here is the latest code, notice the if and else statements are blank I tried to reverse engineer the code, whenever I add html it breaks but here is my code:

    <?php
    
    get_header('topbar'); ?>
    	
    <div class="blog_container">
    		<h2 class="blog-title">
    		Latest News
    		</h2>
    	<p>
    		News information and much more.
    	</p>
    </div>
    
    $posts_query = new WP_Query( $query_args );
    
    if ( $posts_query->have_posts()) { 
    
      $first_post = true;
      while ( $posts_query->have_posts() ) { 
        $posts_query->the_post();
        
        if ( $first_post ) {
        
        } else {
          
        }
    
        $first_post = false;
      } 
    
    }
    
    wp_reset_postdata();
    
    	
    
    		
    <?php 
    ?>
    <?php get_footer();
    
    ?>
    Thread Starter digstertron

    (@digstertron)

    I should probably start a new thread but the code you provided does not work when I apply any line of HTML. Incredibly frustrating, there is no reason why it shouldn’t work and now I get parsing errors every time I add HTML after the if and else statements.

    Thread Starter digstertron

    (@digstertron)

    Ok it’s working sort of but I am seeing raw code on the front end, any ideas?

    Thread Starter digstertron

    (@digstertron)

    Unfortunately it doesn’t work. WP throws an eppy and complains about unexpected ‘<‘ tags which are just div containers that I’ve set for the blog post info to occupy.

    <?php
    
    get_header('topbar'); ?>
    
    <div class="blog_container">
    <h2 class="blog-title">
    Latest News
    </h2>
    <p>
    News information and much more.
    </p>
    </div>
    
    <?php
    while(have_posts()) {
    the_post();?>
    
    <div class="container blog_info">
    	<div class="post-item">
    		<div class="post-image"><?php the_post_thumbnail(); ?></div>
    	</div>
    
    	<div class="blog_outter">			
    		<h2 class="blog_heading">
    			<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
    		</h2>
    		
    			<div class="blog_author">
    				<div class="author_image"><?php echo get_avatar( get_the_author_meta('ID'), 60); ?></div>
    			
    				<div class="author-profile"><?php the_author_posts_link();?></div>
    				<div class="category__list__card">
    						<p class="cat">
    							<?php echo get_the_category_list(', '); ?>
    						</p>
    				</div>
    			
    				<div class="post__stamp">
    					<?php the_time('F j, Y'); ?>
    				</div>		
    			</div>
    	</div>	
    </div>
    
    <?php }
    ?>
    <?php get_footer();
    
    ?>
    • This reply was modified 3 years, 2 months ago by digstertron.
    • This reply was modified 3 years, 2 months ago by digstertron.
    Thread Starter digstertron

    (@digstertron)

    Thanks Matt,

    Sorry I misread your original post, of course the code resides in index.php file which powers my blog page. I shall give it a whirl and let you know how I get on. Cheers!

    Thread Starter digstertron

    (@digstertron)

    Hi there,

    This is great info, many thanks.

    Would the code above reside in the actual index file or functions.php file?
    Also I already have the famous while loop, I guess your code would replace this?

    • This reply was modified 3 years, 2 months ago by digstertron.
Viewing 11 replies - 31 through 41 (of 41 total)