I am trying to use the Category Posts (WP-CPL) plug-in on a blog I’m working on to filter ‘Recent Posts’ by category. Basically, when someone clicks on the category name on the blog, I would like it to display the posts from that category. This would be through the ‘archives.php’ file of the Life Is Simple template.
The shortcode for the plug-in is:
[wp_cpl_sc cat_id=40 list_num=4 css_theme=2 sticky_post="79"]
This is just an example where ‘cat_id’ represents the category that the plugin will display. I don’t want to display just one category, I want it to display the appropriate category when someone clicks on the link. How can I get the plug-in to recognize which category is being requested and display the appropriate posts?
I know that the category title is:
<?php single_cat_title(); ?>
But how do I find the category ID number in this fashion? I’ve included the PHP for the plug-in’s file titled ‘wp_cpl_shortcode.php’ below if that needs to be edited. I would prefer to use shortcode in the actual coding of the site for simplicity’s purpose.
<?php
/**
* shortcode
* The library of shortcode class
* @author Swashata <swashata4u@gmail.com>
* @subpackage WP Category Post List Plugin
* @version 2.0.0
*/
/**
* The WP CPL shorttag support
* @since 1.1.0
* This was started from the version 1.1.0 and was finished by 2.0.0
*/
class itgdb_wp_cpl_shortcode {
/**
* The wp_cpl_shortcode_handler function
* This function is responsible for converting shortcodes into dynamic contents
* @package WordPress
* @subpackage WordPress Category Post List plugin
* @since 1.1.0
* @param array $atts The attributes passed through the shortcode
* @param string $content The string passed through the shortcode. Used for generating title
* @return string The modified content
*/
public function wp_cpl_shortcode_handler($atts, $content = null) {
/** first extract the attributes */
$op = shortcode_atts(array(
'cat_id' => 1,
'css_theme' => 0,
'is_thumb' => 'true',
'list_num' => 10,
'show_comments' => 'true',
'sort_using' => 1,
'sort_order' => 'asc',
'exclude_post' => '',
'sticky_post' => '',
'show_date' => 'true',
'show_author' => 'true',
'show_excerpt' => 'true',
'excerpt_length' => 150,
'optional_excerpt' => 'false',
'read_more' => __('Continue Reading', itgdb_wp_cpl_loader::$text_domain),
), $atts);
/** Sanitize some of the user datas */
$cat_id = (int) $op['cat_id'];
$i = 0;
/** Done, now the main thing */
include_once itgdb_wp_cpl_loader::$abs_path . '/includes/wp_cpl_output_gen.php';
$output_gen = new itgdb_wp_cpl_output_gen();
return $output_gen->shortcode_output_gen($op);
}
}
Sorry if this question is convulated, I’m still learning and think I’ve twisted my brain around today. Thanks for any help!
The plug-in page is here:
I found a much easier way to do this. I called this PHP in the Loop:
And then was able to style the results with CSS and calling different elements such as the_title();