I have created a database that contains all the cities in the USA. I do not want to make a page for each city because it will become problematic because of there too many. in the database, I have set up a short link that can reference to what page it is and give me a result. so far I can test it by making a page selecting the parent(state) and selecting the template for it. that will take me forever to make a page for each city, it already took me a few weeks to complete the database. Every object is unique and has its own information and images.

I’ll place an example of what I have been working on on the bottom of the page Thanks for reading and have a great day!

    enter code here
    <?php /*template Name: city-pages*/ ?>

    <?php get_header(); ?>

    <?php
    /** Themify Default Variables
     *  @var object */
    global $themify; ?>

    <!--this code prints the information of the cities data base-->
    <?php  
    $city_info = get_city_info();
    echo'<pre>';print_r($city_info);echo'</pre>';
    ?>

    <!--END OF CODE-->

    <!-- layout-container -->
    <div id="layout" class="pagewidth clearfix">

      <?php themify_content_before(); // hook ?>
      <!-- content -->
      <div id="content" class="clearfix body-of-city">
        <?php themify_content_start(); // hook ?>

        <?php
        /////////////////////////////////////////////
        // 404
        /////////////////////////////////////////////
        if(is_404()): ?>
        <h1 class="page-title"><?php _e('404','themify'); ?></h1>
        <p><?php _e( 'Page not found.', 'themify' ); ?></p>
        <?php if( current_user_can('administrator') ): ?>
          <p><?php _e( '@admin Learn how to create a <a href="https://themify.me/docs/custom-404" target="_blank">custom 404 page</a>.', 'themify' ); ?></p>
        <?php endif; ?>
      <?php endif; ?>

      <?php
        /////////////////////////////////////////////
        // PAGE
        /////////////////////////////////////////////
      ?>
      <?php if ( ! is_404() && have_posts() ) : while ( have_posts() ) : the_post(); ?>
        <div id="page-<?php the_ID(); ?>" class="type-page">

          <!-- page-title -->
          <?php if($themify->page_title != "yes"): ?>

            <time datetime="<?php the_time( 'o-m-d' ); ?>"></time>
            <?php themify_theme_page_title(); ?>
          <?php endif; ?>
          <!-- /page-title -->

          <!-- page content for template -->   
     <section id="intro" class="intro-section">
    <div class="container">
        <div class="row">
            <div class="col-lg-12">
                <div class="col-lg-12 this-page-header">
                    <h1 class="first-header">Find the right <?php echo $city_info['city'] ?> motorcycle club </h1>
                </div>
                <div class="col-md-7 first-text">
                <p class="paragrap-one">
                    clubs in
                    <?php echo $city_info[ 'city'] ?> is a vital component. If you or a loved one is in
                    <?php echo $city_info[ 'city'] ?> or the surrounding areas and struggling to find a club to <span>
            <?php
            foreach ($city_info['links'] as $drug => $url) {
              echo '<span><a href="'.$url.'"> '.$drug.' </a></span>'; } ?>
                    </span> finding the right
                    <?php echo $city_info[ 'city'] ?> club that's out of state can help you.
                </p>
                </div>
            </div>
        </div>
    </div>
</section>








          <!--END OF CODE FOR CITY PAGES-->

          <div class="page-content entry-content">

            <?php if ( $themify->hide_page_image != 'yes' && has_post_thumbnail() ) : ?>
              <figure class="post-image"><?php themify_image( "{$themify->auto_featured_image}w={$themify->image_page_single_width}&h={$themify->image_page_single_height}&ignore=true" ); ?></figure>
            <?php endif; ?>

            <?php the_content(); ?>

            <?php wp_link_pages(array('before' => '<p class="post-pagination"><strong>'.__('Pages:','themify').'</strong> ', 'after' => '</p>', 'next_or_number' => 'number')); ?>

            <?php edit_post_link(__('Edit','themify'), '[', ']'); ?>

            <!-- comments -->
            <?php if(!themify_check('setting-comments_pages') && $themify->query_category == ""): ?>
              <?php comments_template(); ?>
            <?php endif; ?>
            <!-- /comments -->

          </div>
          <!-- /.post-content -->

        </div><!-- /.type-page -->
      <?php endwhile; endif; ?>

      <?php
        /////////////////////////////////////////////
        // Query Category
        /////////////////////////////////////////////
      ?>
      <?php if($themify->query_category != ''): ?>

        <?php
          // Categories for Query Posts or Portfolios
        $categories = '0' == $themify->query_category? themify_get_all_terms_ids($themify->query_taxonomy) : explode(',', str_replace(' ', '', $themify->query_category));
        $qpargs = array(
          'post_type' => $themify->query_post_type,
          'tax_query' => array(
            array(
              'taxonomy' => $themify->query_taxonomy,
              'field' => 'id',
              'terms' => $categories
              )
            ),
          'posts_per_page' => $themify->posts_per_page,
          'paged' => $themify->paged,
          'order' => $themify->order,
          'orderby' => $themify->orderby
          );
          ?>

          <?php
          query_posts(apply_filters('themify_query_posts_page_args', $qpargs)); ?>

          <?php if(have_posts()): ?>

            <?php
            /////////////////////////////////////////////
            // Entry Filter
            /////////////////////////////////////////////
            if ( ('portfolio' == $themify->query_post_type || 'post' == $themify->query_post_type )&& ( count( $categories ) > 1 ) && 'slider' !== $themify->post_layout && (!isset($themify->post_filter) || $themify->post_filter=='yes')) : ?>
            <?php get_template_part( 'includes/filter', 'portfolio' ); ?>
          <?php endif; // portfolio query ?>

          <!-- loops-wrapper -->
          <div id="loops-wrapper" class="loops-wrapper <?php echo esc_attr( themify_theme_query_classes() ); ?>">

            <?php while( have_posts() ) : the_post(); ?>

              <?php get_template_part( 'includes/loop', $themify->query_post_type ); ?>

            <?php endwhile; ?>

          </div>
          <!-- /loops-wrapper -->

          <?php if ( themify_is_query_page() ) : ?>
            <?php if ( $themify->page_navigation != 'yes' ): ?>
              <?php get_template_part( 'includes/pagination' ); ?>
            <?php endif; // show page navigation ?>
          <?php endif; // is query page ?>

        <?php endif; // have_posts() ?>

        <?php wp_reset_query(); ?>

      <?php endif; // is query page ?>

      <?php themify_content_end(); // hook ?>
    </div>
    <!-- /content -->
    <?php themify_content_after(); // hook ?>

    <?php
      /////////////////////////////////////////////
      // Sidebar
      /////////////////////////////////////////////
    if ($themify->layout != 'sidebar-none'): get_sidebar(); endif; ?>



    </div>
    <!-- /layout-container -->

    <?php get_footer(); ?>

<?php
/**
* Enqueues child theme stylesheet, loading first the parent theme stylesheet.
*/
function themify_custom_enqueue_child_theme_styles() {
    wp_enqueue_style( 'parent-theme-css', get_template_directory_uri() . '/style.css' );
}
add_action( 'wp_enqueue_scripts', 'themify_custom_enqueue_child_theme_styles', 11 );

    function get_city_info() {
         $_SERVER['REQUEST_URI'];
        $city_info = [
     '/testpage/alaska/adak/' => [
                'image-one' => '',
                'image-two' => '',
                'image-three' => '',
                'call-box' => '',
                'city' => 'Adak',
                'state' => 'Alaska',
                'description' => 'description',
                'abbreviation' => 'AK',
               'links' => [
                    'Ride-along' => '',
                    'clubs' => ''
                ],
                'links-two' => [
                    'Bikes' => '',
                    'choppers' => ''
                ],

        '/testpage/california/irvine/' => [
           'image-one' => '',
            'image-two' => '',
            'image-three' => '',
            'call-box' => '',
            'city' => 'Irvine',
            'state' => 'California',
            'description' => 'Irvine description',
            'abbreviation' => 'CA',
            'links' => [
                'Ride-along' => '',
                'clubs' => ''
            ],
            'links-two' => [
                'Bikes' => '',
                'choppers' => ''
            ]
        ]
        /*********************************************************************************************/
    ];

    $default = [
        'city' => '',
        'state' => '',
        'description' => '',
        'links' => [
        ]
    ];
    return isset($city_info[$_SERVER['REQUEST_URI']]) ? $city_info[$_SERVER['REQUEST_URI']] : $default;
}
/*****************************************************************************************************/

Read more here: How to use a template file for a specific url without creating a page for that template?


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: