5 Recent Posts Title & Excerpts determined by Category

– Hijack The Loop, Drop in Plugin, Call with Short Code

The Problem: I want to show just my 5 recent design blog post excerpts on my design page. I, currently, have a blog page with all my posts ever and I have a widget that will list with links, my five recent posts (and the other query short code recently made to call a list of posts). What I want to have is an easy way to call just a few recent blog posts of a certain category, design in this case, to show up as a post title and excerpt with a link to the blog post.

The solution:
like the following 5 recent posts title & excerpt by category dev:
***************Short Code Example in Action***********************


jQuery Local Scroll flesler’s

The problem: A long list of information on a page. Solving by adding same page anchors, causes page to jump to the top on the screen. The solution: Using jQuery, the page can elegantly scroll to the position of the desired text without the rest of the page moving, just the targeted content area scrolls. Here’s how using proper enqueueing, … Continue Reading


5 Recent Posts Title & Excerpts determined by Category

– Hijack The Loop, Drop in Plugin, Call with Short Code The Problem: I want to show just my 5 recent design blog post excerpts on my design page. I, currently, have a blog page with all my posts ever and I have a widget that will list with links, my five recent posts (and the other query short code … Continue Reading


List links of Posts determined by Category

– Hijack The Loop, Drop in Plugin, Call with Short Code The Problem: I want to list just my last 5 happenings blog posts in a widget on my homepage. I, currently, have a blog page with all my posts ever and I have a widget that will list with links, my five recent posts. What I want to have … Continue Reading


Hijack The Loop, Drop in Plugin, Call with Short Code

What we are going to do hijack ‘The Loop’ How create a wp_query object modify loop drop it into a plugin call it with a shortcode passing parameters ******* This is classic information of how to pull certain posts onto certain pages using the best practices. First, The Loop will be covered, which is the powerhouse of your WordPress site. … Continue Reading


Parallax Scrolling

Notice the long one page sites that move like 3 dimensions sliding by that magnetically draws you in? Parallax scroll, it’s around big time. Nike has one of the best known sites using it. It’s eye catching, really. Parallax scrolling is being used in a big way and for the right site it can have an effective impact. Mainly, parallax … Continue Reading


***********End of Short Code Example in Action********************

How it’s done

create plugin file: my_cat_query/shortcode_for_my_query_custom_loop_cat.php
placed into a folder that is placed in the plugins folder /public_html/wp-content/plugins
*be sure to activate plugin in the Admin, once installed.
shortcode is called by placing brackets around ->
others_cat category_name=whatever the category slug name is
(change ‘whatever the category slug name is’ out)
similar to this [others category=Headlines]
Headlines is the category slug name.
Here’s what is dropped into plugin file:

<?php
/*Plugin Name: WordPress Meetup OC Demos category_name query
Description: Some demos for Meetup post by category formatted heavy
Version: 1.0
Author: mitcho tweaked by eshilling
Author URI: http://mitcho.com
*/

add_shortcode('others_cat', 'get_other_cat_posts');
function get_other_cat_posts($attributes)
{   $return = '';
$category_name = $attributes['category_name'];
$my_cat_query = new WP_Query(array('category_name'=>$category_name));
if ( $my_cat_query->have_posts() ) {
$return .= "<p>";
while ( $my_cat_query->have_posts()  && ($post_count < 5) ) {
$my_cat_query->the_post();
$post_count++;
$return .= "<p></p>";
$return .= get_the_post_thumbnail();
$return .= "</p><br />";
$return .= "<a class='post_cat_exc_title' href='";
	$return .= get_permalink();
	$return .= "'>";
        $return .= get_the_title();
		$return .= "</a>";
        $return .= "<br /><div style=\"margin:auto;\"><p>";
		$return .= get_the_excerpt();       }
		$return .= "</p></div>";     }
		return $return;

		}
		?>

Can change the number of post excerpts shown by changing: $post_count < 5 or to show all post excerpts from a certain category remove && ($post_count < 5) Image will show up too by adding a featured image to the post Can switch from using the category to determine how posts will be called, by changing out category_name with different parameter http://codex.wordpress.org/Class_Reference/WP_Query

Leave a Reply

Your email address will not be published. Required fields are marked *

*

*