Find Which Search Keyword For Page With Google Analytics

Posted: January 19th, 2012 | Author: | Filed under: google analytics, html | No Comments »

Open the ‘Traffic Sources’ drop down and click on ‘Overview’

Click on the Search Term/Keyword you are interested in

Click on the ‘Secondary Dimension’ drop down, expand ‘Traffic Sources’ and Click on ‘Landing Page’

View Glorious Data

Such Valuable Information. I really have to wonder why Google felt the need to bury so deep into the UI.


WordPress: Remove Date From Posts on Category Page

Posted: October 4th, 2011 | Author: | Filed under: wordpress | No Comments »

The first thing you will need in order to remove the date from category pages is the id of the category which you wish to hide the dates on. To get the id click on ‘Categories’ in the admin and then click on the actual category you wish to affect. In the url you will see the id, similar to this:

In this instance, our ID is ’42′. Next you will need to find the file that you need to add the code into. By default WordPress will look in

\wp-content\themes\'your-theme'\

for the file in this order:

  1. category-slug.php (Note: available with Version 2.9)
  2. category-ID.php
  3. category.php
  4. archive.php
  5. index.php

Once you have found the appropriate file modify it like so around line 53 near the h2 tag:

<?php //hide date for category
	$show_date=true;
	$cat_array =  get_the_category($post->ID); 
	//print_r($cat_array);	
	$count = count($cat_array);
        for($i=0 ; $i < $count; $i++){
            $cat_id = $cat_array[$i]->cat_ID;
	    if ($cat_id == 42){
	        $show_date = false;
	    }
        }
if ($show_date) {?>
<span class="date"><?php the_time('d M'); ?></span>
<?php
}
?>

Be sure to replace the number on this line

 if ($cat_id == 42)

with this ID from above.
If you wish to hide the date on individual posts, you can add the same code to ‘single.php’


Php long running script to dynamically update html

Posted: July 17th, 2011 | Author: | Filed under: html, php | 1 Comment »

This code is a work in progress and should never be used in a production environment without extensive testing!

First, the page that is loaded into the browser, it uses jQuery to receive status updates from ‘getstatus.php’ script

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Update Inventory</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
 
     var flag = false
     var stop = false;
 
$(function() {
    startProcess();
    getStatus();
 
 
});
 
function startProcess() {
 
    $("#done").load('updatestock.php', function() {
 
        flag = true;
 
    });
 
}
 
function getStatus() {
 
    if ( stop ) {return false;}
 
    $("#status").load('getstatus.php');
    setTimeout("getStatus()",2000);
 
	if ( flag ) {stop = true;}
 
}
 
</script>
 
<style type="text/css">
div {padding:0 0 0 50px;}
</style>
 
</head>
<body>
	<h1>Long Running Script</h1>
	<div id="done"></div>
	<div id="status"></div>
</body>
</html>

This is the long running script simulator

 
<?php
 
$fh = fopen('status.log', 'w'); 
//simulate work for 30 seconds
    while($i < 30) {
	fwrite($fh, time()."<br />\n");
      sleep(1);
      $i++;
    }
 
fclose($fh);
 
?>

And getstatus.php, the script that returns data to be appended to div

<?php
/*
this script is accessed by the html version of the updater, and spools the output to the screen 
so the user can see updated information as the the script runs.
*/
 
$page = file_get_contents('status.log');
echo $page;
 
?>

Try it here (buggy)


Simple php ftp download file script example

Posted: July 15th, 2011 | Author: | Filed under: php | Tags: , , , , | 1 Comment »
 
<?php
 
// define some variables
$local_file = '<save-file-as>';
$server_file = '<server-file-name>';
$ftp_user_name='<ftp-user>';
$ftp_user_pass='<ftp-pass>';
$ftp_server='<ftp-host-name>';
// set up basic connection
$conn_id = ftp_connect($ftp_server);
 
// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
 
/* uncomment if you need to change directories
if (ftp_chdir($conn_id, "<directory>")) {
    echo "Current directory is now: " . ftp_pwd($conn_id) . "\n";
} else { 
    echo "Couldn't change directory\n";
}
*/
 
// try to download $server_file and save to $local_file
if (ftp_get($conn_id, $local_file, $server_file, FTP_BINARY)) {
    echo "Successfully written to $local_file\n";
} else {
    echo "There was a problem\n";
}
 
// close the connection
ftp_close($conn_id);
 
?>