HiveBrain v1.2.0
Get Started
← Back to all entries
patternphpMinor

Displaying all single posts

Submitted by: @import:stackexchange-codereview··
0
Viewed 0 times
allpostssingledisplaying

Problem

I think there are some confusing and weird indentation problems in this WordPress file (single.php). Any suggestions on improving indentation and readability?


    ID, 'Intro Image', true); ?>
        
            " alt="" />
         

      
            
        
    

    
        
        ID, 'Mainbar Left Title', true);
            $mainbar_left_image = get_post_meta($post->ID, 'Mainbar Left Image', true); ?>
            
                
                " alt="" />
             

        ID, 'Mainbar Right Title', true);
            $mainbar_right_image = get_post_meta($post->ID, 'Mainbar Right Image', true); ?>
            
                
                " alt="" />
             
    

    ID, 'Mainbar Right Title', true);
        $mainbar_right_image = get_post_meta($post->ID, 'Mainbar Right Image', true); ?>
        
            
            " alt="" />
         

      
            
        
    

    

Solution

You could you PHP alternate syntax


    ID, 'Intro Image', true); ?>
    
        " alt="" />
    

      
        
            
        
    

    
        ID, 'Mainbar Left Title', true); ?>
        ID, 'Mainbar Left Image', true); ?>
        
            
            " alt="" />
        

            ID, 'Mainbar Right Title', true); ?>
            ID, 'Mainbar Right Image', true); ?>
        
            
            " alt="" />
        
    

    ID, 'Mainbar Right Title', true); ?>
    ID, 'Mainbar Right Image', true); ?>
    
        
        " alt="" />
    

    
        
            
        
    

    


This follows all WP coding standards from what I can tell and is readable.
I would also suggest changing sections like this:

ID, 'Mainbar Right Title', true); ?>
ID, 'Mainbar Right Image', true); ?>

    
    " alt="" />


To:


    ID, 'Mainbar Right Title', true); ?>
    ID, 'Mainbar Right Image', true) ?>" alt="" />


Although that's just personal preference, I find it much more readable.

Code Snippets

<?php
/**
 * The Template for displaying all single posts.
 *
 * @package WordPress
 * @subpackage Starkers
 * @since Starkers 3.0
 */
?>

<?php get_header(); 
<?php get_sidebar(); ?>

<div id="content">
    <?php $intro_image = get_post_meta($post->ID, 'Intro Image', true); ?>
    <div class="block-1">
        <img src="<?php echo $intro_image; ?>" alt="" />
    </div>

    <?php if ( have_posts() ? while ( have_posts() ) : the_post()): ?>  
        <div class="block-2 padding-top no-overlay">
            <?php the_content(); ?>
        </div>
    <?php endwhile; ?>

    <div class="block-2 border-top">
        <?php $mainbar_left_title = get_post_meta($post->ID, 'Mainbar Left Title', true); ?>
        <?php $mainbar_left_image = get_post_meta($post->ID, 'Mainbar Left Image', true); ?>
        <div class="float-left">
            <h2><?php echo $mainbar_left_title; ?></h2>
            <img src="<?php echo $mainbar_left_image ?>" alt="" />
        </div>

            <?php $mainbar_right_title = get_post_meta($post->ID, 'Mainbar Right Title', true); ?>
            <?php $mainbar_right_image = get_post_meta($post->ID, 'Mainbar Right Image', true); ?>
        <div class="float-right">
            <h2><?php echo $mainbar_right_title; ?></h2>
            <img src="<?php echo $mainbar_right_image ?>" alt="" />
        </div>
    </div>

    <?php $mainbar_right_title = get_post_meta($post->ID, 'Mainbar Right Title', true); ?>
    <?php $mainbar_right_image = get_post_meta($post->ID, 'Mainbar Right Image', true); ?>
    <div class="block-3 border-top">
        <h2><?php echo $mainbar_right_title; ?></h2>
        <img src="<?php echo $mainbar_right_image ?>" alt="" />
    </div>

    <?php if ( have_posts() ? while ( have_posts() ) : the_post()): ?>
        <div class="block-4 border-top">
            <?php the_content(); ?>
        </div>
    <?php endwhile; ?>

    <?php get_sidebar('secondary'); ?>
</div>

<?php get_footer(); ?>
<?php $mainbar_right_title = get_post_meta($post->ID, 'Mainbar Right Title', true); ?>
<?php $mainbar_right_image = get_post_meta($post->ID, 'Mainbar Right Image', true); ?>
<div class="block-3 border-top">
    <h2><?php echo $mainbar_right_title; ?></h2>
    <img src="<?php echo $mainbar_right_image ?>" alt="" />
</div>
<div class="block-3 border-top">
    <h2><?php echo get_post_meta($post->ID, 'Mainbar Right Title', true); ?></h2>
    <img src="<?php echo get_post_meta($post->ID, 'Mainbar Right Image', true) ?>" alt="" />
</div>

Context

StackExchange Code Review Q#837, answer score: 5

Revisions (0)

No revisions yet.