Jump to content

SEO and creating pages with a Page class.......


tinwakr

Recommended Posts

Hi Everyone,

 

I just joined today and I am hoping to make some friends as well as obtain a lot of help as needed  ;D

 

I am starting to design a site for a friend and I am hoping to do it with pages that utilize a Page class with an instance of the class(object) on each page and then modify the necessary methods/properties as needed on each page by extending the Page class.

 

My first question is this:

If I do this, will search engines, namely Google, be able to scrape the pages and retrieve the necessary information to add the pages or must I put all the markup in each page? If I do the latter, I am creating something that will be a nightmare to update/modify as all the pages are similar if not identical except for the "main content".

 

Thanks in advance for any and all directions/suggestions.

 

Chuck

 

Link to comment
Share on other sites

You want some kind of template system. You define your static pages (like your header and footer) and then include that pages template. Something like:

 

function load_template($template, $data=array())
{
// does the template exist and is readable?
if (is_readable($template)) {
	// turn data array into variables
	extact($data);

	// fetch the template
	require $template;
}
}

 

Then your templates directory may look like:

templates/
    header.php
    footer.php
    somepage.php

 

Your header and footer files are basically the entire layout minus that specific page's content.

 

somepage.php would look like:

<?php require 'header.php'; ?>

Content goes here. We can use variables that we passed in earlier. <?php echo $foo; ?>

<?php require 'footer.php'; ?>

 

And usage:

load_template('somepage.php', array('foo' => 'bar'));

Link to comment
Share on other sites

Thanks for the quick reply scootstah!

 

The way you suggest doing this, I have done it that way before, I just thought I would do it the OOP way.

 

Including header and footer, etc., still doesn't contain the markup on each individual page so really, what would be the difference? I guess what I am trying to ask is this: Does a search engine look at a page as it is rendered by the browser no matter if the markup is contained in the page or generated by the way I am suggesting?

 

Thanks again,

Chuck

Link to comment
Share on other sites

You can use that function in OOP. Just because you use OOP doesn't mean you can't use procedural functions as well. If you want the template system to be more advanced feel free to implement an OOP solution.

 

In the end your markup is sent to the browser one way or another, and this is what Google will see. It doesn't matter if you write the entire layout on every page or section it off like this.

 

The advantage to doing it the way I suggested is that you don't duplicate code. If you have your entire layout on every single page, and then decide you want to change one little thing in the layout you have to edit every page. If you use my suggestion, you simply edit the header.php and you're done.

Link to comment
Share on other sites

By the way, if you want to do something similar to what I suggested, bear in mind that you can also pass variables to the header and footer...so you can dynamically slip in meta keywords and stuff.

load_template('somepage.php', array('keywords' => 'keyword, keyword2, keyword3'));

 

in header.php:

<meta name="keywords" content="<?php echo $keywords; ?>" />

Link to comment
Share on other sites

scootstah's way in OOP would be something like:

 

class Template {
    private $engine; // Smarty, Twig, PHPTAL, ..
    
    private $title;
    private $stylesheets;
    private $scripts;
    private $headers;
    private $variables;
    
    public function render($script, $variables = array()) {
        print $this->engine->render($script, $this->_mergeAndReturnVariables($variables));
    }
}

 

In the $script you would like to render you write:

 

<?php $this->render('header'); ?>

Content goes here. We can use variables that we passed in earlier. <?php echo $foo; ?>

<?php $this->render('footer'); ?>

 

Take this a step further and implement a Two-Step View. The idea is that you have one file that defines your header and footer and puts a placeholder for the content ("Content goes here. We can use variables that we passed in earlier. <?php echo $foo; ?>")

 

The view is rendered in two-step view: 1) the content 2) the template (header + footer). Basically the inverse of the above.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.