1

I am new to WordPress development (the most I've ever done on the web design/development side of things is creating basic HTML sites); so this may be an extremely simple question, but I am trying to create a multi-page site.

I want 3 static pages, a Homepage, About page and Portfolio page and a Blog which is populated using the WordPress backend. Initially, I was going to just put the blog on a separate sub-domain (e.g. blog.example.com), however, I wish to populate a list on all the pages with a list of recent posts so I wish to keep all of them on the same domain.

However, I'm not sure how to link the pages together, if I put index.php, about.php, portfolio.php and blog.php in the theme folder; the index.php shows as expected, however, if I create the links as follows, it doesn't work (all the hrefs are blank strings):

<ul class="nav">
   <li><center><a id="nav_bar" href="<?php get_home_template() ?>">Home</a></center></li>
   <li><center><a id="nav_bar" href="<?php get_query_template('about') ?>">About</a></center></li>
   <li><center><a id="nav_bar" href="<?php get_query_template('portfolio') ?>">Portfolio</a></center></li>
   <li><center><a id="nav_bar" href="<?php get_query_template('blog') ?>">Blog</a></center></li>
</ul>

And if I direct the links to the wp-content folder, using the following syntax:

<a id="nav_bar" href="<?php bloginfo('template_url') ?>/about.php">About</a>

The link is rendered properly, it points to the PHP files in the wp-content folder, but when navigating to that page, it cannot call the WordPress functions (i.e. get_header() cannot be found).

What is the best way to achieve what I want to do?

  • Though, you have put these files in theme folder, are these theme templates or just general php file? – WisdmLabs Sep 9 '14 at 18:23
  • @WisdmLabs Sorry, I'm not actually entirely sure; how would I determine the difference? They are PHP files which generate the design of the page using the header.php, footer.php etc. – Thomas Russell Sep 9 '14 at 18:26
  • @Shaktal If your question has been answered, could you please accept the solution. Thanks. – Michael Ecklund Jan 4 '17 at 20:21
1

You need to learn how the WordPress template hierarchy works.

It is very important for any individual who wants to learn WordPress or take their current WordPress experience to the next level to know of and understand all of the different aspects of the WordPress Template Hierarchy.

If you plan on consolidating, or organizing the content on your WordPress website, it is essential to understand how your WordPress website handles the requests made from each of the visitors who arrive on and navigate through your WordPress website.

Here's a list of links which you should read from top to bottom:

  1. Theme Development
  2. Template Hierarchy
  3. Child Themes
  4. Conditional Tags
  5. Stepping into Templates
  6. The Loop in Action

Now for my .02 in regards to your particular situation...

Create your static paces in the WordPress Backend Administation area (domain.com/wp-admin/). Give them a title, modify the "slug" if desired to change the URL of the page, and insert some content.

Read through the links posted earlier in my answer. Then come back to here.

Make a file page.php and put it in ./wp-content/themes/<your-theme/ directory. This will be your default template for all "static pages" on your website.

Now, if you wanted different functionality or layout for a specific page, you have a couple of options.

Option #1) Create individual files for each different page. You can do this by making a file called page-<your-page-slug>.php or page-<your-page-ID>.php.

Option #2) Use conditional tags for each different page, within your page.php file.

Example:

if(is_page('about')){// Page with slug of "about".

    // do stuff

} elseif(is_page(28)){// Page with ID of "28".

    // do stuff

} elseif(is_front_page()){// Home page of your website.

    // do stuff

} else{// Any other page.

    // do stuff

}

Now, if you're going to be more or less hard coding your links in your layout... Consider using site_url();.

Example: <a href="<?php echo site_url('/about/'); ?>">About</a>

You could do it using the actual page information.

$page = get_post(28);
if($page){
    echo '<a href="'.get_permalink($page->ID).'">'.$page->post_title.'</a>'.PHP_EOL;
}

Now if you really wanted to get fancy... You could use global variables. Globalling the current post object (a/k/a current page).

if(is_page('about')){// Page with slug of "about".

    global $post;

    echo '<h1><a href="'.get_permalink($post->ID).'">'.$post->post_title.'</a></h1>'.PHP_EOL;

} 

It should also be noted that when setting up your "blog section" of your site that you should check out the reading settings in the WordPress backend administation section. WP Admin -> Settings -> Reading

Set your front page and a page for posts. The page for posts is where your blog will be located. index.php is the default template file for your blog posts. You can setup different templates for each area of your blog. home.php would be your default template file for the "main blog page", category.php would be all your blog posts which have an assigned category to the post. tag.php would be all your blog posts which have an assigned tag to the post. etc...

I cannot go too in-depth on this topic, as for there is just simply way too much information to cover in one answer. This is all explained in the above links earlier in my answer. I can assure you, that if you read and understand those links, you will be well on your way to a solution.

0

See, if your files are just simple php files (not hooked in WordPress by any way), the WordPress functions will not be accessible in those files. If you want to create different pages with different structure/layout, you should first create templates into your theme/child theme, add new pages from admin dashboard and then assign them the template that you created -

1) Create a template -http://codex.wordpress.org/Page_Templates

2) Add a new page from admin dashboard - http://codex.wordpress.org/Pages_Add_New_Screen

3) When adding the page, select the template among those that you created. You will be able to identify them by their name.

If you have added get_header(), get_footer() into your PHP files, that means you have tried to create nothing but the templates only, but it seems they are not loaded as template properly. Refer Template creation link for more details. Please note: do not forget to give 'Template name' when creating a template. You can even refer any existing template into your theme and just copy paste it, rename file name as well as template name, customize layout as you want and assign to any WordPress page.

Also, when pages are ready, you can simply add theme to navigation menu from the dashboard itself http://codex.wordpress.org/WordPress_Menu_User_Guide

If you don't want to create any new template and use existing in the theme, you can use them straight away by assigning them to pages in admin dashboard.

protected by Community Nov 2 '15 at 20:13

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

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