• I’ve hacked away at my template (Revolution News Magazine) for an online magazine I’m building to create a double column feature area (www.kenalu.com). The only easy way I could think of to do that was to build the double column into the header. Took a lot of fiddling, but I made it work. But now that double column appears in the pages as well, and I don’t want that.

    It seems like the easiest way would be either to create a conditional statement that calls the extra code only if it’s on the home page, or to call alternative headers on every page but the home page. Both would work well for me, I don’t need the other stuff that goes along with this expanded content section (a video and rss email subscription) so whacking it away to the simple original header would be fine.

    Only problem is I don’t know where the function get_header() lives so I can modify it to call alternate header files or how to make the header detect that it’s on the home page.

    Any help would be greatly appreciated. I dont’ really know php or css, I’m just faking it, learning as I go.

Viewing 15 replies - 1 through 15 (of 16 total)
  • Two ways to ‘modify’ get_header() are to 1. use the internal function it relies on:

    load_template( TEMPLATEPATH . '/custom-header-name.php' )

    or 2. just use PHP’s include() function.

    (TEMPLATEPATH is a WP constant that defines the path to the current theme directory.)

    Detect if on the home page:
    http://codex.ww.wp.xz.cn/Conditional_tags#The_Main_Page

    Thanks, I think you’ve put me on a better path. I probably should learn PHP more before I try to do this stuff, but I guess I’m learning by doing.
    Actually, while I was hoping for a response I found and tried to use a conditional with if (is_home()) like this:

    <?php
    if (is_home()) {
    <div id=”bigfeat”>
    <div class=”bigfeatleft”>
    <div class=”featured3″>
    <?php $recent = new WP_Query(“cat=26&showposts=1”); while($recent->have_posts()) : $recent->the_post();?>
    <h2>” rel=”bookmark”><?php the_title(); ?></h2>
    <?php the_content(__(‘Read the story »’));?><div style=”clear:both;”></div>
    <?php endwhile; ?>
    </div>
    </div>
    <div class=”bigfeatright”>
    <div class=”video”>
    <h2>Featured Video</h2>
    <object width=”425″ height=”355″><param name=”movie” value=”http://www.youtube.com/v/EfLXV5Iekxc&rel=1″></param><param name=”wmode” value=”transparent”></param><embed src=”http://www.youtube.com/v/EfLXV5Iekxc&rel=1&#8243; type=”application/x-shockwave-flash” wmode=”transparent” width=”300″ height=”216″></embed></object>
    </div>
    <div class=”newsletter”>
    <h2>eNews & Updates</h2>
    <p>Sign up to receive the latest breaking news, as well as all of your other favorite headlines!</p><form id=”searchform2″ action=”http://www.feedburner.com/fb/a/emailverify&#8221; method=”post” target=”popupwindow” onsubmit=”window.open(‘http://www.feedburner.com&#8217;, ‘popupwindow’, ‘scrollbars=yes,width=550,height=520’);return true”><p><input type=”text” value=”Enter your email address…” id=”s2″ onfocus=”if (this.value == ‘Enter your email address…’) {this.value = ”;}” onblur=”if (this.value == ”) {this.value = ‘Enter your email address…’;}” name=”email”/><input type=”hidden” value=”http://feeds.feedburner.com/~e?ffid=1396718&#8243; name=”url”/><input type=”hidden” value=”eNews Subscribe” name=”title”/><input type=”submit” value=”GO” id=”sbutt2″ /></p></form>
    </div>
    </div>
    </div> }
    ?>

    But that gave me a syntax error:

    Parse error: parse error, unexpected ‘<‘ in /home/content/p/e/y/peyotebill/html/kenalu/wp-content/themes/revolution-magazine/header.php on line 318

    So I looked at some other examples and realized that the HTML statements inside php code generally have echo statements. So I surrounded all the HTML with Echo’s, and got pretty much the same errors. I know you didn’t sign up to teach newbies PHP, but do you have any suggestions?

    Hard to say since you didn’t wrap your code in backticks before pasting it, but it looks like the only problem is that you didn’t close your php tag. At the beginning of your code, find this:

    <?php
    if (is_home()) {
    <div id="bigfeat">

    and change it to

    <?php
    if (is_home()) {
    ?>
    <div id="bigfeat">

    Really? I would thing the statement would have to be inside the PHP tag to execute.

    <div> is html, not PHP, so sending it to the PHP processor causes a parse error.

    I pretty much suspected that, I thought that was why you wrap them in echo statements like:

    <?php
    if (is_home()) {
    echo ‘<div id=”bigfeat”>’;

    I’ll try your suggestion though.

    That’s also an option, but you didn’t use echo statements either in your original code.

    PHP 101…

    This:

    <?php if (is_home()) { ?>
    <div id="bigfeat">
    <?php } ?>

    Is much the same as:

    <?php
    if (is_home()) {
    echo '<div id="bigfeat">';
    } ?>

    For the PHP interpreter, anything that falls within the if statement (i.e. between ‘{‘ and ‘}’) is processed. But since it lies outside the <php ?> tags, the interpreter assumes it’s just output.

    Tried the change you suggested, got: Parse error: parse error, unexpected $ in /home/content/p/e/y/peyotebill/html/kenalu/wp-content/themes/revolution-magazine/header.php on line 91

    There are only 90 lines in header.php so I assume it’s looking at the next line of home.php after the function is called, no idea where it’s finding a ‘$’

    Paste up your header.php template here

    http://wordpress.pastebin.com/

    And link back with the url provided for it.

    Hey, it works, how cool is that. Somehow my formatting got hosed a little, but I’ll find that problem.

    I hadn’t enclosed the final curly bracket in a PHP statement as:
    <?php } ?>

    Thanks so much for putting up with my 101 question.

    One last question. why would one elect to use the
    echo ‘<div id=”bigfeat”>’; approach? It seems to be the common way to stuff html inside php

    Oh, and is there a book you recommend. I’m reading a number of online PHP and CSS references, but most seem to talk only about syntax. I dug into the W3C tutorials a lot before I asked the question and looked at a lot of sample code in the WordPress documentation. Didn’t really get close.

    The W3C examples seem particularly unhelpful and kind of ugly.

    Here’s the pastebin url
    http://wordpress.pastebin.com/m40b03b6e

    why would one elect to use the echo ‘<div id=”bigfeat”>’; approach?

    In most cases it’s up to the inidividual coder, though of course how the code is implemented can sometimes dictate the need.

    Around here we tend to minimalize the use of echo or printf or whatnot, to keep the code portions as readable as possible to anyone not so well versed in PHP or programming in general. We don’t support a blogging tool meant only for programmers. ;)

    Sorry, can’t recommend a good tutorial book or online ref. I think the last ‘learning’ text I picked up was for Perl 4. :p

    I’m sure others here can recommend a few.

    Digging through the WordPress Lessons can provide you tidbits from a WordPress perspective:

    http://codex.ww.wp.xz.cn/WordPress_Lessons

    Perhaps it’s time for a “PHP for the WordPress user” doc…

Viewing 15 replies - 1 through 15 (of 16 total)

The topic ‘Alternate Headers’ is closed to new replies.