Theme Overriding Help
-
Fairly new to WordPress, I am recently coming over from Drupal. I am having a trouble overriding my theme for one simple function, maybe someone can help! I am using a custom theme Five3.me, and I have made a child theme out of that that I have been editing. I have not modified any source theme files.
What I am trying to do, is create custom fields on “Posts”, so include a name and picture. this is pretty standard stuff.
First, I copied single.php into my theme directory, and changed the code to:
get_header(); ?> <?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?> <?php get_template_part( 'custom-content', 'single' ); ?> <nav id="single"> <span class="nav-previous"><?php previous_post_link( '%link', __( '← Previous', 'five3' ) ); ?></span> <span class="nav-next"><?php next_post_link( '%link', __( 'Next →', 'five3' ) ); ?></span> </nav><!-- #single --> <?php comments_template( '', true ); ?> <?php endwhile; // end of the loop. ?> <?php get_footer(); ?>
As you can see I only changed get_template_part( ‘content’, to get_template_part( ‘custom-content’,.
I then copied content.php and renamed it custom-content.php. I add this bit into the body:
<?php $membername = get_post_meta( $post->ID, 'membername', true ); echo '<div class="memberdiv">'; foreach( $membername as $member){ echo '<h3>' . $member['name'] . '</h3>'; echo '<img src="' . $member['member-picture'] . '" class="mem-pic" />'; echo '</div>'; }?>
This works, if I go to any post, I see my custom tags. But I also have a page, with a slug god-stories. This is set as my summary post page inside of reading settings.
Now I am trying to get the same meta to show up on this post reel page. What I did was make a custom template for the page with this code:
<?php /** * Template Name: Custom Page Template * * */ get_header(); ?> <?php the_post(); ?> <?php get_template_part( 'custom-content', 'page' ); ?> <?php comments_template( '', true ); ?> <?php get_footer(); ?>
I open up the god-stories page and I select “Custom Page Template” and save it, and nothing happens. Through troubleshooting, I find that this page is still using content.php from the parent theme directory. If I change the main theme my changed show up… but then they are applied to all pages, which doesn’t work.
First, what am I doing wrong? Second, is there a better way for me to get custom fields to show up not only on every post but also on one page in my child theme? I tried if statements but unfortunately my PHP is not that strong.
- The topic ‘Theme Overriding Help’ is closed to new replies.