Share this page     submit to reddit   
   

Add a Category

Grouping pages into categories makes it easier for people to navigate around a web site and find the content that they're interested in.  Before you add any posts to a new web site, it's a good idea to decide how you're going to categorize them.  To add a new category to your site, go to the admin area and click on 'Add a Category'.  

Fill in the category name, and choose a slug.  The slug is a word or phrase that will be used to represent your category in URLs.  The slug will also be used as the name of a directory in the Pyplate content directory.  Apart from letters and numbers, only the following symbols can be used in the slug: - _ .

Aim to use a slug and title that contain relevant keywords, as this will make it easier for search engines to see what this category is about.

Choose a parent category.  Your new category will be created inside the parent category. Choose the slug and parent category carefully - once you've saved a category it can't be moved.

Fill in the tags field with keywords that are relevant to the category that you're creating, and fill in the description field with one or two sentences describing what this category is about. When users view a page that lists all the posts in a category, the tags will be embedded in that page as meta keywords, and the description will be used as the meta description.

Add a Page

Add new pages using the Pyplate user interface.  Go to the admin area and click on 'Add a Page' in the administration menu.

Fill in the page title, and enter a file name.  The file name is used as the name of the file where the post is stored, and it will also be used as part of the URL for the page.  There are some limitations on which characters can be used in the file name - apart from letters and numbers, only the following symbols can be used in the file name: - _  .

Choose a category for your post using the dropdown menu.  Pages can't be moved once they've been created, so make sure you don't forget to select a category before you save your new page.  

Write your post in the main text area with the toolbar.  You can use the toolbar to format your post and embed images in it.  

Search engines examine individual pages on web sites and try to determine what each page is about.  They usually do this by analysing the text on a page looking for keywords, and by examining any links on your page.  Search engines also look at invisible fields embedded in web pages.  These fields are contained in HTML meta tags in a page's head section like this:

<meta name="keywords" content="relevant,tags,go,here">
<meta name="description" content="The description of your page goes here">

Fill in the tags field using keywords that are relevant to the post you've written.  The tags are embedded in the head section as meta tags when a page is served.  Google has stopped using meta tags because spammers misused them, but some search engines do still pay attention to the meta tags in a page.

Search engines often use a page's meta description to see what kind of content is on the page. Type a sentence or two about what the page is about.  Make sure to use any relevant keywords in the meta description.  Note that meta descriptions are also used in the RSS feed of your site.

Edit Templates and Layouts

Pyplate uses HTML templates to fill in parts of each web page.  These templates are snippets of HTML stored in the template directory (by default this is in /usr/share/pyplate/templates), and they're used to fill in the page banner, and footer.  You can edit these templates by going to your site's Admin area and clicking on 'Site Settings'.  

The head section

There is a template file that gets embedded in the head section of each page.  This can contain things like meta data, links to CSS files, and Javascript code.  If you want to use Google Analytics to track the number of visitors on your site, you need to paste your Google tracking code in the head section.

The Banner and Footer Templates

The banner needs to contain an HTML div with a class attribute "banner".  Inside the div, you can add a title wrapped in h1 tags, followed by a subtitle for your site wrapped in h2 tags.  If you want you can go further than this and have several divs inside the banner.  In this site, I've used the banner div to contain one div for the left side of the banner, and another div for the contents of the right side of the banner.  

The footer field can be used to create a page footer.  This field needs to contain an HTML div with the class attribute "footer".  Again this can contain more than one div if you wish.

The Navigation Bar

By default, the navigation bar is generated by Pyplate.  When Pyplate generates this part of the page, it accesses the database to get a list of all the top level categories in your site 

(categories whose parent is the root category), and prints links to those categories as an unordered list as follows:

<div class="navbar">
 <ul class="navmenu">
  <li><a href="/">Home</a></li>
  <li><a href="/overview/">Overview</a></li>
  <li><a href="/how-to/">How-To</a></li>
 </ul>
</div>

Sometimes you might want to use a handwritten navigation bar.  Using code in Pyplate to generate the navigation bar every time a page is served uses up quite a lot of CPU cycles.  It's faster to use a template file instead.  Another reason to use a template is that you might want to customize the navigation bar.  For example, if I wanted to include a link to another site in my navigation bar, I would just add another li tag containing a link like this:

<div class="navbar">
 <ul class="navmenu">
  <li><a href="/">Home</a></li>
  <li><a href="/overview/">Overview</a></li>
  <li><a href="/how-to/">How-To</a></li>
  <li><a href="http://some-other-site.com/">Some other site</a></li>
 </ul>
</div>

This code needs to be pasted into the navigation bar field on the Site Settings page.  The code in layouts.py needs to be modified so that Pyplate uses the navigation bar template instead of generating the navigation bar from the database.  On the Site Settings page, scroll down to the Layout field.  Scroll down until you see a function called getLayout, and look for the following line of code:

navbar=pyplate.get_navbar(dbase),

Comment out this line by putting a '#' symbol in front of it.  Add the following code:

navbar=pyplate.getFile(pyplate.getCMSRoot()+"/template/navbar.html"),

Don't forget the comma at the end of this line.  You need to make this change anywhere that you see a call to pyplate.get_navbar in getLayouts.

Manage Backups

It's important to do backups of your site every time you update it.  If you're planning on modifying your site's templates or CSS files, it's a good idea to back up your site before you start.  

When a Pyplate site is backed up, it gets packed into a .tar.gz file.  The name of the file includes the date the backup was made in the following format:

backup_YYYY.MM.DD.HHmmss.tar.gz

Pyplate's backup page

Backups include everything in the site - content, scripts, the database, templates and the contents of the web root directory including cached pages.  

The Site backup page has a button that can be used to do a backup, and beneath that there is a table that lists all the previous backups.  These backups can be downloaded, deleted or restored.

Restoring a backup will unpack one of the archived backup files.  This will overwrite your existing website, so any changes that you made to your site since the backup was made will be lost.

Set daily backups

You can set daily backups by editing the webserver's crontab file.  In a terminal type this command:

sudo crontab -e -u www-data

This opens the crontab file for user www-data (the webserver's default user name) in a text editor.  If you want to run a backup once a day, add this line at the end of the file:

@daily /usr/share/pyplate/content/admin/backup.cgi

If you prefer weekly backups, use @weekly instead of @daily.

Add comments to your site

Comments increase engagement with your audience.  They allow people to ask questions and make suggestions, and they give users a reason to stay on your site for longer.  Pyplate doesn't have support for comments built-in, but you can add a comments plug-in.

There are companies that provide comments solutions which store comments in their database, and use a Javascript plugin to display them on your site.  Disqus have a popular comments plugin which I use on my Raspberry Pi site.  

Install Disqus comments

Create an account on Disqus.com, where you will be given a few lines of HTML code that you can add to your web site.  This code needs to be added to the comments template on the Comments and Sharing page in the admin area.  

On Disqus.com, click on the link that says 'For websites', and then click on the button to 'Add Disqus to Your Site'.  Create an account and fill in the form.  When you're done, you should be presented with a piece of code that you can copy.  Go to the Comments and Sharing page in the admin area, and paste the code in the template:

Make sure the Enable Comments box is checked, and click the save button.

In /usr/lib/cgi-bin/pyplate.py, look for a function called getPost, and uncomment the line near the end that creates a permalink to this page:

post_str += "<br><a href=\"{0}\">Comments</a>".format(post)

A popular alternative is Facebook's comments plugin.  If you use Facebook comments, you need to add two pieces of code.  The first one can be placed in the banner section on the site settings page.  The second piece needs to be placed in the comment template.

If you're using page caching, you'll need to clear or rebuild the cache in order to see any changes on your site.

Add sharing buttons to your site

Add sharing buttons to your site's templateSharing buttons make it easy for people to share links to your site on social networks.  This is a great way to increase the number of visitors that your site gets from social networking sites.

Sites like AddThis or ShareThis can be used to generate a few lines of HTML amd Javascript code that can be embedded in a web page to display sharing buttons.  When people view your site in a browser, the buttons will be loaded from another site and embedded in your page.

Get the code

Create an account on addthis.com or sharethis.com, and look for a button that says 'Get the code'.  You need to set some basic options so that the code will be generated to suit your needs.  First, you need to choose the type of site - choose 'Button for website' or 'basic HTML'.  Next you need to choose the style and format of your buttons.

With ShareThis you'll be given two pieces of code.  The first one needs to be placed in the head section on the Site Settings page in the Pyplate admin area.  The second one needs to be saved in the sharing template on the Comments and Sharing page.  AddThis provide one piece of code which needs to be saved in the sharing template.

Individual social networks provide their own buttons:

Getting each button individually means you have more control over the way they are displayed.

If you're using page caching, you'll need to clear or rebuild the cache in order to see any changes on your site.

Manage the page cache

Pages can be created dynamically when they are requested, but it's more efficient to generate pages once and store them so that they can be used over and over again.  Cached pages can be served much more quickly than dynamic pages, so caching significantly reduces page load times.  

When Pyplate is installed, the cache is empty.  You can cache the pages in your site by clicking on 'Page Cache' in the Administration menu, and clicking on the button to 'Build the entire cache'.

Cached pages are static, meaning that they don't change once they've been created.  The downside of page caching is that it means pages can be out of date.  If you change your site's templates or CSS code, changes won't be visible until cached pages have been cleared.  Once the cache is cleared, the cache should be rebuilt again in order to carry on serving pages quickly and efficiently.

If you add a page or change a page title, you'll need to rebuild the page cache so that the new title shows up in site navigation.  Instead of caching the entire site, pages in a specific category and its subcategories can be recached.   

There are buttons to update cached versions of the sitemap file and the RSS feed, and a button to update a cached copy of the sidebar.  Pyplate updates these files automatically when you make changes to your site, so it's unlikely that you'll need to use these buttons often.  Sometimes if you make changes to template files you may need to recache the sidebar.  If you rebuild the entire cache, the sidebar and the XML files will be updated automatically.  

If you want to edit your site's templates or themes, it's important to empty the cache first, otherwise you won't see the changes you've made, you'll just keep seeing the same cached pages.

Auto-cache pages

Rebuilding the page cache causes spikes in the load on the CPU.  While the cache is being built, page load times may increase.  For small sites, this isn't much of a problem because rebuilding the cache takes a second.  With larger sites, re-caching every page could take a long time.  

Auto-caching means new pages are cached automatically, and you don't need to rebuild the cache once you've emptied it - the cache will refill as users browse your site.  When auto-caching is turned on, pages are cached when they are requested.  When a user visits your site, if the page isn't already in the cache, Pyplate will generate the page and save it so that it can be reused later.  

Auto-caching is turned off by default.  To turn it on, open /usr/lib/cgi-bin/index.py and look for the following line:

autocache = False

Replace False with the word True (Python is case sensitive, so don't forget to use a capital 'T').  

Note that while you're working on your site's CSS and templates, it best to turn off auto-caching.  If it's turned on, pages will keep getting cached, so you won't see the changes you're making to your site.  

Add images to your site

Pyplate comes with Lightbox Javascript image viewer installed.  When you're adding a new post you can easily embed images on your site using the CKEditor toolbar, and apply the lightbox style in the Style menu.  The lightbox effect means that when visitors on your site click on an image, the image will be enlarged and pop out of the page.

Add an image

When you're editing a post, click the image button on the toolbar above the text area.

Enter the URL of the image.  If the image is stored on your server, you can use a relative path:

/some_image.jpg

If the image is on another site, you need to use its full URL:

http://some_domain.com/some_image.jpg

Set the options

Enter the width that you want to be applied to the image.  The width should be less than the size of the div that contains the image.  You don't need to set the height.  The height will be adjusted automatically so that the image's aspect ration is maintained.  Setting the alignment option to left or right makes the image float to the left or right.  Text will automatically wrap around the image.

The alternative text field is used if the image can't be displayed.  I've pasted in the attribution for the image that I used (By University of Liverpool Faculty of Health from Liverpool, United Kingdom (dogUploaded by AlbertHerring) [CC-BY-2.0], via Wikimedia Commons].  If you use images from sources like Wiki Commons, it's important to check the usage rights for that image, and give credit for it where necessary.)

If you want to use the lightbox effect, you need to create the image as a link to itself.  Click on the link tab and enter the image's URL again.  Click on the OK button on the image dialog. Click on the image in the text area to select it, and select Lightbox in the style menu on the CKEditor toolbar.

Click on the OK button on the image dialog. Click on the image in the text area to select it, and select Lightbox in the style menu on the CKEditor toolbar.

Save the post and visit the page you've just created.  The image should be embedded in it, and if you click on it, the picture will appear in a Javascript frame.

 

Import and export the database

The Import/Export page in the admin area can be used to export the database to a pair of XML files.  These files are named postindex.xml and categoryindex.xml, and they are stored in /usr/share/pyplate/database.  Once the database has been exported, you can view the XML files in a text editor.  You can edit fields in the XML files and import them into the database.  

When data is imported from the XML files, Pyplate uses the path field to identify records.  It looks at the path in each XML record, and if the database contains a record with a matching path, the record will be updated.  If the database doesn't contain a record with that path, Pyplate will create a new record using data from the XML file.  If you change a post path or category path in the XML files, Pyplate will regard these records as new entries.  The old database record won't be updated - a new record will be created.  

Creating a new database

The Build button creates a new database generated from the contents of the XML files.  

If you delete records from the XML files and then import the XML files into the database, this will not remove the records that you deleted from the XML files.  They will still be in the database.  One way to remove records from the database is to export your current database to the XML files and delete records from the XML files using a text editor.  Next, click on the Build button.  A new database will be created in /usr/share/pyplate/database/pyplate.db-YYYY.MM.dd-hhmmss.  You can replace the old database with the new one using this command in a terminal:

cd /usr/share/pyplate/database
sudo cp ./pyplate.db-2014.05.17.101903 ./pyplate.db

Note that you should always back up your site before modifying the database.  

 

Follow me