Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm using the approach of having all of my single-views in one loop-single.php and thus have a simple switch statement that will render each single-view based on the post type:

switch($post->post_type) {

    do_action('basey_loop_single');

    default: ?>

        <?php echo apply_filters('basey_page_title_news', __('<h1>News</h1>','basey')); ?>
        <?php /* Start loop */ ?>
        <?php while (have_posts()) : the_post(); ?>
            <?php basey_post_before(); ?>
                <article <?php post_class() ?> id="post-<?php the_ID(); ?>">
                    <?php basey_post_inside_before(); ?>
                        <header>
                            <h2 class="entry-title"><?php the_title(); ?></h2>
                            <?php basey_entry_meta(); ?>
                        </header>
                        <div class="entry-content">
                            <?php the_content(); ?>
                        </div>
                        <footer>
                            <?php wp_link_pages(array('before' => '<nav id="page-nav"><p>' . __('Pages:', 'basey'), 'after' => '</p></nav>' )); ?>
                            <div class="taxonomy">
                                <?php echo __('Posted in ','basey'); the_category(', '); ?>
                            </div>
                            <?php $tag = get_the_tags(); if (!$tag) { } else { ?><div class="tags"><?php the_tags(); ?></div><?php } ?>
                            <div class="commentLinks"><?php comments_popup_link( __( ' 0 Comments', 'blank' ), __( ' 1 Comment', 'blank' ), __( ' % Comments', 'blank' ), 'comments-link', __('Comments closed', 'blank')); ?> <?php if ( comments_open() ) : ?>| <a href="<?php the_permalink(); ?>#respond" title="<?php echo __('Add a Comment','basey'); ?>"><?php echo __('Add a Comment','basey'); ?></a><?php endif; ?>
                            </div>
                        </footer>
                    <?php basey_post_inside_after(); ?>
                    <?php comments_template(); ?>
                </article>
            <?php basey_post_after(); ?>
        <?php endwhile; /* End loop */ ?>

<?php }

You can see at the top that I've included a do_action() call for what I hope can be an extendable area (that can be plugged-into via other plugins or theme functions I write). While this is also part core PHP question --> is there a way to plug into a switch statement the same way you would an array (like so):

function add_extra_fruits($fruits) {

$extra_fruits = array(
    'plums',
    'kiwis',
    'tangerines',
    'pepino melons'
);

// combine the two arrays
$fruits = array_merge($extra_fruits, $fruits);

return $fruits;
}
add_filter('add_fruits', 'add_extra_fruits');
share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

Not quite sure what you're after - something like this?

<?php echo apply_filters( 'basey_page_title_news', __( '<h1>News</h1>', 'basey' ) ) ?>
<?php

    while ( have_posts() ) : the_post();
        switch ( true ) :
            case has_action( "basey_loop_single_$post->post_type" ) :
                do_action( "basey_loop_single_$post->post_type", $post );
                break;

            default : ?>

    <!-- your fallback code -->

<?php

        endswitch;
    endwhile;

?>

If a plugin/theme created a hook for a particular post type, it'd replace the default output.

share|improve this answer
    
Yeah that honestly looks like what it - but function basey_loop_single_page_output() { echo 'test'; } add_action('basey_loop_single_page', 'basey_loop_single_page_output'); isn't working -- any suggestions? –  Zach Jul 3 '12 at 19:02
    
Is the post type in question definitely a page? –  TheDeadMedic Jul 3 '12 at 19:05
    
Yesir, definitely a page. –  Zach Jul 3 '12 at 19:09
    
OH MY, one of those days. Check revision (note the switch expression). –  TheDeadMedic Jul 3 '12 at 19:19
    
Appreciate the continued help with this - still nothin though - is everything working on your end? Thanks again. –  Zach Jul 3 '12 at 19:22
show 3 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.