Posts

Showing posts with the label Technical

Passing a query string to your WordPress site and show something useful

Objective: Say my website runs on Word Press (henceforth known as WP) at http://www.abcdxyz.com A post might look like the following http://www.abcdxyz.com/?page_id=21 And the post gets rendered nicely. Say I want to pass a Query String (henceforth known as QS) test=1, based on which I want to show a plain text to user or in other words simple want to hook on to WP rendering technique and modify it. My intended URL becomes http://www.abcdxyz.com/?test=21 Normally if you call this, WP would render the default page to you and simply dispose off your idea of passing and doing something useful with QS. Solution: We have to modify the $query_vars, a mechanism of WP internals, with hook. 1. In your plug in file write the following hooks add_filter('rewrite_rules_array', 'add_new_allowed_qs'); You may define the body of the function as follows: function add_new_allowed_qs( $query_vars ){ array_push($query_vars, 'test'); // return return $q...

Left join should fetch data from left table even when right table doesn't have a reference

Okay first things first, the title may be confusing. Objective: There are two tables, Parent and Children. I'm creating a listing page where I'm fetching the parents and the children count, yes, please note it's count. Structures: Parent: id, parent_name Children: id, parent_id, child_name A single sql is needed which would fetch me the following columns: Parent.id, Parent.parent_name, count(child_name) as no_of_children Say for parent Tomtom there's two children, For Kawasaki there's 3 and for Mickey there's none (no association in Children table, no records absolutely). I want a list like the following: Row 1: 1 Tomtom 2 Row 2: 2 Kawasaki 1 Row 4: 3 Mickey 0 I tried the following SQL: select a.id as parent_id, a.parent_name, count(b.id) as no_of_children from Parent a LEFT JOIN Children b ON a.id = b.parent_id group by b.parent_id The output: Only the record mappings where at least 1 association is present in the Childr...

jQuery Select change event firing twice

Hmmm...nice one jQuery code: $('#my_dd').change(function(){      alert('hello') ; }) Surprisingly on change the alert was getting fired twice. Solution: Nothing much, this was more or less my ignorance, put the block inside document ready and everything should be fine Final code: $(document).ready(function(){      $('#my_dd').change(function(){          alert('hello') ;      }) }) Hope this helps anyone. Cheers

CodeIgniter, how to make some data from your database available throughout to all of your views

Huh, I know why you are here, welcome and all my compassion. I too spent 2 hours to get this out of the most popular light weight framework online documentation and huge fanbase. CI is more sweeter than a piece of Cake (;)), according to hardcore fans, but certainly their documentation is pain in the...well leave it. To the point: I want some data to be always available to all of my views regardless of which page I'm into in. For example it could be a drop-down of states in the right hand corner of my header menu. How do I do it? Solution: Create a helper file, say my_lil_helper.php and keep it under application/helpers. By the way you can do all the good things loosely, usually you do inside your controller, inside a helper. So it could be loading a model, a library, whatever. So you write a function there like this: function return_states() { //Model call to fetch data from db table and return return $state_array; } In you header file, all you have to do is, us...

Modal window generated, but not draggable, weired problem solved

These days I'm working with the jQuery UI toolkit and facing diversified problems which are quite silly in nature. For example today i was trying to implement modal windows using the UI toolkit, the window was getting generated but it was not draggable. A little investigation revealed that these libraries are not only dependent on other smaller building block files, but also on the order in which the files are included. I altered the following sequence: jquery.ui.draggable.min.js jquery.ui.mouse.min.js to jquery.ui.mouse.min.js jquery.ui.draggable.min.js And it worked like a charm. Hope this helps anyone facing similar problems. Cheers!

d(a).zindex is not a function

Can drive you crazy if it's really in form. Can fuse your every bit of good wits and you can start banging your forehead on your keyboard. To the point: Scenario: I was using jQuery UI datepicker. When I was generating the picker inline to a div, it was working correctly. But the moment I was binding it with a textfield, there you go:- d(a).zindex is not a function Which libraries were used in my header: 1) jquery.min.js 2) jquery.ui.datepicker.min.js The reason: I was selectively using just the datepicker portion from the entire UI library. And the problem was there itself. I overlooked the top portion of the jquery.ui.datepicker.min.js file which clearly stated this file had a dependency with jquery.ui.core.js Solution: I included jquery.ui.core.min.js (it could be jquery.ui.core.js either) among the scripts and there I was escaping the gravitational pull of the black hole namely 'd(a).zindex is not a function' Hope this helps somebody who i...

Rotating an Image on a View by touching it : the Objective C way

What? You want to rotate an Image by touching it? iPhone? iPod touch application? Have googled day and night? Got your spine aching, eyes red? Calm down, help is on its way. But I don't promise its bullet proof, but still, at least its working to some extent, and its done my way, my recipe which I tried over and over again so that it could taste the way it tastes now. As said earlier, it's not perfect, but it serves the main purpose, that is rotating an image around it's center by touching it, to some extent. Scenario: I had a View, UIView object. I called it "canvas". I had another view, UIImageView. I called it "imgobj". I was required to rotate it around it's center by touching. Concept: This is only possible when I know the angle between the straight lines made by by the points, center C (cx, cy) and where I touched P1 (x1, y1) and center (cx, cy) and where I took off my finger from the screen (x2, y2). So basically if we can get the difference o...

Sharing a link to your facebook wall from your external application

Goodmorning Kolkata , a new day, a new requirement from the client. His post on basecamp says, though he appreciates the fact that a photo could be directly uploaded to ones facebook album, it doesn't really appeal him much. Why? Ummm... tough question. He wants something simpler, sweeter and less painful (uploading images from external applications to facebook required the user to approve them on facebook before they could go live...extra clicks are painful alright) than the above method. In fact facebook also realizes this I guess and thus offers us exactly what we are looking for: http://www.facebook.com/sharer.php The above URL expects two parameter, 'u' and 't'. 'u' is the link you want to share, 't' is the additional title you want to supply Facebook in case it is unable to crawl through the title of the page provided in the link. So for example a complete link should look something like this: http://www.facebook.com/sharer.php?u=http://your-we...

Photo upload to Facebook from your PHP web application

Recently I was asked by one of my clients to develop a feature on his website so that a user on that website may click on a button and publish an image from his/her account (on that website) to his/her facebook account. While doing so the system would ask for the users facebook credentials. Sounds simple? Yeaah...apparently its simple but when you start getting your hands dirty you slowly realize you are in deep mess. Particularly if you are a first timer as far as developing on facebook platform is concerned. There are multiple ways to achieve this. Using facebook connect or using a facebook application specially developed by yourself to accomplish the task. I followed the second approach. I'm trying to outline the exact steps you need to perform to get this up and running with least pain. And yes, the following examples would all be in PHP . Login to facebook, click on the developers link available in the footer section of the page and follow the steps so that ultimately you end...