Sunday, February 27th, 2005

Changing Wordpress Styles to Themes

The new version of Wordpress has many improvements including the new Themes structure. You can completely customize the appearence of your blog including the templates and switch between them with a click.

But the new theme structure doesn’t work with the old styles. To change an “style” to a theme, upload the style folder into the theme directory and open the style.css in a text editor. Insert the following template at the top and fill in the information.

/*
Theme Name: Rose
Theme URI: the-theme's-homepage
Description: a-brief-description
Author: your-name
Author URI: your-URI
Template: classic
Version: a-number--optional
.
General comments/License Statement if any.
.
*/


The important part is telling it to use the classic templates. Go to “Presentation” and select your theme and you back to normal.

A theme switcher is also available. Just drop it in the plugins directory and activate. Put <?php wp_theme_switcher()?> wherever you want the list to show up and you’re done.

Laura in Tutorials § No Comments

Sunday, March 28th, 2004

Automagically backing up your website with OS X

I cobbled this together from several different sources, most notably the help desk from my server and an article from Mac OSX Hints.

The first thing you need is to be able to access your server space via ssh. You might need to contact your server help desk to get shell access.

Logging in

  1. open up Terminal.app (Applications/Utilities/…)
  2. run the command ’ssh-keygen -t rsa’
  3. You will be asked what file you want to save the key in, press return to accept the default.
  4. You will be asked for a passphrase. Hit return twice to have no passphrase.
  5. type ‘cd .ssh’ to enter the root ssh directory.
  6. type ‘cat id_rsa.pub >> authorized_keys2′ to add your public key to the list of authorized keys.
  7. type ‘chmod 600 id_rsa’ to change the permissions on that file.
  8. type ‘cd ..’ to return to your home directory
  9. type ’scp -r .ssh user@yourdomainname.com:~/’ to copy the ssh keys you just created to the webserver.
  10. ssh into the .ssh folder on the server and chmod 300 authorized_keys2.
  11. test it out by running ’ssh user@yourdomainname.com’, you should now be able to log in there without being prompted for a password.

Multiple computers

If you want to set multiple computers to login to your account, download the .ssh folder from your server to the second computer. Delete the two rsa files and follow the instructions above until the one that begins “type ’scp…”. Instead, type ’scp .ssh/authorized_keys2 user@yourdomainname.com:~/.ssh/’.

Backup Script

The next thing is scripts to login to your server space and backup your files to your computer. The first file backs up your files in a compressed file format for easy downloading.

#!/bin/sh
mysqldump -h databaseURL.mydomain.com -u user -ppassword database_name> /home/user/backup.sql
rm archive.tar.gz backup.sql.gz
tar cvf archive.tar home/user/images home/user/public
gzip archive.tar backup.sql

Create a new file in TextEdit and copy the above code into it. Save it as archive.sh. Replace url of the database, the username and password, the database name and the path to your root directory on the server in the mysqldump line. The rm line deletes the files already on the server. the tar line copies the selected files and folders into an archive. The last line compresses the tar and sql files ina gzip format. These can be uncompressed by Stuffit.

#! /bin/sh
newtime=`date +%m-%d-%y_%I%M%p`
ssh -l user mydomain.com /home/user/archive.sh
scp user@.mydomain.com:backup.sql.gz ~/Documents/Path/To/Backup Folder/backup_$newtime.sql.gz
scp user@.mydomain.com:archive.tar.gz ~/Documents/Path/To/Backup Folder/archive_$newtime.tar.gz

Again replace place-holders with your information. It will run archive.sh, download the backup files from your server to your computer and rename them with the date and time. Save this file as backup.sh.

Upload archive.sh to the root of your account and set the permissions so that it can be executed (chmod 755 backup.sh). Put the second in a Crontab folder in your Library folder and set its permissions the same way.

To test the files:

  1. open Terminal and type ‘cd Library/Crontab’
  2. type ’sh backup.sh’

You should see the list of files added to the tar archive and the progress as the two files are downloaded. The only thing left to do is create a cron job to run the backup.sh file automatically.

crontab

Back in Terminal, type ’setenv EDITOR “pico”‘. Pico is the easiest Unix editor to use. if you like another, you probably already knew all of this.

  1. Use the arrow keys to navigate to the end of the “diskutil repairPermissions” line and hit return.
  2. My cron job is 0 18 * * * /Users/user/Library/Crontab/backup.sh. Unix uses the 24 hour clock. I have it set to run at 6pm every night since I can almost always be found on my computer then. The crontab won’t run if A) you aren’t logged in or B) The computer is asleep. You can find more information on the cron settings at MacDevCenter.com.
  3. Hit ‘ctrl X’ to close the crontab and return to save the changes.

That’s it. You can now rest easier knowing that if something happens to your website you won’t lose anything.

Laura in Tutorials § No Comments

PHP Link Identifier

I wanted a php script that identified which page in the navigation bar the user was on when the navigation was added using ssi on multiple pages. I found examples in ASP, Cold Fusion, and Server-Side Includes but no PHP. (I found one later that didn’t quite work the way I wanted it to. It uses an array with the names of all of the files and I wanted the page to self-identify so I didn’t have to do upkeep.)

I managed to figure out some code, using the examples as pointers and looking through the functions on the main PHP site. All you have to do is put (or include) the following in the head of all of you pages you’ll include the navigation on.

<?php
//get the file path of the current webpage as a variable
$path = $_SERVER['DOCUMENT_ROOT'];
// the variable $file is set to “index.php”, etc.
$file = basename ($path);
  ?>

Then, format the links in your navigation bar as if…else statments.


<ul>
<?php if($file == "index.html"){print '<li class="on">';}else { print '<li>';}?><a href="index.html" class="on">Home</a></li>

<li><a href=”http://www.someothersite.com” >An External Link</a></li>

<?php if($file == “thisfile.html”){print ‘<li class=”on”>’;}else { print ‘<li>’;}?><a href=”thisfile.html”>This File</a></li>

<?php if($file == “thatfile.html”){print ‘<li class=”on”>’;}else { print ‘<li>’;}?><a href=”thatfile.html”>That File</a></li>

<?php if($file == “theotherfile.html”){print ‘<li class=”on”>’;}else { print ‘<li>’;}?><a href=”theotherfile.html”>The Other File</a></li>
</ul>

Don’t worry about mixing links you want checked and the you don’t, the code around each link is self-contained so it just skips over links that aren’t coded. Basically, it says “If the variable $file is the same as this link’s file-name, write a list-item with a class of “on”, otherwise, just write a list-item.

If the page is in the list, the link to it gets highlighted, if not, it’s skipped.

Laura in Tutorials § No Comments

Tuesday, June 17th, 2003

RSS

New tutorial up- RSS.

laura in Tutorials § Comments Off

Monday, May 5th, 2003

Content and Knowledge Management Systems. Huh?

I’ve added a new tutorial to The Creative Librarian called “Content and Knowledge Management Systems. Huh?” It discusses CMSs and gives directions to a few of them. Link is in my tutorials section.

laura in Tutorials § Comments Off

Thursday, December 19th, 2002

Simple Webpage Creation

Introduction

The basis of webpages is html (hypertext markup language). Html is a markup language, which means that it identifies certain elements in a document. It works the same as MARC records. MARC records can be imported into any catalog capable of interpreting the coding, and html documents can be displayed by any browser that knows the language.

Html has evolved over the years, as web users needed more from it. The current standard for html is Xhtml (Extensible HyperText Markup Language). Xhtml is a child of html and XML (Extensible Markup Language ) that is acting as a bridge between the two. It uses the same elements as html 4.0 (the last revision) but with stricter rules required by XML. Since Xhtml (strict) is the current standard, that’s the one I’ll be using for this lecture.

Part of the stricter standards required in Xhtml is the “separation of style from content.” This is a recurring refrain because it is the most important point. When the World Wide Web became so popular so quickly, pieces of code (tags- both standard and proprietary to certain browsers) were added to html to allow designers to make their webpages more attractive and complex. (See In the Beginning…)But markup languages aren’t supposed to have anything to do with how things look, they are used to give structure. It’s like painting each individual board before you build your house. It looks nice when you’re finished but redecorating is a pain and paint gets into places it’s not supposed to be, messing the structure up. Most of the tags that were added are now being withdrawn from the standard and future browsers won’t support them anymore.


This is where Cascading Style Sheets come in. The information can be marked up in Xhtml, and then the design can be applied using style sheets. The result is html that is much easier to read and a website that is far easier to change. It is also easier, I’m told, for a Xhtml/CSS site to comply with the federal regulations for accessibility for people with disabilities.

Laura in Tutorials § No Comments

map1 map2 map3 map4 map5 map6 map7 map8 map9 map10 map11 map12 map13 map14 map15 map16 map17 map18 map19 map20 map21 map22 map23 map24 map25 map26 map27 map28 map29 map30 map31 map32 map33 map34 map35 map36 map37 map38 map39 map40 map41 map42 map43 map44 map45 map46 map47 map48 map49 map50 map51 map52 map53 map54 map55 map56 map57 map58 map59 map60 map61 map62 map63 map64 map65 map66 map67 map68 map69 map70 map71 map72 map73 map74 map75 map76 map77 map78 map79 map80 map81 map82 map83 map84 map85 map86 map87 map88 map89 map90 map91 map92 map93 map94 map95 map96 map97 map98 map99 map1 map2 map3 map4 map5 map6 map7 map8 map9 map10 map11 map12 map13 map14 map15 map16 map17 map18 map19 map20 map21 map22 map23 map24 map25 map26 map27 map28 map29 map30 map31 map32 map33 map34 map35 map36 map37 map38 map39 map40 map41 map42 map43 map44 map45 map46 map47 map48 map49 map50 map51 map52 map53 map54 map55 map56 map57 map58 map59 map60 map61 map62 map63 map64 map65 map66 map67 map68 map69 map70 map71 map72 map73 map74 map75 map76 map77 map78 map79 map80 map81 map82 map83 map84 map85 map86 map87 map88 map89 map90 map91 map92 map93 map94 map95 map96 map97 map98 map99 map100