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.
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.
<?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! – +1 thumb, 1 overall.
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: (more…)
2018 update: Bower might not be the right thing to be using nowadays. Here’s a note from the Bower website: “…psst! While Bower is maintained, we recommend using Yarn and Webpack or Parcel for front-end projects read how to migrate!”
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)… (more…)
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:
$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.
Please let me know if this post was useful with a click, be honest 🙂 (No Ratings Yet)
Problem: After requesting a renewal QuickSSL Premium cert from GeoTrust, and uploading the Cert and CA Intermediates to the Plesk 10 interface, I’m warned that: “Warning: the CA certificate does not sign the certificate”.
Problem: I wanted to use Foundation 4’s tooltips on some WordPress post thumbnail (featured) images, but wasn’t sure how to add the necessary data attribute and classes.
Solution: It turns out after some playing about that an array of attributes can be passed to the WordPress ‘get_the_post_thumbnail()‘ function. Firstly we need to add the class ‘has-tip’ (and any extra positioning classes like ‘tip-top’ if that’s where we want the tooltip to appear – see the Foundation Docs link at the top). We then need to add the data attribute ‘data-tooltip’. An example of how to do this is in the following code where I pull out a value from an Advanced Custom Field, and display a list of images with tooltips:
Problem:
I’m building something using Drew Morris’ Foundation 4 Theme for WordPress (http://fwp.drewsymo.com/) and it allows shortcodes like [row] and [column] to be used, so that content can be aligned to the grid.
The problem is, when those shortcodes are used with any sort of line break after them, wpautop() plays havoc with the markup. I could just disable wpauto() with `remove_filter( ‘the_content’, ‘wpautop’ );` but I want it to effect all other content.
Solution:
Wordpress 3.6 has an nice new tag called has_shortcode() which can be used along with some RegEx and preg_replace() to replace the offending <br /> tags. Here’s my first version… it can be improved but it’s working pretty well so far!
Problem: This morning I wanted to quickly move a little Laravel test project onto my live server. The default file structure of Laravel stores all the framework resources in a vertical tree of files and directories, and then the ‘public’ directory is adjacent to these. Like so:
- [app]
- [bootstrap]
- [public] etc
To host it on my CentOS box running cPanel I want to adhere to the following (standardish) structure:
- [.htpasswds]
- [etc]
- [mail]
- [public_ftp]
- [public_html] etc etc varies depending on server
I could just upload everything in my Laravel project to the ‘public_html’ directory… but then to run the app I’d need to browse to http://example.com/public/. Worse still, my whole framework file-structure will be visible if I browse to http://example.com
Solution: With a little path remapping in two files, this can be easily achieved. Here’s what I did:
1) Create a new directory called ‘laravel4’ adjacent to ‘public_html’ so that your remote file structure now looks like this: (more…)
Problem: Someone on the Shopp Helpdesk asked how they could display the payment type that a customer had just selected, on the following Order Confirmation page. They were using multiple ‘Offline Payment’ type options, and presumably they needed the customer to be able to visually confirm what they’d selected. As far as I can see, there’s no template tag provided for this.
Solution: All sorts can be pulled from the ShoppShopping() object directly. In this case the following worked:
data->Order->Billing->cardtype; ?>
Bonus: To display the same info in reciept.php, the following can be used: