HELP: Why are get_template_part and conditional tags breaking my code?
-
I have a block of HTML that shows up in several places across my theme…
<header class="row"> <div class="headline"></div> <hr> <div class="subhead"></div> </header>
Instead of repeating myself I decided to drop my code into a file called
headline.php
and useget_template_part( 'headline' )
to call my code where I need it without being redundant.Then I add a statement to update my values according to the page being display.
Nowheadline.php
looks like so:<?php if (is_home()) { $the_post = get_post(2); $headline = $headline->post_title; $subhead = $headline->post_content; } elseif (is_single()) { $headline = the_title(); $subhead = the_content(); } elseif (is_search()) { $headline = "here is the headline for search"; $subhead = "here is the subhead for search"; } else { $headline = "here is the default headline"; $subhead = "here is the default subhead"; } ?> <header class="row"> <div class="headline"><?php echo $headline; ?></div> <hr> <div class="subhead"><?php echo $subhead; ?></div> </header>
I assumed this would work. However, when I refresh my page,
<div class="headline"></div>
and<div class="subhead"></div>
are empty.Am I missing something? Can someone tell me what I’m doing wrong?
Viewing 9 replies - 1 through 9 (of 9 total)
Viewing 9 replies - 1 through 9 (of 9 total)
- The topic ‘HELP: Why are get_template_part and conditional tags breaking my code?’ is closed to new replies.