B2 Templates

If you have just installed B2 and are new to php, I am sure you are really confused about what to do next. Why people say B2 is so good...how do they include it in their cool layouts. It needs php knowledge? Is it really hard? Ask me, no its not hard at all, your page needs a .php extension, thats about it, rename your .html file into.php if you are still confused. The tutorial below shows you what codes you need to put where in your layout/page for the blog to show up the way you want on it.

Tutorial

» Make (code) a layout, the way you like it, like you always make cool layouts for your sites.
» Open the layout code in notepad or anything you like to use for code editting.
» Now you need to insert the codes into your layout as shown below, these are B2 tags.


REQUIRED ENTITIES

Blog Header
On the very top of page, above everything, add the following code,

<?php /* Don't remove this line, it calls the b2 function files ! */ $blog=1; include ("blog.header.php"); ?>


Change the "blog.header.php" to "b2/blog.header.php" if you installed b2 in a directory called b2.

B2 Loop
In your layout, the portion where all your B2 tags (shown below) will go, you must add this code, without the below code, most of the other B2 tags wont work!

<!-- // b2 loop start -->
<?php while($row = mysql_fetch_object($result)) { start_b2(); ?>


The Entries
In your layout, the place where you want your blog entires to show up, like the main content area, you must add the code below

<?php the_content(); ?>


See the optional entities you can show along with your blog entries, after that there is another REQUIRED entity, shown in the end.


OPTIONAL ENTITIES

Date
The place where you want the date of blogging for an entry to show up, add the code below

<?php the_date("D","M","Y"); ?>


You can change the order DMY, Obviosuly D is for date, M for month and Y is for year.

Time
The place where you want the blogging time of an entry to show up, put the code given below,

<?php the_time("h:i:a") ?>


You can again change the order, H is for hour, I is for minutes and A is for seconds.

Entry Title
The place where you want the title of the blog entry to show up, add the code below,

<?php the_title(); ?>


Category
The place where you want to show the entry category, put the code below,

<?php the_category() ?>


Author
The place where you want the name of author to show up, add the code below

<?php the_author() ?>


Comments Link
The place where you want the comments link to show up, add the code below,

<a href="<?php comments_link() ?>"><?php comments_number("comments ?", "1 comment", "% comments") ?></a> <?php include ("b2comments.php"); ?>


Change "b2comments.php" to "b2/b2comments.php" if you installed B2 in a directory named b2.

Custom Comments link
You must have seen these in many blogs where people show their comments like this:
1 loved or 3 read or 6 angels or even c3mments, c7mments etc. To get such links you need to edit the above code a little

Edit this part of the code: ("comments ?", "1 comment", "% comments")
comments ? This will appear when there are no comments, change the way you like it.
1 comment This is when there is only 1 comment.
% comments This is when there are more than 1 comments, the "%" is the number of comments.

Play around with these to get what you want.


REQUIRED ENTITY

End B2 Loop
If you dont put thise code in the end of B2 loop, your entries wont show up the way you want them to.

<!-- // this is just the end of the motor - don't touch that line either --> <?php } ?>


This line ends the B2 loop, which means all the portion between the begning of the B2 loop and the end of it, will be repeated everytime you blog, the content will be shown in the same way as you arranged the entities between these two tags (the beginning and end of B2 loop). After adding all these tags, save your page as .php upload it to see how your template looks like, play around until it looks exactly the way you want it to, good luck!


An example of how all these codes together look in the most common B2 templates, they go with almost all kind of layouts,

<!-- // b2 loop start -->
<?php while($row = mysql_fetch_object($result)) { start_b2(); ?>

<div class="head"> <?php the_title(); ?> on <?php the_date("D","M","Y"); ?> @ <?php the_time() ?> </div> <p>
<?php the_content(); ?>

</p> <div align="right"> <a href="<?php comments_link() ?>"> <?php comments_number("COMMENTS ?", "1 COMMENT", "% COMMENTS") ?> </a> <?php include ("b2comments.php"); ?></div>

<!-- // this is just the end of the motor - don't touch that line either --> <?php } ?>

The code above will generate entries like this in your layout,

Title of blog entry here on 16 Nov 2004 @ 7:45:pm
The entry content will be shown here...... The entry content will be shown here...... The entry content will be shown here...... The entry content will be shown here......
Comments ?



Note: Any questions regarding this tutorial should be asked here.


« Back