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.

For the Single post, wordpress would choose the Single.php. which is below

<?php
/*
 Template Name: single movie Template
 */
get_header(); ?>

<div id="primary">
    <div id="content" role="main">
    <?php query_posts(array('post_type'=>'movie_reviews')); ?>
    <?php $mypost = array( 'post_type' => 'movie_reviews' );
    $loop = new WP_Query( $mypost ); ?>
    <!-- Cycle through all posts -->
    <?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
        <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
            <header class="entry-header">

                <!-- Display featured image in right-aligned floating div -->
                <div style="float:top; margin: 10px">
                    <?php the_post_thumbnail( array(100,100) ); ?>
                </div>

                <!-- Display Title and Author Name -->
                <strong>Title: </strong><?php the_title(); ?><br />
                <strong>Director: </strong>
                <?php echo esc_html( get_post_meta( get_the_ID(), 'movie_director', true ) ); ?>
                <br />

                <!-- Display yellow stars based on rating -->
                <strong>Rating: </strong>
                <?php
                $nb_stars = intval( get_post_meta( get_the_ID(), 'movie_rating', true ) );
                for ( $star_counter = 1; $star_counter <= 5; $star_counter++ ) {
                    if ( $star_counter <= $nb_stars ) {
                        echo '<img src="' . plugins_url( 'Movie-Reviews/images/icon.png' ) . '" />';
                    } else {
                        echo '<img src="' . plugins_url( 'Movie-Reviews/images/grey.png' ). '" />';
                    }
                }
                ?>

            </header>

            <!-- Display movie review contents -->
            <div class="entry-content"><?php the_content(); ?></div>

        </article>

        <hr/>
    <?php endwhile; ?>
    </div>
</div>
<?php wp_reset_query(); ?>
<?php get_footer(); ?>

For archive and list of them the wordpress would chose archive.php

/*
Template Name: archive movie template

*/

<?php get_header(); ?>
<section id="primary">
<div id="content" role="main" style="width: 70%">
<?php if ( have_posts() ) : ?>
          <header class="page-header">
          <h1 class="page-title">Movie Reviews</h1>
         </header>
         <table>
        <!-- Display table headers -->
        <tr>
        <th style="width: 200px"><strong>Title</strong></th>
        <th><strong>Director</strong></th>
        </tr>
        <!-- Start the Loop -->
        <?php while ( have_posts() ) : the_post(); ?>
                 <!-- Display review title and author -->
                <tr>
               <td><a href="<?php the_permalink(); ?>">
               <?php the_title(); ?></a></td>
              <td><?php echo esc_html( get_post_meta( get_the_ID(), 'movie_director', true ) ); ?></td>
              </tr>
         <?php endwhile; ?>

<!-- Display page navigation -->

</table>
<?php global $wp_query;
if ( isset( $wp_query->max_num_pages ) && $wp_query->max_num_pages > 1 ) { ?>
    <nav id="<?php echo $nav_id; ?>">
   <div class="nav-previous"><?php next_posts_link( '<span class="meta-nav">&larr;</span> Older reviews'); ?></div>
   <div class="nav-next"><?php previous_posts_link( 'Newer reviews <span class= "meta-nav">&rarr;</span>' ); ?></div>
  </nav>
 <?php };
endif; ?>
  </div>
</section>
<?php get_footer(); ?>

So, my question, archive display is just a collection of the single display. For this case, there would be a stars displayed for movie review in single post but I don't see star displayed in archive.php. Does archive.php in some way call single.php by wordpress?

share|improve this question
    
archive.php is its own page - it does not call single.php. The ratings don't show in your archive, because none of the ratings code is included in archive.php. –  vancoder Apr 4 '13 at 20:58
    
See the codex pages about Template Hierarchy. archive.php (if present) does not call any other template files (unless explicitly coded that way, for instance, by get_template_part). If archive.php is missing, however, WordPress loads index.php. –  t f Apr 4 '13 at 21:10
    
However,I do see stars in the archive page. List of 5 Movie Reviews. And each review consists of rating of stars. –  jason hong Apr 4 '13 at 21:19
    
Then you're not looking at the archive.php that you have included here. –  vancoder Apr 4 '13 at 21:23
    
You have declared your archive.php to be a template at the top of the file. I'm not sure if that will exclude it from being used an automatic archive page. –  vancoder Apr 4 '13 at 22:13

Your Answer

 
discard

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

Browse other questions tagged or ask your own question.