0

I have a menu that has the following link in it to my homepage:

<ul id="css3menu1" class="topmenu">
<li class="topmenu"><a href="<?php bloginfo('template_url'); ?>/homepage.php" target="_top" title="Home" style="height:20px;line-height:20px;">Home</a></li>

When I click on the menu link it takes to the homepage file (this url:http://elliottequineconnections.com/wp-content/themes/elliottequineconnections/homepage.php) the top of the file displays(where I have an image) but none of the php code inside the file is executed.

Code that is not executed:

<?php if (have_posts() ) : while (have_posts()) : the_post(); ?>
<div class="post" id="post-<?php the_ID(); ?>">
<h2><?php the_title(); ?></h2>
<div class="entry">
<?php the_content('<p class="serif">Read the rest of this page &raquo;</p>'); ?>
<?php wp_link_pages(array('before' => '<p><strong>Pages</strong>','after' => '</p>', 'next_cr_number' => 'number'));    ?>
</div>
</div>
<?php endwhile; endif; ?>
<?php edit_post_link('Edit this entry.','<p>','</p>'); ?>   
</div>
</div>
<?php endwhile; endif; ?>
<?php edit_post_link('Edit this entry.','<p>','</p>'); ?>

Am I linking to homepage.php in the wrong way?

2 Answers 2

1

The problem is not that the PHP doesn't execute. It does execute but you get fatal errors because you are loading your template files directly, which means they are loading without the WordPress framework that supplies necessary functions. View source of those pages and you can see error.

You should not be linking directly to that file at all, or directly to any of your template files-- for example, http://elliottequineconnections.com/wp-content/themes/elliottequineconnections/horses-for-sale.php

That is not how WordPress templating works. You should have created pages from the backend-- wp-admin->Pages-- for your content. When you edit one of those pages, you can see the permalink right under the title. That is what you need to link to. It won't look like the actual path to the file.

You can get the permalink for that pages by using get_permalink( $id ); where $id is the ID of the page, but that is going to be tedious. You can make things easier on yourself by using a custom menu. You would do that by registering a navigation menu in your theme's functions.php and then adding code to display that menu elsewhere in the theme.

Following the Codex, you would put this in function.php:

register_nav_menus( array(
    'pluginbuddy_mobile' => 'PluginBuddy Mobile Navigation Menu',
    'footer_menu' => 'My Custom Footer Menu'
) );

And then in footer.php you would place:

$defaults = array(
    'theme_location'  => 'footer_menu'
); 
wp_nav_menu( $defaults );
// and the same for the pluginbuddy_mobile menu

Untested but that is about it. You will end up with a menu on the back-end under Appearance that will let you construct your menu with a GUI.

0

Replace

<a href="<?php bloginfo('template_url'); ?>

with

<a href="<?php echo home_url(); ?>

assuming you have set your settings->reading to use [whatever page is using homepage.php as a template] as its static front page.

1
  • Hi I replaced <a href="<?php bloginfo('template_url'); ?> with <a href="<?php echo home_url(); ?> which resolved to elliottequineconnections.com/homepage.php but I get a file not found. I have set settings->reading as its static front page. I have other templates that need to be access from a menu link as well so they wouldn't be the front page. Not sure how to link to them as well and have php execute. Mar 27, 2013 at 22:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.