Link a modified single.php to a Post Type WordPress

0

I am creating a Physicians directory, so I used Custom Post Types and Custom Fields to make a personalized tab of each person I needed to create a directory of doctors.

So far, I made the custom posts and customs fields, but according to the tutorial to give the format that I want to each doctor file, I must create a copy of the file single.php, in the tutorial, it changes the name to the file, as single-books.php and automatically shows the changes.

I am using Astra, and I did what I could to add the code, but I do not know if I need another step to connect the "Medical" CPT posts with the custom fields, or I am entering the code incorrectly.

Link to the tutorials

Custom Post Type "Doctors"

single-doctor.php:

 <?php
/**
* The template for displaying all single posts.
*
* @link https://developer.wordpress.org/themes/basics/template-hierarchy/#single-post
*
* @package Astra
* @since 1.0.0
*/

get_header(); ?>

<?php if ( astra_page_layout() == 'left-sidebar' ) : ?>

<?php get_sidebar(); ?>

<?php endif ?>

    <div id="primary" <?php astra_primary_class(); ?>>

        <?php astra_primary_content_top(); ?>

        <div class="col-lg-3 col-md-3 col-sm-12 col-xs-12">
           <?php $imagen_doctor = get_field( 'imagen_doctor' ); ?>
      <?php if ( $imagen_doctor ) { ?>
    <img src="<?php echo $imagen_doctor['url']; ?>" alt="<?php echo $imagen_doctor['alt']; ?>" />
<?php } ?> </br></br>

      <b>Nombre:</b> &nsbp; <?php the_field( 'nombre' ); ?></br></br>

         <b>Especialidad:</b>&nsbp;<?php the_field( 'especialidad' ); ?></br></br>

        </div>

        <div class="col-lg-9 col-md-9 col-sm-12 col-xs-12">
        <i><?php the_field( 'resena' ); ?></i><br></br>
        <b>Permiso COFEPRIS:</b>&nsbp;<?php the_field( 'permiso_cofepris' ); ?></br></br>
        <b>Cédula Profesional:</b>&nsbp;<?php the_field( 'cedula' ); ?></br></br>
        <b>Dirección:</b>&nsbp;<?php the_field( 'direccion' ); ?></br></br>
        <b>Teléfono:</b>&nsbp;<?php the_field( 'telefono' ); ?></br></br>
        <b>Correo Electrónico:</b>&nsbp;<?php the_field( 'correo' ); ?></br></br>
        <?php $location_array = get_field( 'ubicacion_google_maps' );
// var_dump( $location_array ); ?></br></br>
        </div>

        <?php astra_content_loop(); ?>


        <?php astra_primary_content_bottom(); ?>

    </div><!-- #primary -->

<?php if ( astra_page_layout() == 'right-sidebar' ) : ?>

    <?php get_sidebar(); ?>

<?php endif ?>

<?php get_footer(); ?>
    
asked by Rebeca Lopez Cobarrubias 11.11.2018 в 04:04
source

1 answer

0

The answer is: You just have to change the name of the file to the same as the custom post type to recognize it.

I used single-doctors.php but the name of the custom post type was "Pt_doctors" so it did not appear and had conflicts; so I changed the file name to single-pt_doctors.php 'and now it works correctly.

    
answered by 11.11.2018 в 19:03