CodeHQ

Archive for December, 2014

| Newer Entries »

Post by taxonomy term

Saturday, December 13th, 2014

$terms = wp_get_post_terms( $post->ID , 'type' );

if ( $terms != null ){
 foreach( $terms as $term ) {
	$args = array(
		'post_type' => 'portfolio',
		'posts_per_page' => '3',
		'tax_query' => array (
			array (
				'taxonomy' => 'type',
				'field' => 'slug',
				'terms' =>  $term->slug
			)
		)
	);
	
}}

$query = new WP_Query($args);
$i = 1;
while ( $query->have_posts() ) : $query->
the_post(); 

Posted in PHP, WordPress | No Comments »

Shortcodes

Saturday, December 13th, 2014

Code not escaping properly – download this this file.

/* Add Button Shortcode */

function button($atts, $content = null) {
    extract(shortcode_atts(array(
        "link" => '#',
        "style" => 'btn-primary'
    ), $atts));
    return ''.$content.'';
}
add_shortcode("button", "button");
[button link="http://google.com"]Clicky clicky[/button]

Custom shortcode which includes php file example here

Posted in PHP, WordPress | No Comments »

Border-box

Saturday, December 13th, 2014

Use this to make an element include padding in to it’s width/height.

@media screen {
  *, *:after, *:before {
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
    box-sizing: border-box; } }

Posted in CSS | No Comments »

A WordPress query

Saturday, December 13th, 2014

A WordPress query that can be amended – like below for different post types/amount of posts/categories etc – codex info here

$args = array(
	'post_type' => 'post',
	'posts_per_page' => '16',
	'orderby' => 'rand'
);

$query = new WP_Query($args);

 $i = 1;

while ( $query->have_posts() ) : $query-> the_post();

Posted in PHP, WordPress | No Comments »

WordPress menu

Friday, December 12th, 2014

1) Register the menu in your functions.php file (Primary is the ID for the menu, Primary Menu is the name and Theme-name is the name of your theme)

register_nav_menus( array(
    'main_menu' => 'Main Navigation',
    'footer_menu' => 'Footer Menu',
    'legal_menu' => 'Legal Menu',
));

2) Enter this in to the location in your theme file where the menu will go (normally header.php)

<?php wp_nav_menu( array( 'theme_location' => 'primary' ) );?>

Tags: , , , , ,
Posted in PHP, WordPress | No Comments »

« Previous Page