Jump to content

Duplicate php code but different result displayed ?


CtrlAltDel

Recommended Posts

HI All, Im having real trouble trying to solve this problem.

in my page i have "<!-- START of RECENT Babies -->" section, which displays just fine.

In a nutshell, i have copied and pasted it again into the same page "<!-- START of RECENT Babies 2 -->

 

the first set displays 3 images across the page, however, the 2nd set displays just 2 images across.

 

If i remove the first set of code, the 2nd displays just fine with 3 images. so i assume its working.

 

I cant for the life of me work out what im doing wrong, any clues please.

 

here is my page code:

EDIT: sorry first post using code tag. i set it as lime93 as i thought it meant where the problem was. line 93 here is actually the very first line.

<?php
/**
Home Page
 */

get_header(); ?>

 


    <!-- START of 2 BOXED  Slides -->  
   
    <div id="primary" class="content-area"> 
    
    <?php if( get_theme_mod( 'active_featured_stories' ) == '') : ?> 
     
		<main id="main" class="site-main grid stories" role="main">

        	<div class="col-1-1">
        		<?php if ( get_theme_mod( 'blackandwhite_featured_title' ) ) : ?>
        			<h1 class="featured-title"><?php echo esc_html( get_theme_mod( 'blackandwhite_featured_title' )); // change the title ?></h1>
            	<?php endif; ?> 
        	</div><!-- col-1-1 -->
             
			<!-- Beginning of Featured Stories --> 
        	<div class="featured-stories">
			
				<?php
				global $post;
				$args = array( 'post_type' => 'post', 'posts_per_page' => 2, 'meta_key' => '_bw_secondary_checkbox'  );
				$myposts = get_posts( $args );
				foreach( $myposts as $post ) :	setup_postdata($post); ?>
				
            	<div class="featured-container">
                	<div class="featured-info featured-container"> 
                    	<h1><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
               			<p><?php $content = get_the_content(); echo wp_trim_words( $content , '15' ); ?></p>
                	
                    	<a class="read-up" href="<?php the_permalink(); ?>">
                    		<?php if ( get_theme_mod( 'blackandwhite_button_text' ) ) : ?>
								<?php echo esc_html( get_theme_mod( 'blackandwhite_button_text' )); // change the text ?>
                    		<?php endif; ?>
                    	</a>   
                	</div><!-- featured-info --> 
                    
                	<div class="featured-image featured-container">
                		<a href="<?php the_permalink(); ?>">
							<?php the_post_thumbnail('featured-square', array('class' => 'featured-thumb grayscale')); // featured-square thumbnail ?>
                    	</a> 
                	</div><!-- featured-image -->
            	</div><!-- featured-container --> 
				<?php endforeach; // end featured stories ?>
        
        	</div><!-- featured-stories --> 


		</main><!-- #main -->

</div>
        
    <?php else : ?>  
	<?php endif; ?>
	<?php // end if ?>  
    <!-- END of 2 BOXED  Slides --> 



<!-- Beginning of Intro Post -->
    <div id="secondary" class="content-area">
		<main id="main" class="site-main grid" role="main">
<?php
global $more;
$more = 0;
query_posts('cat=9');

if(have_posts()) : while(have_posts()) : the_post();
?></p>
    					<h1><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
<?php
$content = get_the_content('Read more');
print $content;
?>


<p><?php
endwhile;
endif;
wp_reset_query();
?>
<!-- END of Intro Post -->


<!-- START of RECENT Babies -->         
	</div><!-- #primary -->

    <div id="secondary" class="content-area">
		<main id="main" class="site-main grid" role="main">
        	
			<?php if ( get_theme_mod( 'blackandwhite_editorial_title' ) ) : ?>
            	<h1 class="featured-black">    
					<?php echo esc_html( get_theme_mod( 'blackandwhite_editorial_title' )); // change the title ?>
            	</h1>  
            <?php endif; ?>
                <div id="freshly-pressed">				
				<?php				
global $post;
$args = array( 'posts_per_page' => 6, 'offset'=> 0, 'category' => 7, 'order'=> 'DESC','orderby'=> 'date',);

$myposts = get_posts( $args );
foreach ( $myposts as $post ) : setup_postdata( $post ); ?>				            
                <div class="press">
                <a href="<?php the_permalink(); ?>"><?php the_post_thumbnail('large', array('class' => 'featured-thumb grayscale')); ?></a>
                	
                    <div class="press-info">
    					<h1><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
                		<p><?php the_date(); ?></p>
                	</div><!-- press-info --> 
                
                </div><!-- press --> 
				<?php endforeach; ?> 
                </div><!-- Freshly Pressed -->   

		</main><!-- #main -->
	</div><!-- #secondary -->
<!-- END of RECENT Babies  --> 



<!-- START of RECENT Babies 2 -->         
	</div><!-- #primary -->

    <div id="secondary" class="content-area">
		<main id="main" class="site-main grid" role="main">
        	
			<?php if ( get_theme_mod( 'blackandwhite_editorial_title' ) ) : ?>
            	<h1 class="featured-black">    
					<?php echo esc_html( get_theme_mod( 'blackandwhite_editorial_title' )); // change the title ?>
            	</h1>  
            <?php endif; ?>
                <div id="freshly-pressed">				
				<?php				
global $post;
$args = array( 'posts_per_page' => 6, 'offset'=> 0, 'category' => 7, 'order'=> 'DESC','orderby'=> 'date',);

$myposts = get_posts( $args );
foreach ( $myposts as $post ) : setup_postdata( $post ); ?>				            
                <div class="press">
                <a href="<?php the_permalink(); ?>"><?php the_post_thumbnail('large', array('class' => 'featured-thumb grayscale')); ?></a>
                	
                    <div class="press-info">
    					<h1><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
                		<p><?php the_date(); ?></p>
                	</div><!-- press-info --> 
                
                </div><!-- press --> 
				<?php endforeach; ?> 
                </div><!-- Freshly Pressed -->   

		</main><!-- #main -->
	</div><!-- #secondary -->
<!-- END of RECENT Babies 2 -->



    
    
<?php get_footer(); ?>
Edited by CtrlAltDel
Link to comment
Share on other sites

Way too much spaghetti code to follow.  Perhaps if you learned to structure your script to separate the php code from the html (put the php at the top) and to generate any dynamic data-reliant parts into php variables and inserted them into the non-dynamic parts at the end of the script things could be analyzed easier.

Edited by ginerjm
Link to comment
Share on other sites

If i remove the first set of code, the 2nd displays just fine with 3 images. so i assume its working.

 

Do you need both code blocks? If not, you're probably fine.

 

If so, is PHP set to display all errors and warnings? That will likely give you a clue as to what's causing the problem. To show all errors and warnings, you can add the following to the top of your PHP script:

<?php
//REPORT ALL PHP ERRORS
error_reporting(E_ALL);
ini_set('display_errors', 1);
?>
 
Just be sure to remove the code when you are done testing.

 

 

Way too much spaghetti code to follow. 

 

Unfortunately, this seems to be the style when working with WordPress websites.

Edited by cyberRobot
Link to comment
Share on other sites

Thank you cyberRobot, i did as you suggested and it threw no errors. But thanks for your your reply nonetheless.

 

@ginerjm  perhaps if you learned to use punctuation in your posts they could be easier read, think of the scoldings you could give out then.

I had forgotten why i don't visit here much.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.