Install latest version WordPress Mac Terminal command

Nice little one liner for installing the latest version of WordPress through a little mac terminal command.

Create yourself a ~/.bash_profile file and create this function within it.

wp-install(){
	wget http://wordpress.org/latest.tar.gz;
 	tar xfz latest.tar.gz;
	mv wordpress/* ./;
	rmdir ./wordpress/;
	rm -f latest.tar.gz;
}

Nice little one liner for installing the latest version of WordPress through a little mac terminal command. Create yourself a ~/.bash_profile file and create this function within it. wp-install(){ wget http://wordpress.org/latest.tar.gz; tar xfz latest.tar.gz; mv wordpress/* ./; rmdir ./wordpress/; rm -f latest.tar.gz; }

Laravel and WordPress as a subfolder

I wanted to recreate a small blog for a site I was building in Laravel for a bit of fun but didn’t want to waste/spend loads of time recreating a blog. When in my honest opinion WordPress does an un-touchably good job of that already.

If you want to just simply install WordPress in your Laravel install under a subfolder, it’s quite simple really. Just install into public/blog (or whatever you want to name your blog).

Mac terminal fan? Little SVN one liner for you.

cd public | mkdir blog && cd blog | svn co http://core.svn.wordpress.org/tags/3.5 .

If you don’t use the public folder as your vhosts root like me you could use a .htaccess rule instead.

# Apache configuration file
# http://httpd.apache.org/docs/2.2/mod/quickreference.html
# Note: ".htaccess" files are an overhead for each request. This logic should
# be placed in your Apache config whenever possible.
# http://httpd.apache.org/docs/2.2/howto/htaccess.html
# Turning on the rewrite engine is necessary for the following rules and
# features. "+FollowSymLinks" must be enabled for this to work symbolically.
<IfModule mod_rewrite.c>
	Options +FollowSymLinks
	RewriteEngine On
</IfModule>
# For all files not found in the file system, reroute the request to the
# "index.php" front controller, keeping the query string intact
<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteCond %{REQUEST_URI} !^public
    RewriteRule ^(.*)$ public/$1 [L]
</IfModule>

Maybe something like that might help? But don’t hold me to it. You could also use a exclusion rule in your .htaccess file.

RewriteCond %{REQUEST_URI} !^/(~blog|/.*)$

I wanted to recreate a small blog for a site I was building in Laravel for a bit of fun but didn’t want to waste/spend loads of time recreating a blog. When in my honest opinion WordPress does an un-touchably good job of that already. If you want to just simply install WordPress in your

Read the rest of this article →

MySQL rand unix timestamp without additional PHP loop + subquery

Figured we could improve a PHP script to not require an additional loop around records and sub query today.

This query will insert a random unix timestamp between now and 86399 seconds time (or almost one day) for each row.

I’ve found it to be an improvement on sub queries.

UPDATE dummy_table SET time_field = UNIX_TIMESTAMP(NOW())+FLOOR(1 + (RAND() * 86399));

Figured we could improve a PHP script to not require an additional loop around records and sub query today. This query will insert a random unix timestamp between now and 86399 seconds time (or almost one day) for each row. I’ve found it to be an improvement on sub queries. UPDATE dummy_table SET time_field =

Read the rest of this article →

A rule of life

Make it a rule of life never to regret and never to look back. Regret is an appalling waste of energy; you can’t build on it; it’s only good for wallowing in.

Make it a rule of life never to regret and never to look back. Regret is an appalling waste of energy; you can’t build on it; it’s only good for wallowing in.

Katherine Mansfield

Lemonstand get unpaid orders by customer

During the checkout process Lemonstand automatically clears your shopping cart in favour of creating a Shop_Order object which is pretty static and can be paid for at any point in the future. This object represents the state of your cart when you clicked pay now.

Sometimes (as many of you will know) a user will click pay and not actually either a) want to pay or b) able to pay successfully. Unfortunately in most theme designs the cart is usually fairly prominent in the UI design and serves as a reference point before you checkout.

This is fine, that is, until a user clicks pay. After they click pay if they choose to navigate away little do they know but they’ll find it tricky to get back to that point again without visiting a ‘My account’ page or something similar. Which at this early stage and since in alot of users eyes your not a customer with an account until you check out and complete an order is not great.

We wanted to be able to show the customer there unfinished order in two places so to make it a little easier to pick up where you left off. Below I discuss a couple of ways that we have implemented this.

*Note: Lemonstand do not provide a function for selecting unpaid orders.

/* The order status id way */
$unPaid = Shop_Order::create()->where('customer_id = ?',$this->customer->id)->where('status_id != ?',$your_unpaid_status_id)->limit(2)->find_all(); ?>
/**
  * The more flexible way perhaps for sellable themes.
  * - works best when no status id is known */
$unPaid = Shop_Order::create()->where('customer_id = ?',$this->customer->id)->find_all();
$un_paid = 0;
if(count($unPaid) > 0)
{
    foreach($unPaid as $u_order)
    {
        if(!$u_order->is_paid())
        {
            $un_paid++;
            # Do what you like here.
            echo 'Order ID '.$u_order->id.' is unpaid';
        }
    }
}
/**
  * The tidy way for a non re-sellable theme.
  * - loaded in through a custom module (perhaps containing helper functions)
  * - works best when no status id is known */

# To be placed in your custom module.
function has_unpaid_orders($customer_id){
    $orderCount = 0;
    if($customer_id)
    {
        $unPaid = Shop_Order::create()->where('customer_id = ?',$customer_id)->find_all();
        if(count($unPaid) > 0)
        {
            foreach($unPaid as $u_order)
            {
                if(!$u_order->is_paid())
                {
                    $orderCount++;
                }
            }
        }
    }
    return $orderCount;
}
/* Called from your template like this */
Your_Helper::has_unpaid_orders($this->customer->id);

/* or */
if(Your_Helper::has_unpaid_orders($this->customer->id))
{
    # do something
}

If you are unsure what we mean by a custom helper module. Shortly I will describe in another post how you can achieve this.

During the checkout process Lemonstand automatically clears your shopping cart in favour of creating a Shop_Order object which is pretty static and can be paid for at any point in the future. This object represents the state of your cart when you clicked pay now. Sometimes (as many of you will know) a user will

Read the rest of this article →

Lemonstand back to search or category results

Today I had to add a basic back to search results implementation and thought i’d blog it for future reference.

I could not find anything implemented in the documentation so decided to add this snippet of code to any of the category or search pages that I had. Be sure to add it inside of the partial which gets re-loaded during pagination changes to continuously update the session as the user browses.

<?php Phpr::$session->set('back_r', $_SERVER['REQUEST_URI']); ?>

You can imagine whats next, open your product page / product partial (depending on your setup) and add the following lines where you would like to display the back to search results link.

$back_r = Phpr::$session->get('back_r');
if($back_r)
{
    echo '<a href="'.root_url($back_r).'" title="Back to search results">&laquo; back</a>';
}

Hopefully this might be of use to someone else.

Today I had to add a basic back to search results implementation and thought i’d blog it for future reference. I could not find anything implemented in the documentation so decided to add this snippet of code to any of the category or search pages that I had. Be sure to add it inside of

Read the rest of this article →

Lemonstand simple display product list from category

I quite often get asked how to achieve this easily by friends and colleagues and in there defence it’s not ‘clearly’ documented. So I thought i’d knock something up really quickly to show you how it can be done.

In this example I create a category called ‘Featured’ and I importantly set the ‘API code’ for this category to ‘featured’. This is found at the very bottom of the category creation / edit page.

I want to pull in some featured products into my homepage so I dive into the CMS and pull up the homepage.

You’ll want to enter the below snippet into the template.

<? 
$category = Shop_Category::create()->find_by_code('featured');
$this->render_partial('shop:product_list', array(
    'products'=>$category->list_products()->find_all()
)) ?>

This snippet first fetches the correct category object and then renders a partial called shop:product_list (or shop;product_list.htm if you use template based files) with all of the products under this category.

Now you just need to make your partial and add some basic code to it.

I’m not going to dive into the full extent of what you can now do with the below code but just get you on your way.

In your shop:product_list partial add the following code:

<ul>
<? foreach ($products as $product): ?>
<li>
<h3><a href="<?=  $product->page_url('/product') ?>"><?= h($product->name) ?></a></h3>
<p><?= h($product->short_description) ?></p>
</li>
<? endforeach ?>
</ul>

And that’s all there is to it. You’ll now be getting a list of all the products in this category on your homepage. Of course it is also worth noting you could use this same partial in many places across your site. It’s use will probably largely depend on how heavily uniform or customised the section on your site is.

Hope this is of some use.

I quite often get asked how to achieve this easily by friends and colleagues and in there defence it’s not ‘clearly’ documented. So I thought i’d knock something up really quickly to show you how it can be done. In this example I create a category called ‘Featured’ and I importantly set the ‘API code’

Read the rest of this article →

Linode – My early impressions

linode logo gray Linode   My early impressionsFor quite sometime now i’ve been looking for a place to house my personal projects, which gives me the flexibility of a cloud style host but with full root access so that I may toy around with installing whatever I need.

Linode offers the ability to deploy Linux virtual servers in the Linode cloud. With it’s simple Stackscripts for quick deployment of LAMP or LEMP server stacks. You can also deploy Stackscripts with popular open source CMS WordPress, CMS Drupal and even a Minecraft multiplayer server in a few clicks.

Check out some of the awesome Stackscripts on Linode – http://www.linode.com/stackscripts/

Linode might not be the cheapest cloud based VPS you’ll find, but with it’s basic package starting at just $19.99 a mere £12 p/month it’s still pretty in-expensive.

I deployed the WordPress and Ubuntu Stackscript from Linode in a few minutes then successfully setup vhosting and my WordPress sites in not a great deal longer. So far my Linode has 16 days of uptime. Running this very blog icon smile Linode   My early impressions (amongst others)

This blog is running on an Ubuntu LAMP stack, with WordPress (Version 3.4.2 at the time of writing), fine tuned with WP Super Cache and CDN Sync Tool for fast static content delivery. It’s also fully responsive icon wink Linode   My early impressions buzzzwwooorrdddds.

One thing I have noticed since deploying my Linode is the fantastic community behind it. Unlike other alternatives, i’ve noticed Linode has an extremely knowledgeable and loyal following of fellow mostly friendly and happy to help Linux server enthusiasts. Linode has some excellent tutorials and help guides coupled with an excellent IRC channel which is almost always buzzing.

I’m so far very impressed with Linode and in comparison to AWS it provides a combination of cloud, community, help and control at a good price. AWS micro instances are cheap at about £10 p/m but do not offer guaranteed resources, where as Linode does. I also kept getting MySQL crashes on my AWS instance.

Linode even offers a generous 7 day money back guarantee.

For quite sometime now i’ve been looking for a place to house my personal projects, which gives me the flexibility of a cloud style host but with full root access so that I may toy around with installing whatever I need. Linode offers the ability to deploy Linux virtual servers in the Linode cloud. With

Read the rest of this article →

Get latest 3 tweets from twitter

Just blogging this for future reference. It’s useful to grab twitter status’s asynchronously. But does not provide any niceties like nice formatting of dates or hashtag links etc. On the flip side it does give you ultimate flexibility to play with the data as you will.

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script type="text/javascript">
var url = 'http://api.twitter.com/1/statuses/user_timeline/daveheward.json?count=3&include_rts=1&callback=?';
$.ajax({  
    url: url,  
    dataType: 'json',   
    async: false,  
    success: function(json){  
        $.each(json, function(index, value){ 
            //console.log(value);
            $("#twitter_update_list").append(value.text+'<br>');
        });
    }  
});
</script>

Just blogging this for future reference. It’s useful to grab twitter status’s asynchronously. But does not provide any niceties like nice formatting of dates or hashtag links etc. On the flip side it does give you ultimate flexibility to play with the data as you will. <script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script> <script type="text/javascript"> var url = 'http://api.twitter.com/1/statuses/user_timeline/daveheward.json?count=3&include_rts=1&callback=?'; $.ajax({

Read the rest of this article →