To create a custom template in WordPress for specific categories based on the slug is not a built-in function.  Not sure why since it makes sense to build this capability without creating a new filter.  This could be plug-in, but it’s so simple, it’s one of those things you wonder why it’s taking so long to be included in the core capabilities.  Who wants to install all those single-purpose plug-ins, anyway?

So if you have a category slug called “news” and you want all your news posts to use this new template, just add this filter to your child theme’s footer.php file.  In this example, you would need to create a template file called “single-news.php” and WordPress will automatically use this to override the theme’s template for that category.

//Gets WP category slug of post and looks for single-[cat slug].php template file:

add_filter('single_template', create_function(

      '$the_template',
      'foreach( (array) get_the_category() as $cat ) {
            if ( file_exists(STYLESHEETPATH . "/single-{$cat->slug}.php") )
                  return STYLESHEETPATH . "/single-{$cat->slug}.php"; }
           return $the_template;' )
);

NOTE: If you’re not using a child theme, read this first, then if you’re still not convinced, use:   TEMPLATEPATH  instead of STYLESHEETPATH for above.  But don’t ever do it that way, every time WordPress gets updated you’ll end up having to make these changes, unless you just like letting code get broken because you’re too insecure of a web developer to want to create new solutions so you’d prefer to just keep fixing things you could prevent from breaking…


On one of my separate dev servers I figured it was as good of a time as any to upgrade to Windows 10.  It was a seamless update, kudos to Microsoft, but when I started up Virtual Box instance running on it, my network adapters were throwing strange errors.  I won’t bore you with the details, I just expected it to work and escape the wrath of Microsoft’s omnipotent presence.

I actually uninstalled Virtual Box the reinstalled it, enough angry web developers out there said this fixed it.  It didn’t.  Then I had to fanangle the /etc/network/interfaces file AND the network adapter settings on each VM to get to work properly again.  Who’s to say it wasn’t the firewall on the Windows server and why am I running Ubuntu, Red Hat, Fedora and CentOS VMs on Windows 10, you might ask?  Because those are the flavors I encounter most on live sites, so I like to set up as close of an environment I will encounter on my host and Virtual Box has been so reliable to deploy a new virtual server in less than 20 minutes with everything you need — MySQL, Apache, PHP, and all the PHP libraries, Virtualmin, and Webmin all ready to go.

So for documentation purposes, if you upgrade to Windows 10 and expect Virtual Box to keep humming, you may run into a few hiccups, it took me over an hour to get it to be visible on my LAN and accessible again so I could dev locally.  I remember back in 2005 devving sites on remote servers thinking how slow it was, not devving your site locally first is like pushing a race car instead of driving it — without using your hands!  Oh well, I’m not the strongest server admin, I’m more about the software and systems, so here are my latest settings that got VB and all VMs to work.

Below, you will see how I have 3 servers on different local IP addresses, each with a different web project.  Here are all the main settings that are easy enough to duplicate if needed!  Bridged Adapter is key, but I was reminded that it must still be the second adapter, not the first.  Why?  Good question, perhaps someone with more technical knowledge could enlighten us all?!  Any insight would be appreciated!

Latest VM VirtualBox network interfaces adapter setting 1 Latest VM VirtualBox network interfaces adapter setting 2 Latest VM VirtualBox network interfaces adapter setting 3

 

Here’s the cat /etc/network/interfaces:  Latest VM VirtualBox network interfaces file configuration


I added some new improvements to the “Insert Script” WordPress plug-in.  You can now declare a JSON string and it will parse it out as $json_vals_arr, an array that gets passed directly to your external PHP script.

You can also declare “strings” instead of “vals” as a GET URL string like:  “strings=’variable1=value1&variable2=value2&etc=andSoOn'”.

To download the most recent version, type in “Insert Script” and select the plug-in author “Aaron Belchamber”.  To learn more, visit the official Insert Script WordPress Plug-in Page.  This is a simple and clean way for WordPress PHP developers looking to integrate external scripts and content within a WordPress page, post, or widget.


I recently ran into an issue where I found I was creating a new user profile system for different systems and then it occurred to my:  DRY.  DON’T REPEAT YOURSELF.  Yet, in the bustle of activity I realized there was too much in common with these user profiles to rewrite the code.

So why not extract the user-related code and put it all in its own bundle for easier maintainability?  After all, in Symfony, it’s a breeze working between bundles, from one bundle you can call code from other bundles.  It was a “duh” moment, to say the least.

So how do you move some code you wrote that works to its own bundle?  Well, it took me less than 5 minutes to move 6 entities, 7 controllers and their supporting code like routing and update to the new bundle.

Step #1:  Go to your command line and type:    “app/console  generate:bundle”

I went through the Symfony tool and called it “UserBundle”.  Symfony will automatically create all the base and template files and folder structure for you new User Bundle.

Step #2:  Now, find all code that you already wrote and move it all to your new bundle following the same folder structure.

Step #3:  Do a search and replace all paths to your old bundle where the “namespace” and “use” declarations are and replace with the path to your new User Bundle.

Step #4:  Update your routes with the new paths, where applicable to make sure they are pointing to your new bundle’s controllers.

Step #5:  Clear your cache with “app/console ca:cl –env=prod”  then “app/console ca:cl”

Step #6:  Type in the URL that matches the path that will execute the controller code with the “app_dev.php” debug in the URL and test for errors.

Step #7:  Congratulate yourself for having the foresight to using a PHP framework, imagine the logistics if you wanted to move your code from some home-grown system what pitfalls you could have encountered.  Aren’t Symfony web developers just luckier than the plain old PHP developer variety?  Well, we’re luckier because there are tools and helpers already waiting for us so we can focus on writing code that creates solutions, not writing the code that helps us write the code to create solutions.  All you companies with your own Web Development department — are you getting this yet?!  If not, your loss.  Literally….


Here’s how you can allow different search engine bot crawlers if you prefer to address them individually.  There might be some crazy reasons why which I try to explain below.  For some companies, it seems web developers often don’t dev to create new web assets, they dev to squeeze any remaining SEO juice from their old assets.  Always diminishing returns when you measure the opportunity cost of not spending time and resources moving forward, but instead looking back.

SetEnvIfNoCase User-Agent .*bing.* search_robot
SetEnvIfNoCase User-Agent .*google.* search_robot
SetEnvIfNoCase User-Agent .*yahoo.* search_robot
SetEnvIfNoCase User-Agent .*bot.* search_robot
SetEnvIfNoCase User-Agent .*ask.* search_robot

Order Deny,Allow
Deny from All
Allow from env=search_robot

Here are some more .htaccess SetEnvIf & SetEnvIfNoCase Examples from Apache’s website.

PHP Logic for detecting different search engine crawlers

You may want to redirect your content to be customized for different search engine bots to repair certain SEO issues that you may encounter.

Here is the Search Engine Directory of Spider Names

if(stristr($_SERVER['HTTP_USER_AGENT'], "googlebot")){

    // what to do -- change "googlebot" to other spiders in list
}

For certain instances where some how a server that was supposed to be locked down was inadvertently crawled by a search engine, you don’t want to open your entire site for all crawlers, here’s a way you can open your site to confirm your site ownership file by the crawler and perhaps disavow content if you don’t have anything better to do than massage your site’s SEO and squeeze every drop of juice from it.

<html>
<head>
<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">
<title>Web Development is a finite resource</title></head>
<body>
Does quality content matter any more?
</body>
</html>