Add Featured Image as a Background Image

Below is how you would use the featured image as a background image (also with an if statement so you can have a fallback image). <?php if (has_post_thumbnail( $post->ID ) ): ?> <?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), ‘single-post-thumbnail’ ); $image = $image[0]; ?> <?php else : $image = get_bloginfo( ‘stylesheet_directory’) . ‘/images/default_cat_img.jpg’; ?> … Continued

Add Sequential Classes to loop, WordPress

Below are to examples you will probably need the most.  Adding a sequential class to a for loop, and adding a sequential class to a while loop For Loop <?php global $post; $cntr = 1; $myposts = get_posts(‘category=1&numberposts=3&order=des’); foreach($myposts as $post) : setup_postdata($post);?> <li class=”<?php echo “post-” . $cntr; ?>”><a href=”<?php the_permalink() ?>”><?php the_title() ?></a></li> … Continued

WP REST API (WP API), Tips and Tricks

I’m starting to use the WP API more and more, and have definitely needed some help along the way.  Here are some tips and tricks I’ve been able to pick up and use. Get multiple types of posts / pages / etc /wp-json/posts?type[]=post-type&type[]=post-type Filter by specific number of posts per page /wp-json/posts?filter[posts_per_page]=4&page=2 (number of posts … Continued

Display posts from WordPress custom post type

There are more than a few way to show a Custom Post Type in WordPress.  This has been by far the best way to not just show custom post types, normal posts, but also retain a lot of WordPress default functionality. <?php $args = array( ‘post_type’ => ‘any-post-type’, ‘posts_per_page’ => 4, ); $query = query_posts($args); … Continued

Advanced Custom Fields Repeater Pagination

In the code below you will see an example of  Advanced Custom Fields Repeater Pagination with an image gallery mapped to a custom field named images with a sub field named image which contains an image object. The Repeater will be displayed on a page at the URL (just an example) /pictures. 12 images will be displayed per page, and pagination … Continued