Pages

Thursday, January 19, 2017

Wordpress using wrong template after AJAX loading

A tricky problem with my AJAX-search function. WordPress decided to use front-page.php for loading extra AJAX-content. The problem was that this styled the content in a different way than I needed.

After identifying the root of the problem (which takes time!), I looked around for a neat solution. What I came up with was overriding the template hierarchy in case the request URL contains a “?” (which means we are searching). This is not a universal solution but it works for me.

Add the following to your functions.php


function ccb_template_override($template)
{
if( strpos($_SERVER['REQUEST_URI'],"?")!==false )
{
return locate_template('search.php');
}
return $template;
}
add_filter('template_include', 'ccb_template_override');

For a better solution that applies to all AJAX-loaded content, we need to set a flag (for example a GET-variable in the AJAX-request, or depend on server variables that tell us whether a request is an AJAX-request or not (which I understood are not universal yet).

Wednesday, January 18, 2017

#TechCelebs

Wednesday, December 30, 2015

Meteor

I played around with meteor yesterday and I have mixed feelings. First of all, I was impressed that the whole plaform (it is not just a framework but an end-to-end development platform for all devices and browsers that matter because of the power of JavaScript). It worked out of the box on my Windows machine and it deployed out of the box to the site (http://happy2016.meteor.com/).

I watched some videos about meteor and I like their bottom line of bringing to the world what Facebook and Google have been hiding from us for their revenue. Fast interactive (reactive) web technologies.

There are a few things that make me skeptical as to whether meteor is the future. First of all, do we really want to code in Javascript? I have found debugging a minor application to be a nightmare, even with Chrome developer tools. Hot code pushing and “optimistic UI” may be neat, but it really isn’t all that elegant or robust. I like the integration of angular and node, but I’m not sure about MongoDB. I needed a random record (my bad, I’m still thinking in SQL-records with primary and secundary keys rather than in document collections) and it was pretty tricky (but of course Stackoverflow helped me out).

I normally pick a platform for its clout and the amount of contributed modules/plugins. That’s why I used Drupal back in 2011 and switched to WordPress more recently. PHP, I know.

On Atmosphere.js there are some good projects available, but many are buggy and better not used in a production environment. Eventually, the success of meteor and similar platforms will hinge on how easy it is to deploy an app.

Tuesday, December 22, 2015

jQuery UI style hack

Some of us still use jQuery UI :) In fact, it wasn’t too bad, is still supported by all modern browsers, and performs reasonably well on mobile.

There is one issue: the graphics look horribly 2010. jQuery UI offers a user interface to cherrypick your own CSS (it’s great and kind of works: look at their themeroller here.

Still, it doesn’t let you replace the .png icons with font icons (fontawesome, dashicons). I didn’t feel like overhauling the thing so I came up with a simple hack that works for me (on this site):

.ui-corner-all { border-radius:0!important}
.ui-state-hover {border:0!important;background:transparent!important}
.ui-widget-header {background:@color1!important; color:@bkg!important}
.ui-widget-content{font-family:@font3!important}
.ui-state-default, ui-state-default:hover {color: @color1!important;background:@bkg!important;border:0!important}
.ui-corner-all thead, .ui-corner-all td {color: @color1!important;}
.ui-datepicker-prev span, .ui-datepicker-next span {visibility:hidden!important}
.ui-datepicker-prev:before, .ui-datepicker-next:before {font: 2em/1 dashicons!important;color: @bkg!important;}
.ui-datepicker-prev:before { content: "\f141"!important;}
.ui-datepicker-next:before{content: "\f139"!important;}

Sunday, December 20, 2015

Bob the Builder likes women with brick tits.

Tuesday, December 8, 2015

Weekly changing random number

Simple task: How do we generate a random number that automatically changes every certain period of time. Of course, we use the week number when calculating the random number. Also, we have to cache a “large integer” that will not change until the end of the week to get a deterministic random-enough number.

The result can look something like this when we integrate it in a WordPress menu and we only take into account the tags with a minimum number of posts.

$the_tags = get_tags();
foreach ($the_tags as $t) {
if ($t->count>INFOCUS_MIN) $ft[] = $t;
}
$tag = $ft[abs(SOME_LARGE_INTEGER * date(“W”) % sizeof($ft))];
$link = get_tag_link($tag->term_id);
$infocus = ‘<li id=”menu-item-featured-tag” class=”menu-item”><a href=”‘.$link.'”>’ . __(‘In focus: ‘)
. $tag->name.'</a></li>’;

This might be useful and hooking this simple stuff into a menu doesn’t really justify a plugin. But it can be extended with other functionality. We can call it Magic Menu Items. It could integrate with Jetpack to access statistics, and so on.

Wednesday, October 21, 2015

Gmail notification only for important mails

Some e-mails are more important than others. As a freelance writer/web designer/translator I often get time critical messages. I want to get an email notification with a sound alarm and a vibration for those, but not for all my mail (my phone would be abuzz continuously).

So I found this useful article on how-to geek. It is free and really simple to set up in gmail. You basically add a filter label and set your notifications only for that label in Android (the label needs to be created on a pc though).

Gmail notification is just a part of the puzzle for freelancers, especially those who want to be the first to respond to job offers.

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | Lady Gaga, Salman Khan