Ylama
Ylama

Reputation: 2489

custom theme for wordpress new page

I created a custom theme for word-press. When i say 'add new' page and i put content into this page it only displays the footer and header but dosnt hook my content which is in the CMS on that page.

This is what i have : page.php

<?php get_header(); ?>

<div class="row">
    <div class="col-sm-12">

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

                get_template_part( 'content', get_post_format() );

            endwhile; endif; 
        ?>

    </div> <!-- /.col -->
</div> <!-- /.row -->

<?php get_footer(); ?>

Its been a long day what am i doing wrong here. Any tips please?

Would also like to make like a parent page from this new page, but its only option with page attributes are 'default template'.

Upvotes: 1

Views: 41

Answers (2)

Ylama
Ylama

Reputation: 2489

My actual problem, resolved. So i used 'advanced custom field' plugin for my WordPress. The problem using this is that it still requires you to do some coding.

I added a new page.

For that page I had an header image and content. So for ACF(advanced custom field) that is equal to two field types "Image --> field type and Text-Area --> field type"

Field name is what i used to call the fields to my .php page template.

Field Name : Image = header-image

Field Name : (2)Text Area = header-image-text-top (and) header-image-text-author

(I needed to display my text on the image thats why my div is just based on header image.)

So I hooked my page template and then added the the hooks for the fields i want to display on this page template.

page-stay.php :

  <?php 
    /*Template Name: Stay - Parent Page */  
   get_header(); ?>



<div id="primary" class="content-area">
    <main id="main" class="site-main" role="main">

    <?php
    // Start the loop.
    while ( have_posts() ) : the_post(); ?>

    <article id="post=<?php the_ID(); ?>" <?php post_class(); ?>>

       <!-- <header class="entry-header">
            <?php the_title( '<h1 class="entry-title">', '</h1>' ); ?>
        </header>(you can use this if you need your page header to display)-->

        <div class="enry-content">   
        <?php 
        $image = get_field('header-image');

            if( !empty($image) ): ?>
            <div class="head-image">
            <img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>" />
                <div class="head-text-box">
                    <div class="head-text-box-holder">
                        <p class="headtext-quote"><?php the_field('header-image-text-top'); ?></p>
                        <p class="headtext-author"><?php the_field('header-image-text-bottom'); ?></p>
                    </div>
                </div>
            </div>
        <?php endif; ?> 

  </article>

    <?php endwhile; ?>

    </main><!-- .site-main -->
</div><!-- .content-area -->

<?php get_footer(); ?>

Upvotes: 0

nibin.gv
nibin.gv

Reputation: 16

If you didn't have a template part please use the_content() instead of get_template_part( 'content', get_post_format() );

Upvotes: 0

Related Questions