Skip to main content
added a tag
Link
Malachi
  • 29.1k
  • 11
  • 87
  • 188

How can I modify the following WordPress custom loops in order to improve readability and efficiency for Wordpress?

Spelling. No tag in title. Removed unrelated content and signature.
Source Link

How can I modify the following WordpressWordPress custom loops (PHP) in order to improve readability (andand efficiency)?

I'm just a beginner in PHP and I would like to know tips in order to improve readability (andand perhaps efficiency).

Thanks in advance.

Alex

How can I modify the following Wordpress custom loops (PHP) in order to improve readability (and efficiency)?

I'm just a beginner in PHP and I would like to know tips in order to improve readability (and perhaps efficiency).

Thanks in advance.

Alex

How can I modify the following WordPress custom loops in order to improve readability and efficiency?

I'm just a beginner in PHP and I would like to know tips in order to improve readability and perhaps efficiency.

Tweeted twitter.com/#!/StackCodeReview/status/34263164208029696
Source Link
wyc
  • 555
  • 1
  • 3
  • 9

How can I modify the following Wordpress custom loops (PHP) in order to improve readability (and efficiency)?

The following code retrieve custom post types with their custom taxonomy.

I'm just a beginner in PHP and I would like to know tips in order to improve readability (and perhaps efficiency).

home.php:

<?php
/**
 * Template Name: Home
 * @package WordPress
 * @subpackage Prominent
 * @since Prominent 1.0
 */
get_header(); ?>

<div id="sidebar">
    <?php get_sidebar(); ?>
</div><!-- #sidebar -->

<div id="content">

    <?php // Create and run custom loop
        $custom_posts = new WP_Query();
        $custom_posts->query('post_type=page_content&page_sections=Profile');
        while ($custom_posts->have_posts()) : $custom_posts->the_post();
    ?>
    <div class="block-1">
        <?php the_post_thumbnail('large'); ?>
    </div>
    <?php endwhile; ?>

    <?php // Create and run custom loop
        $custom_posts = new WP_Query();
        $custom_posts->query('post_type=page_content&page_sections=Tagline');
        while ($custom_posts->have_posts()) : $custom_posts->the_post();
    ?>
    <div class="block-2 padding-top">
        <h2><?php the_title(); ?></h2>
        <p><?php the_content(); ?></p>
    </div>
    <?php endwhile; ?>

    <?php // Create and run custom loop
        $custom_posts = new WP_Query();
        $custom_posts->query('post_type=page_content&page_sections=Themep');
        while ($custom_posts->have_posts()) : $custom_posts->the_post();
    ?>
    <div class="block-2 border-top">
        <h2><a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'twentyten' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title(); ?></a></h2>
    <?php endwhile; ?>

        <?php // Create and run custom loop
            $custom_posts = new WP_Query();
            $custom_posts->query('post_type=page_content&page_sections=ThemeCL');
            while ($custom_posts->have_posts()) : $custom_posts->the_post();
        ?>  <div class="float-left">
                <a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'twentyten' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_post_thumbnail(); ?></a>
                <p><?php the_excerpt(); ?></p>
            </div>
        <?php endwhile; ?>

        <?php // Create and run custom loop
            $custom_posts = new WP_Query();
            $custom_posts->query('post_type=page_content&page_sections=Theme Child Right');
            while ($custom_posts->have_posts()) : $custom_posts->the_post();
        ?>  <div class="float-right">
                <a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'twentyten' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_post_thumbnail(); ?></a>
                <p><?php the_excerpt(); ?></p>
            </div>
        </div>
    <?php endwhile; ?>

    <?php // Create and run custom loop
        $custom_posts = new WP_Query();
        $custom_posts->query('post_type=page_content&page_sections=FromBlog');
        while ($custom_posts->have_posts()) : $custom_posts->the_post();
    ?>  <div class="block-3 border-top">
            <h2><a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'twentyten' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title(); ?></a></h2>
            <a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'twentyten' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_post_thumbnail(); ?></a>
            <p><?php the_excerpt(); ?></p>
        </div>
    <?php endwhile; ?>

    <?php // Create and run custom loop
        $custom_posts = new WP_Query();
        $custom_posts->query('post_type=page_content&page_sections=Featured');
        while ($custom_posts->have_posts()) : $custom_posts->the_post();
    ?>
    <div class="block-2 border-top">
        <h2><a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'twentyten' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title(); ?></a></h2>
        <a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'twentyten' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_post_thumbnail('large'); ?></a>
        <p><?php the_excerpt(); ?></p>
    </div>
    <?php endwhile; ?>

    <?php // Create and run custom loop
        $custom_posts = new WP_Query();
        $custom_posts->query('post_type=page_content&page_sections=Last');
        while ($custom_posts->have_posts()) : $custom_posts->the_post();
    ?>
    <div class="block-3 border-top">
        <h2><a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'twentyten' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title(); ?></a></h2>
        <a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'twentyten' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_post_thumbnail(); ?></a>
        <p><?php the_excerpt(); ?></p>
        <p><?php the_meta(); ?></p>
    </div>
    <?php endwhile; ?>

    <?php // Create and run custom loop
        $custom_posts = new WP_Query();
        $custom_posts->query('post_type=page_content&page_sections=Lastest');
        while ($custom_posts->have_posts()) : $custom_posts->the_post();
    ?>
    <div class="block-7 border-top">
        <h2><a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'twentyten' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title(); ?></a></h2>
        <a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'twentyten' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_post_thumbnail(); ?></a>
        <p><?php the_excerpt(); ?></p>
    </div>
    <?php endwhile; ?>

</div><!-- #content -->

<?php get_footer(); ?>

Thanks in advance.

Alex