Custom Template Question? (2 posts)

  1. scm22ri
    Posted 3 years ago #

    Hi Everyone,

    I made my own WP template for displaying inventory (it's not fancy but that's not the point). My question is, how would I go about using a template and displaying inventory located in different states/cities.

    For example, the below code is displaying inventory in Providence, RI (because the sql syntax deems so) but how would I account for different states/cities inventory?

    Thanks Everyone!


    Template Name: Cars
     * The Template for displaying all single posts.
     * @package WordPress
     * @subpackage Twenty_Eleven
     * @since Twenty Eleven 1.0
    get_header(); ?>
    		<div id="primary">
    			<div id="content" role="main">
    				<?php while ( have_posts() ) : the_post(); ?>
    					<nav id="nav-single">
    						<h3 class="assistive-text"><?php _e( 'Post navigation', 'twentyeleven' ); ?></h3>
    						<span class="nav-previous"><?php previous_post_link( '%link', __( '<span class="meta-nav">←</span> Previous', 'twentyeleven' ) ); ?></span>
    						<span class="nav-next"><?php next_post_link( '%link', __( 'Next <span class="meta-nav">→</span>', 'twentyeleven' ) ); ?></span>
    					</nav><!-- #nav-single -->
    					<?php get_template_part( 'content', 'single' ); ?>
    					<?php echo "This is our custom template!";?>
    					 global $wpdb;
    					$cars = $wpdb->get_results("SELECT year, make, model, transmission, mileage, state, city, price
                        FROM cars_database d
                        WHERE (d.state = 'rhode island')
                        AND (d.city='providence')
                        GROUP BY (d.model)");
                        // print_r($cars);
    					// echo "<tr> <th>Year</th> <th>Make</th> <th>Model</th> <th>Transmission</th> <th>Mileage</th> <th>State</th> <th>City</th> <th>Price</th>";
    					 echo "This is the results for Rhode Island. How would I get the results for others states using this template?";
    					 echo "<table>";
                         foreach($cars as $car){
                         echo "<tr>";
                         echo "<td>".$car->year."</td>";
                         echo "<td>".$car->make."</td>";
                         echo "<td>".$car->model."</td>";
    					 echo "<td>".$car->transmission."</td>";
    					 echo "<td>".$car->mileage."</td>";
    					 echo "<td>".$car->state."</td>";
    					 echo "<td>".$car->city."</td>";
    					 echo "<td>".$car->Price."</td>";
                         echo "</tr>";
                        echo "</table>"; 
    					<?php comments_template( '', true ); ?>
    				<?php endwhile; // end of the loop. ?>
    			</div><!-- #content -->
    		</div><!-- #primary -->
    <?php get_footer(); ?>
  2. vtxyzzy
    Posted 3 years ago #

    One possibility would be to have the template get Custom Fields for state and city from the Page using it.

Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.