Strangely enough, the sticky footer examples which I've seen for Twitter Bootstrap 3 seem to ignore the fact that there is now a class which takes all the pain away. It's called 'navbar-fixed-bottom', and it is usually used to create a bottom up navigation bar. However, if you add it to your footer code, it works better than any other sticky footer examples. Here's how it works:
Create a footer thus:
<footer class="navbar-default navbar-fixed-bottom">
<div class="container">
<p>Hello world!</p>
</div>
</footer>
Then style it using CSS thus:
footer.navbar-default.navbar-fixed-bottom
{
background:red;
color:white;
padding:1em 0;
}
footer.navbar-default.navbar-fixed-bottom p
{
margin:0;
}
Easy! Sticky footers all the way for me now. They're really useful for mobile web apps.
Monday, 27 January 2014
Thursday, 19 December 2013
Quick overview of humans.txt for SEO
humans.txt is a TXT file that contains information about the different people who have contributed to building the website. Click here to access an example from humans.txt. The file is picked up by search engines.
Add a humans.txt to your site and reference it using the tag
<link type="text/plain" rel="author" href="humans.txt" />
Add a humans.txt to your site and reference it using the tag
<link type="text/plain" rel="author" href="humans.txt" />
Labels:
humans.txt,
SEO
Wednesday, 11 December 2013
Dynamic progress bar for Twitter Bootstrap using PHP
Twitter Bootstrap offers some very useful progress bars. See http://getbootstrap.com/components/#progress
They are based on percentages, so you need to get the length of the shaded bar as a percentage of the whole bar for them to be accurate.
Below is a small example of how to do this with PHP.
<?php
$currentVal = 10;
$maxVal = 20;
$percentageVal = ($currentVal/$maxVal)*100;
?>
<div class="progress">
<div class="progress-bar" role="progressbar" aria-valuenow="<?php echo $currentVal ?>" aria-valuemin="0" aria-valuemax="<?php echo $maxVal ?>" style="width:<?php echo $percentageVal ?>%;">
<span class="sr-only"><?php echo $percentageVal ?> Complete</span>
</div>
</div>
They are based on percentages, so you need to get the length of the shaded bar as a percentage of the whole bar for them to be accurate.
Below is a small example of how to do this with PHP.
<?php
$currentVal = 10;
$maxVal = 20;
$percentageVal = ($currentVal/$maxVal)*100;
?>
<div class="progress">
<div class="progress-bar" role="progressbar" aria-valuenow="<?php echo $currentVal ?>" aria-valuemin="0" aria-valuemax="<?php echo $maxVal ?>" style="width:<?php echo $percentageVal ?>%;">
<span class="sr-only"><?php echo $percentageVal ?> Complete</span>
</div>
</div>
Labels:
bootstrap,
percentage,
PHP,
progress bar,
twitter
Recursive delete for blogs and forums
Let's say, you've developed a blog or forum and you need to delete some entries. You will also want to delete the responses to those entries. In this example we'll use a table structure like this, where 'refid' is a field used to associate a response with it's referer :
`id`
`refid`
`userid`
`title`
`content`
`tags`
`created`
In our PHP we want to go through each blog entry which we'd like to delete and ascertain it's responses identified by 'refid' before deleting it. Thus :
function deleterecursiveblog($id)
{
$q = "SELECT * FROM `blog` WHERE `refid`='{$id}'";
$result = mysqli_query($con,$q);
if(isset($result))
{
foreach($result as $key)
{
deleterecursiveblog($key['id']);
}
}
$q = "DELETE FROM `blog` WHERE `id`='{$id}'";
$result = mysqli_query($con,$q);
}
`id`
`refid`
`userid`
`title`
`content`
`tags`
`created`
In our PHP we want to go through each blog entry which we'd like to delete and ascertain it's responses identified by 'refid' before deleting it. Thus :
function deleterecursiveblog($id)
{
$q = "SELECT * FROM `blog` WHERE `refid`='{$id}'";
$result = mysqli_query($con,$q);
if(isset($result))
{
foreach($result as $key)
{
deleterecursiveblog($key['id']);
}
}
$q = "DELETE FROM `blog` WHERE `id`='{$id}'";
$result = mysqli_query($con,$q);
}
Friday, 6 December 2013
Bash techniques
I've been doing a lot of work in bash lately. I've been speeding up the time taken to create the website basics. Right now I can create a Twitter Bootstrap/Modernizr website with blogs etc within a couple of seconds by calling my bash script. So, below are some techniques I've learned along the way:
Prep-end all slashes in a web address with backslashes
webdir=`echo $webdir | sed s,/,\\\\\\\\\\/,g`
Get the last substring from a string separated by slashes
dbn=${longstring##*/}
Put the contents of a .sql into a database
mysql -u root -p password $dbn < $workingdir"/users.sql"
Change a line within a .ini file
sed -i -e '/DB_NAME =/ s/= .*/= '$dbn'/' config.ini
Hope they help!
Prep-end all slashes in a web address with backslashes
webdir=`echo $webdir | sed s,/,\\\\\\\\\\/,g`
Get the last substring from a string separated by slashes
dbn=${longstring##*/}
Put the contents of a .sql into a database
mysql -u root -p password $dbn < $workingdir"/users.sql"
Change a line within a .ini file
sed -i -e '/DB_NAME =/ s/= .*/= '$dbn'/' config.ini
Hope they help!
Labels:
bash
Thursday, 28 November 2013
Error reporting in PHP
I've seen quite a few blogs which go into great depth about error reporting in PHP. What I and almost everyone else wants when something is going wrong is... Tell me everything. So, here are the lines to put at the top of your .php file
<?php
ini_set('display_errors',1);
ini_set('display_startup_errors',1);
error_reporting(-1);
?>
Job done.
<?php
ini_set('display_errors',1);
ini_set('display_startup_errors',1);
error_reporting(-1);
?>
Job done.
Friday, 22 November 2013
OOP Series : Interfaces
An interface is a template of mthods. Not properties. An interface is usually accompanied by an 'implements' clause. Classes which implement an interface must contain the declared methods. There is no defined means of declaring a JavaScript interface/implments combination.
PHP : template.class.php
<?php
interface template
{
function setWidth($width);
function setHeight($height);
}
?>
PHP : document.class.php
<?php
require_once 'template.class.php';
class document implements template
{
public $width, $height;
function setWidth($width)
{
$this->width = $width;
}
function setHeight($height)
{
$this->height = $height;
}
}
?>
Now a file (index.php) which creates a document object.
<?php
require_once 'document.class.php';
$doc = new document;
$doc->setWidth(10);
$doc->setHeight(10);
echo $doc->width.' '.$doc->height;
?>
PHP : template.class.php
<?php
interface template
{
function setWidth($width);
function setHeight($height);
}
?>
PHP : document.class.php
<?php
require_once 'template.class.php';
class document implements template
{
public $width, $height;
function setWidth($width)
{
$this->width = $width;
}
function setHeight($height)
{
$this->height = $height;
}
}
?>
Now a file (index.php) which creates a document object.
<?php
require_once 'document.class.php';
$doc = new document;
$doc->setWidth(10);
$doc->setHeight(10);
echo $doc->width.' '.$doc->height;
?>
Labels:
implements,
interface,
JavaScript,
oop,
PHP
Subscribe to:
Posts (Atom)