我正在尝试使用我正在开发的博客上的分类帖子(WP-CPL)插件,按类别过滤“最近的帖子”。基本上,当有人单击博客上的类别名称时,我希望它显示该类别中的帖子。这将通过“档案”进行。php的生活文件是简单的模板。
插件的短代码是:
[wp_cpl_sc cat_id=40 list_num=4 css_theme=2 sticky_post="79"]
这只是一个示例,“cat\\u id”表示插件将显示的类别。我不想只显示一个类别,我希望它在有人单击链接时显示适当的类别。如何让插件识别所请求的类别并显示相应的帖子?
我知道类别标题是:
<?php single_cat_title(); ?>
但是我如何以这种方式找到类别ID号呢?我已经包含了插件文件“wp\\u cpl\\u shortcode”的PHP。如果需要编辑,请参见下面的php。为了简单起见,我更愿意在站点的实际编码中使用shortcode。
<?php
/**
* shortcode
* The library of shortcode class
* @author Swashata <[email protected]>
* @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);
}
}
很抱歉,如果这个问题被曲解了,我还在学习,我想我今天已经绞尽脑汁了。谢谢你的帮助!
插件页面如下:
http://wordpress.org/extend/plugins/wp-category-posts-list/
最合适的回答,由SO网友:MxmastaMills 整理而成
我找到了一个更简单的方法。我在循环中调用了这个PHP:
if ($paged == 0)
$offset = 0;
else
$offset = ($paged - 1) * 11;
global $post;
$category = get_the_category($post->ID);
$category = $category[0]->cat_ID;
$myposts = get_posts(array(\'numberposts\' => 11, \'offset\' => $offset, \'category__in\' => array($category), \'post__not_in\' => array($post->ID),\'post_status\'=>\'publish\'));
foreach($myposts as $post) :
setup_postdata($post);
然后能够使用CSS对结果进行样式化,并调用不同的元素,如\\u title();