Flush the DNS Cache on Mac OS El Capitan (using a nice quick alias)

Updated June 2016: For OS X / 10.11 / El Capitan

Problem: I’ve updated some Name Server records on a domain and I want to check they’ve propagated using Dig. When I dig mydomain.com ns I keep getting the old results.

Solution: The local DNS cache on the machine needs to be cleared. As far as the OS is concerned, it’s already looked up that domain name and doesn’t need to do a fresh lookup until the domain record’s TTL (time to live) has expired.

On OS X 10.11 El Capitan there are two things needed. Firstly clearing the Directory Service cache and secondly forcing mDNSResponder to restart. This can be done using two commands in Terminal¹:

$ dscacheutil -flushcache
$ sudo killall -HUP mDNSResponder

Continue reading “Flush the DNS Cache on Mac OS El Capitan (using a nice quick alias)”

Get terminal / bash prompt to show useful info

Problem: Well it’s more of an irritation. My new hosting provider does allow SSH access, but when logged in the bash prompt looks like this, regardless of which account  I’m logged-in as, or where I am:

-bash-4.2$

What I want is for it to show something like:

username@server:/current/path$

Solution: The bash prompt can be customised via a profile script, ideally anything that loads when you log in like ‘.bash_profile’, ‘.bashrc’ or ‘.profile’. If one of these files doesn’t already exist in your home directory (check with ls -la ~ to list the contents) then create one. Here is an example of creating, editing and loading a login script to show a better prompt.

Continue reading “Get terminal / bash prompt to show useful info”

Updated for 1.2 & 1.3: Adding category depth tag to Shopp

Problem: I needed to display sub categories of a category in category.php but only one level deep. Using:

<?php if(shopp('category','hascategories')): ?>
  <?php while(shopp('category','subcategories')): ?>
    //display stuff
  <?php endwhile; ?>
<?php endif; ?>

…displays all subcast AND their subcats. Continue reading “Updated for 1.2 & 1.3: Adding category depth tag to Shopp”

Flush the DNS Cache on Yosemite (using a nice quick alias)

Problem: I’ve updated some Name Server records on a domain and I want to check they’ve propagated using Dig. When I dig mydomain.com ns I keep getting the old results.

Solution: The local DNS cache on the machine needs to be cleared. As far as the OS is concerned, it’s already looked up that domain name and doesn’t need to do a fresh lookup until the domain record’s TTL (time to live) has expired.

On OS X Yosemite there are two name resolution caches that need emptying, Multicast DNS and Unicast DNS. They can be cleared / emptied / flushed using two commands in Terminal:

sudo discoveryutil mdnsflushcache
sudo discoveryutil udnsflushcaches

Continue reading “Flush the DNS Cache on Yosemite (using a nice quick alias)”

Remove ‘ul’ and ‘li’ tags from WordPress menus while retaining all the classes

Problem:
I need to output a WordPress nav menu as a series of anchors surrounded by spans, within one nav element. Manipulating the args passed to wp_nav_menu() function will allow the <ul> element to be removed, and passing the output through ‘striptags’ can remove the <li> elements, but I end up losing all the link ancestry classes.

Solution:
If a ‘Walker’ class is used, the output from wp_nav_menu() can be controlled totally. Here’s an example that removes the list elements, adds a span around each item link, and adds the possibility of a separator string between each menu item.

Add to your theme / header / etc: Continue reading “Remove ‘ul’ and ‘li’ tags from WordPress menus while retaining all the classes”

Custom Ordering Shopp (wordpress plugin) products in just one category

Problem: I’ve developed a site using the Shopp ecommerce WordPress Plugin and product ordering is set to ‘Price – Low to High’ at the Client’s request. Splendid. But now – for one category only – he want’s the Products to be give a custom order. In the Shopp presentation settings, ‘Product Order’ is set site-wide.

Solution: I created a custom template for the category in question, then in that template loaded the specific category with the ‘order’ option set to ‘custom’. Here are some steps.

1) Create the category specific template in the ‘Shopp’ theme templates directory in your WordPress theme. In my case the file was called category-truss.php as ‘truss’ is the slug of the category, and it’s a copy of my main category.php template file.

2) At the top of category-truss.php add the API function shopp(‘storefront.category’) like so:

<?php shopp('storefront','category','slug=truss&load=true&order=custom'); ?>
// load=true is needed to stop the functioning spitting out the category directly.
// slug is whatever your category's slug is. See the docs for more 'order' options.

3) In the Shopp Admin area, edit the category you want to custom order, then use the ‘Arrange Products’ button/link. Then drag the products into the order you want and test.

It might be that there’s an easier or better way to do this, if so please let me know in the comments!

Please let me know if this tiny snippet was useful, just one click!
Nope, not helpful...Yep, more useful than not! - +1 thumb, 1 overall.
Loading...

Exclude a WordPress Post Category across the whole site… but not custom queries.

Problem: On my latest project there’s a WordPress post category that only ever displays in a sidebar. I never want it to display in a ‘main’ loop posts on an archive page (whether it be the blog home, date archives, author archive etc etc. Until now I’ve been using ‘query_posts()’ and doing something like this in the main templates like home.php and index.php:

<?php $catObj = get_category_by_slug('my-cat-slug');
query_posts( 'cat=-'.$catObj->term_id );
if ( have_posts() ) :
	while ( have_posts() ) : the_post(); ?>
		<!-- Show stuff init! -->
	<?php endwhile;
endif;?>

This works… but I have to do it everywhere the loop is used, and when you dig into WordPress Templates that’s a lot of places.

Solution: There’s always a way to do something globaly in WordPress using Filters, Actions, or Classes in your theme’s functions.php file (or a plugin even). In this case we can use the ‘pre_get_posts’ action in functions.php to exclude the category for all main queries: Continue reading “Exclude a WordPress Post Category across the whole site… but not custom queries.”

Bower update failed with ‘ERR! error rolling back’

Problem: I just tried to update Bower with:

$ npm update -g bower

Which resulted in failure, and Bower wasn’t able to roll back so the install was fudged. Here’s some output of the errors:

$ npm ERR! error rolling back Error: EACCES, unlink '/usr/local/lib/node_modules/bower/.editorconfig'
$ npm ERR! error rolling back  bower@1.2.8 { [Error: EACCES, unlink '/usr/local/lib/node_modules/bower/.editorconfig']
$ npm ERR! error rolling back   errno: 3,

Solution: Firstly I stopped being a dork and remembered I’d need to add ‘sudo’ (the ‘Error: EACCES’ gives it away)… Continue reading “Bower update failed with ‘ERR! error rolling back’”

Edit crontab with NANO on centos (crontab -e)

Problem: I don’t know where my root users crontab file is, and this doesn’t usually matter because using the command ‘crontab -e’ opens it for editing anyway… but it opens in VI and I am too stupid / lazy / in a rush to use VI.

Solution: The -e switch makes the file open in whatever the default editor for the environment is. To override this, pass the EDITOR environment var to the command when it’s run:

sudo env EDITOR=nano crontab -e

Please let me know if this nano tip was useful, just one click!
Nope, not helpful...Yep, more useful than not! - +40 thumb, 54 overall.
Loading...

wp_get_attachment_image_src() is NOT working, broken, failed, blaa…

Problem: No matter WHAT I do, wp_get_attachment_image_src() is NOT working. I JUST want the featured image source of this $post->ID.

Solution: Yes is probably is working… but stupidly I’m trying to pass it the POST ID and not the ATTACHMENT ID like I should be. The Attachment ID can be found with the get_post_thumbnail_id() function, and then passed like this:

1
2
$thisimg = wp_get_attachment_image_src(get_post_thumbnail_id($arr->ID),full);
print_r($thisimg); //shows the Array of bits you need.

Duh… me.