I Build Web Sites

Do you need to take your dull website and make it shine? That's what SLiK INTERACTIVE is here to do, offering a range of web design services to meet your internet needs.

  • Mizu
  • Flow Go Riding Center
  • TW's Grille and Bar

Archive for the ‘Hacks’ Category

So I know in Wordpress there are several built-in functions for checking what page the user is currently viewing, but I needed to be able to check what page when not using Wordpress. After some searching I found this really simple PHP snippet for doing just that. Add this code somewhere in your PHP file so you can perform an action depending on the current URL:

 

1
2
3
4
5
6
7
8
9
10
<?php
 
$uri = $_SERVER['REQUEST_URI'];
if ($uri == "/") {
      echo "You're on the homepage";
} else {
     echo "You're on an internal page";
}
 
?>

Joomla CHMOD Trick when Installing Extensions


Are you getting Joomla an error like it can’t create a new directory when you try to install an extension? I can’t remember where I found it but this little PHP script will allow you to change the permissions for all of the  necessary folders in one shot when run in a browser. It will save you much time and headache trying to do it one by one. Thanks to the original creator! This is how to use it:


  1. Copy and paste the text into a new text file. Save it as “chmod.php”
  2. Upload the file to the root of your site and go to the following URL in your browser: http://www.yoursite.com/chmod.php?chmod=0777
  3. Upon hitting return, you should get a screen indicating success listing all of the directories of which it has changed the permissions. If something went wrong then you will get a different screen indicating it failed. Usually this is because the base path is wrong in chmod.php. ( The base path is usually something like “httpdocs/” )
  4. Install your extensions
  5. Once you’ve installed your extensions, go to: http://www.yoursite.com/chmod.php?chmod=0755 to change the permissions back to 755 so your files aren’t vulnerable.



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
 
<?php
 
// your ftp credentials
$ftp_server='your_server';
$ftp_user='ftp username';
$ftp_pass='ftp password';
 
// where is Joomla installed? (trailing slash required)
 
$base = 'httpdocs/';
 
// what files or directories need chmod applied? (trailing slash optional)
$dirs = array( 'administrator/backups',
               'administrator/components',
               'administrator/language',
               'administrator/language/en-GB',
               'administrator/modules',
               'administrator/templates',
               'administrator/cache',
               'components',
               'images',
               'images/banners',
               'images/stories',
               'media',
               'language',
               'language/en-GB',
               'language/pdf_fonts',
               'modules',
               'plugins',
               'plugins/content',
               'plugins/editors',
               'plugins/editors-xtd',
               'plugins/search',
               'plugins/system',
               'plugins/user',
               'plugins/xmlrpc',
               'tmp',
               'templates',
               'cache'
             );
 
// default to safe 0755 setting
if ($_GET['chmod']) {
    $ftp_chmod = $_GET['chmod'];
} else {
    $ftp_chmod = "0755";
}
echo "chmod=".$ftp_chmod.'<br/>';
 
// connect via ftp and apply chmod
$conn_id = ftp_connect("$ftp_server");
ftp_login($conn_id, $ftp_user, $ftp_pass);
foreach( $dirs as $dir ){
    if (ftp_site($conn_id, 'CHMOD '.$ftp_chmod.' '.$base.$dir)) {
        echo "success ";
    } else {
        echo "failed ";
    }
    echo $base.$dir.'<br/>';
}
ftp_close($conn_id);
 
echo 'DONE';
?>

Superfish Menu IE Z-Index Bug

Someday, us developers will not need to worry about IE6 fixes…but until that day comes we all must suffer!


Anyways, if you are using a superfish menu in Joomla then you may have noticed that in IE6, you can’t see the vertical drop-down menu because it is being covered up by the main content of the page. Turns out this is called the Z-Index Bug, which is only associated with IE6 and IE7. Awesome.


The FIX:


If your HTML looks something like this:


1
2
3
4
<div id="header">
<div id="nav" class="sf-menu">Here the menu</div>
</div>
<div id="content">Here the content</div>

Then you should add the following CSS to each of these elements:


1
2
3
4
5
6
#header {
    z-index:2;
}
#content {
    z-index:1;
}

This ensures that the entire header div, which contains the superfish menu, has a z-index that is greater than the main content div, which was overlapping the drop-down menu. Worked for me!

Youtube Video Overlaps Lightbox/Thickbox

This is usually occurs when there is an embedded youtube video and a Lightbox gallery on the same page. The flash video player will jump above the Lightbox images. You’d think that changing the z-index of elements would fix this but, nope.


The way to fix this problem is with a couple of additions to the Object and Embed tags used when embedding the youtube video.

The Fix:


Add the following code after the Object tag


1
<param name="WMode" value="transparent"></param>

And add the following code just before the type=”application/x-shockwave-flash”


1
wmode="transparent"

Together it should look something like this:


1
2
<object width="300" height="220"><param name="WMode" value="transparent"></param><param name="movie" value="http://www.youtube.com/v/NnMgg4nygSY&hl=en&fs=1&"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param>
<embed wmode="transparent" src="http://www.youtube.com/v/NnMgg4nygSY&hl=en&fs=1&" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="300" height="220"></embed></object>

Wordpress Pagination Not Working!!!

Take it easy, this is actually a pretty easy fix.


Basically the functions involved with paging are using a global variable called $wp_query. When we create our own instantiation of WP_Query ( the object $wp_query is an instance of ), we don’t have this global variable which is why paging is not working.


SO…


Add the following code directly above the main while loop:

1
2
3
4
5
6
<?php
$temp = $wp_query;
$wp_query= null;
$wp_query = new WP_Query();
$wp_query->query('showposts=5'.'&paged='.$paged);
?>

Also change this:

1
<?php while (have_posts()) : the_post(); ?>

To this:

1
<?php while ($wp_query->have_posts()) : $wp_query->the_post(); ?>

So it all together should look something like this:

1
2
3
4
5
6
7
8
9
10
...
	<?php if (have_posts()) :
             $temp = $wp_query;
             $wp_query= null;
             $wp_query = new WP_Query();
             $wp_query->query('showposts=5'.'&paged='.$paged);
         ?>
	 <?php while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
<div class="post" id="post-<?php the_ID(); ?>">
...

IE6 Bug – Negative Margins

I recently implemented a javascript animated menu into a site I built and ran into this problem of negative margins not rendering in IE6 when cross browser testing…So to make a long story short I found this workaround which did the trick!

 

Style the element with position: relative and give it negative offsets instead of negative margins.

 

1
2
position: relative;
left: -20px;

This will have the same effect as negative margins. Hope it works for you!

IE6 Bug – DIV Disappears When Window Resizes

In Internet Explorer 6 there’s a bug ( one of many… ) that occurs when you resize the browser window causing an absolute positioned div tag’s contents to disappear. It only returns if you refresh the browser. This usually occurs with background images and on text positioned next to a floated element.

 

After searching for awhile I found this solution which worked best:

 

Turns out if you add a CSS rule of height:1%; to the containing div, the content then shows up like it is supposed to, even after resizing the browser window. Hope this saves someone some valuable searching time!


1
2
3
4
5
6
7
 #container_div{
     height:1%;
} 
 
#inner_div{
     position:absolute;
}