First you need to choose which post type you want to list and to choose a custom field to filter by you use the “meta_key” key in the array. The key starts with “wpcf-” and afterwards the name of the custom field you want to use.
1 2 3 4 5 6 7 8 9 |
$posts = query_posts( array( 'post_type' => "event", 'posts_per_page' => 40, 'meta_key' => 'wpcf-start-date', // load up the event_date meta 'orderby' => 'meta_value', 'order' => 'asc', ) ); |
I frequently use Font Awesome when making website to easily add icons to buttons or within the pages. You can also use Font awesome to make a custom list style. This is a useful website to search for Font awesome icons -> http://faicons.com/ and get the unicode to change the icon. You can change the type of icon in the li:before selector….
You can do this by adding this code to your template file. This will add a hook. Your javascript code will now be placed in the footer of your page (or where the wp_footer() function is called).
1 2 3 4 5 6 7 8 9 10 |
<?php function footer_script(){ ?> <script> jQuery(document).ready(function(){ //put your js code here }) </script> <?php } add_action('wp_footer', 'footer_script'); ?> |
For example, if I have a button with an id “btn” and a form with the id “form” and I want to scrollto the form when I click on the button HTML:
1 2 3 4 5 6 |
<p><a href="" id="btn">go to form</a></p> <form id="form"> </form> |
jQuery:
1 2 3 4 5 6 7 8 |
$(document).ready(function(){ $("#btn").click(function(e){ e.preventDefault(); $('html, body').animate({ scrollTop: $("#form").offset().top }, 1000); }) }) |
Instead of MAMP I use Vagrant to set up my virtualhosts locally. That way you can emulate your webserver’s setup. To configure my Vagrant virtual machine I use PuPHPet. You need to have VirtualBox installed for this. After downloading the PuPHPet configuration manifest you need to start up the virtual box. You do this by executing this command:
1 |
vagrant up |
Sometimes I…
Sometimes there are problems with the tabindex when you use the Gravity forms plugin in WordPress. You can fix this by adding this to your theme’s functions.php file
1 2 3 4 5 6 7 8 |
//############################################################################### // Fix Gravity Form Tabindex Conflicts //############################################################################### add_filter("gform_tabindex", "gform_tabindexer"); function gform_tabindexer() { $starting_index = 1000; // if you need a higher tabindex, update this number return GFCommon::$tab_index >= $starting_index ? GFCommon::$tab_index : $starting_index; } |
This will set the start index from gravity forms to a higher number.
Add this piece of code to your theme’s function.php file.
1 2 3 4 5 |
add_filter('widget_tag_cloud_args','set_number_tags'); function set_number_tags($args) { $args = array('number' => 20); return $args; } |
Set the number of the amount of tags you want to display on your page. Or you can just use the parameters for the wp_tag_cloud function.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
<?php $args = array( 'smallest' => 8, 'largest' => 22, 'unit' => 'pt', 'number' => 45, 'format' => 'flat', 'separator' => \\"\n\\", 'orderby' => 'name', 'order' => 'ASC', 'exclude' => null, 'include' => null, 'topic_count_text_callback' => default_topic_count_text, 'link' => 'view', 'taxonomy' => 'post_tag', 'echo' => true, 'child_of' => null(see Note!) ); ?> |
1 |
<?php wp_tag_cloud( $args ); ?> |
When within a facebook app you sometimes want to scroll to the top of the page but outside of the iframe which contains your app. To do that you use the following code in javascript:
1 |
FB.Canvas.scrollTo(0,0); |
This will only work when your canvas height is set to “Settable”. By default 800px. You can make in settable in the app Dashboard…
The default password form uses this message: “This post is password protected. To view it please enter your password below:”. You can use a custom text to display on a protected page by using a filter in WordPress. Add this code to your theme’s functions.php file:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
<?php function custom_password_form() { global $post; $label = 'protected-page-'.( empty( $post->ID ) ? rand() : $post->ID ); $o = '<form action="' . esc_url( site_url( 'wp-login.php?action=postpass', 'login_post' ) ) . '" method="post"> ' . __( "Enter the password to see the protected page:" ) . ' <label for="' . $label . '">' . __( "Password:" ) . ' </label><input name="post_password" id="' . $label . '" type="password" size="20" /><input type="submit" name="Submit" value="' . esc_attr__( "Submit" ) . '" /> </form> '; return $o; } add_filter( 'the_password_form', 'custom_password_form' ); ?> |
I recently did a find and replace over a whole project where every file had to be edited. There were about 2000 files that had to be edited. My Sublime text was crashing after a while. Problem was that, after I closed Sublime text and reopened it, the 2000 files reopened automatically, which meant my Sublime Text kept crashing. You…