Zar Saeed
Zar Saeed

Reputation: 110

Template page not showing data in WordPress

I created a template page on WordPress Admin and just added a h2 heading which does not appear with associated link for the page but it's working if admin logged in wordpress login. I also made the page public on page setting but still the problem is not remove page data shown only to admin. I have searched many forums but didn't find any solution.

  <?php 
/*
 Template Name: Contact Us

*/

get_header(); ?>


<div class="contact-box1">
    <h2 >
  <br><br>
        YOUR ENQUIRY
   </h2>

 <?php get_footer(); ?>

Upvotes: 1

Views: 1280

Answers (3)

Johannes
Johannes

Reputation: 67748

EDITED (I included the full code now):

It's not enough to include the header and the footer, you also need to include the loop in order to fetch the content which was for that particular page in the text editor (in the backend), where you should add/create your content.

So after creating that template, you need to create a "new page" in the backend, selecting that page template in the right sidebar.

In my example below, you would write your header into the title field in the backend, then it would be displayed as an h2 in the real page. And the whole content (inluding that title h2) is wrapped in the .contact-box1 DIV, as you had it in your original code.

example:

<?php 
/*
 * Template Name: Contact Us
 * @package WordPress
 * @subpackage Amplified_Antennas
*/

get_header(); ?>

<div class="contact-box1">

<?php 
if ( have_posts() ) {
    while ( have_posts() ) {
        the_post(); 
          <h2><?php the_title(); ?></h2>
          <?php the_content(); ?>
    } // end while
} // end if
?>

</div>

<?php get_footer(); ?>

P.S.: In your posted code, you are not closing this DIV tag: <div class="contact-box1">

Upvotes: 1

Shital Marakana
Shital Marakana

Reputation: 2887

how to create template in WordPress?

     <?php
/**
 Template Name: Contact Us
 *
 * This is the template that displays all pages by default.
 * Please note that this is the WordPress construct of pages
 * and that other 'pages' on your WordPress site may use a
 * different template.
 *
 * @link https://codex.wordpress.org/Template_Hierarchy
 *
 * @package WordPress
 * @subpackage Amplified_Antennas
 * @since 1.0
 * @version 1.0
 */

get_header();
?>
<?php
while ( have_posts() ) : the_post();
?>
<div class="contact-box1">
    <h2>Contact ENQUIRY</h2>
</div>
<?php
endwhile; // End of the loop.
?>

<?php
get_footer(); ?>

Upvotes: 1

sagar
sagar

Reputation: 590

its working fine in here its not problem with the templating i guess you have not selected the template name right side of the dashboard and only put one contact us to the page as http://amplifiedantennas.com.au/contact-us doesnt have anything assigned over there

Upvotes: 1

Related Questions