jump to navigation

BellaBuffs: Dynamic Page Titles February 20th, 2008

Posted by asadream in Writings.
Tags: , ,
1 comment so far

I love talking about BellaBuffs, don’t I? Jem loves me because of that.

This tutorial requires that you have a basic understanding of PHP includes (more specifically of using the function to include a header and footer file). It is also best if you are at least a little familiar with BellaBuffs and you should know a bit what the “if…else” function does.

What exactly will you achieve with this tutorial? I am one who likes “clean” page titles. Every page should contains the title of the site preceded (or followed, but I prefer to put it first) by the individual title of the page (for example, “Resources”, “About Us” or “How to create a butterfly in Photoshop”). Well, I will here explain you how to get such titles in BellaBuffs. I’m talking about the <title> tag here.

First, you must prepare the header.php file. If you renamed it, well, then, go ahead with whatever the file is called. The file contains a title tag. Its default content is <?php echo $title; ?> - Powered by BellaBuffs. Now, if you have taken a look into the prefs.php file, you know that $title is not a variable for individual page titles, but the variable inside which is stored your fanlisting’s title. We’ll need to change the content of this title tag.

<?php if (isset($thetitle) && !empty($thetitle)) {
echo $thetitle . ” · “;
} else { $thetitle = “”; } ?>

Okay, you might be going “huh?” at this, but I’ll explain. The first line (isset and !empty) verifies that our variable, $thetitle, actually exists in the first place, and that its value is not empty. This way, when we actually display it (the echo function on the next line), we’re not displaying nothing or getting a PHP error.

As I already said, the second line displays the actual title. “middot” is probably my favorite entity to use for that purpose. It is simply a dot standing at mid-line height. Of course, you can change this part to anything you like. You might wonder also why I separated the variable and the entity with a dot. It’s simply to “separate” the two “parts” of the echo statement: the variable and the static part. The period will not be displayed. It acts to say “oh, and echo that too, immediately after”. Don’t forget to place a space before and after whatever separator you use.

You can use any other name beside $thetitle, but avoid using just $title as, like we’ve seen above, the $title variable already exists within the script.

Now we can prepare our files. You will need to edit each file of the script, but it’s only a minor edit. There would be a way to do it only with the header.php file, but it would require a lot of if and elseif, and a lot of checks. I much prefer doing it the other way.

The key is simply to add $thetitle = "Title of the individual page"; inside each file before the header file is included.

In the contact.php file, I personally put it just before the first “if” statement—that is, before any other PHP. The page will be called “Contact” regardless of whether the form was sent or not, and of whether there was an error.

Do not define the variable inside the header.php, footer.php, functions.php or prefs.php files!

In the join.php file, I put it just after the two other variables that are declared at the start:


$show_form = true;
$error_msg = NULL;
$thetitle = “Join”;

The “fun” file, though is members.php. This file will do more than just displaying the members, it can also sort them by country. I thought it would be interesting, then, to have the title change for each country page, to reflect the fact that the content is a bit different. This will need a bit more playing around than the other pages.

Before header.php is included (before or after prefs.php is included shouldn’t matter), put the following:

if (isset($_GET['c'])) {
$thetitle = “Members: ” . $_GET['c'];
}
else {$thetitle=”Members”;}

What is $_GET['c']? If you do not know anything of the $_GET superglobal, I recommend reading information on the W3Schools website or just searching for information on it.

$_GET['c'] is used in the script to find the country. If, for example, you go to members.php?s=sortCountry&c=Canada, you will see members from Canada. This means that, in the above lines, we are doing the following steps:

  1. Check if we are viewing a single country.
  2. If yes to 1, then display Members: name of country.
  3. If no to 1, then just display Members.

You can then also change the title within the page, that is when it is shown within the <h1> element. Find these lines:

foreach ($newArray as $country) {
foreach ($countryCount as $key => $cc) {
if ($key == $country) {
echo ”

  • $country ($cc members)
  • “;
    }
    }
    }

    Just before the foreach statement is the line echo "<ul>";. Before this line, enter echo "<h1>Members</h1>";. This will show the title on the country list page.

    Beneath the foreach statement is the exit function followed by an else. Just before the foreach function that is inside this else statement, enter echo "<h1>Members: " . $_GET['c'] . “</h1>”;. This will show the word “Members” followed by the country on individual country pages. Naturally, you can change it to anything you like, such as Members from $_GET['c'].

    And voila, you got yourself nifty titles. I’m starting to feel a bit weird, so maybe the last few paragraphs are utter gibberish. If you have questions or comments, just post a comment and I’ll get back to you if I deem it appropriate.

    My Rules When I Write February 1st, 2008

    Posted by asadream in General, Writings.
    Tags: , , , ,
    4 comments

    As an entirely self-taught author, living secluded in my room most of the time, I’ve still managed to make up a few rules of my own when it comes to writing. I’ll share them with you.

    1. Sentence Length

    Keeping your sentences’ length to a good “level” is one of the first tips you should earn when you write, no matter the purpose (school, law, job applications, blogging, etc.). It is not so much excessive length or extreme briefness that can go wrong, as it is inappropriate length.

    A series of short sentences do not necessarily make action seem faster. It rather makes it appear broken into pieces, “chopped up”, which, while it can be your wish, is not always a desirable effect.

    Longer sentences with carefully chosen words can create beautiful descriptions of landscapes. “Chopped up” sentences, as I mentioned above, can create the ambiance of a confused, near-death person whose thoughts wander around a room. Let’s try describing a landscape with such sentences.

    (more…)

    Neglecting Writer January 26th, 2008

    Posted by asadream in Personal Life, Writings.
    Tags: , , , , ,
    add a comment

    I’ve been a neglecting writer since the holidays, but my dreams keep reminding me of my creative side. I make dreams that inspire new stories. However, I know it is no use to start twenty novels at a time. I can write down the idea, but I must delay the actual writing until I have something completed, else I won’t finish anything before some forty years.

    I’m suffering from pain in the upper back (on the right side only) since last Thursday. I felt it starting during my group therapy and developing during the evening. I’m not sure what has caused it, but I’ve tried having better control of which position I stand and lie in, and it feels a bit less worse than yesterday…for the back only. My neck is rather tense this morning. I guess it would help if I had a “normal” sleeping schedule.

    And Then There Were More… January 14th, 2008

    Posted by asadream in General, Personal Life, Updates, Writings.
    Tags: , ,
    add a comment

    I have added a few more poems I found in another notebook. My relationship to notebooks is quite, er, enthusiastic.

    Je voudrais (I Would Love), Le tableau (The Painting) Unwanted and Wilted Flower are now all available for your enjoyment. As per usual, they are not addressed to children; however, none of them really needs an adult content warning.

    I haven’t been posting much lately for various reasons I will keep to myself. Last week was exhausting. Well, not really. There wasn’t that much going on, but I felt constantly tired and slept a lot. I took walks on several days, but I still was tired all the time and had great difficulty falling asleep at night. That difficulty is still here, as can be seen from my posting this at 4:15 a.m.

    Eric got a cold at the end of last week. Fortunately it didn’t last very long and he is quite fine by now, just a little bit left. He has an interview for a job tomorrow. I’m quite happy because I know his chances of getting the job are rather high and, if he does get it, he will be working much closer to home. He will be gone for much less hours per day and will be back much earlier, which will be good for him and will allow me to see more of him.

    Speaking of jobs, I have an appointment next week with a girl from an organism that help people in therapy find jobs that suit them. I hope I can get to work (or rather to earning money!) soon.

    Filled With Ideas December 1st, 2007

    Posted by asadream in Personal Life, Writings.
    2 comments

    I am filled with ideas of stories to write. I was looking at a project of mine (a secret thing to do with insanity of my own) and I saw several titles that suddenly woke ideas inside my head, or revived ones I hadn’t had for a while. I’m actually even thinking of trying to turn one into a comic. Now, however, this would mean getting collaboration, something I have never done in my entire life. I can come up with a story and picture characters in my head but, when it comes to drawing, I fucking suck. I want original, publishable work here. I don’t know who could really help me…

    Eric likes to draw, but he is not too certain of his own talent and is often too busy or too tired, so I doubt he would be an appropriate choice. He has a friend who can draw very well, but I’m not acquainted with him well enough to ask for such a partnership.

    I believe…no, I’m certain the idea comes in part from my reading the Fables comics, which I heartily recommend. The plots I have in mind are quite different, but the quality of this comic has given me…shall I say hope?

    In other news, however, “real” life presents no interest to me. I barely eat, although I do still drink a lot of Pepsi and juice. I don’t care for what time I’m going to bed. It’s almost 5:30am right now and I don’t care. I’d stay up until mid-morning, where I would take a short nap before getting back to putting my ideas on paper. Well, converting them into binary code, as I mostly do it on the computer.

    I’m not really interested in seeing people, except one particular man, and, of course, Eric. I wish I could live off my creativity, but it is unfortunately impossible. Should I even be well off with my current income, there would still be so many things to do “out there”, and that doesn’t interest me at all. Why am I not the daughter of a rich artist?