所以我决定使用子页面快捷码插件,这个插件可以提取子页面的ID、标题、缩略图、摘录等。插件作者解释说,他鼓励定制自己的插件。
模板作者描述说,你应该能够构建自己的模板,我不完全理解这一点,但我已经能够更改现有模板,使其生成<li>
每个孩子的。现在,我需要为所有列表项添加一个容器,它看起来像
<div class="row-fluid">
<ul class="thumbnails">
<li class="span3">
<li class="span3">
<li class="span3">
<li class="span3">
</ul>
</div>
编辑:我添加了建议的更改,但出现以下错误:
Warning: call_user_func_array()
要求参数1是有效的回调函数
\'wpse_113253_child_pages_shortcode_template\'
找不到或函数名无效。。。。
子页面快捷码插件的源代码以及我的自定义设置和建议的修复:
<?php
/*
Plugin Name: Child Pages Shortcode
Author: Takayuki Miyauchi
Plugin URI: http://wpist.me/wp/child-pages-shortcode/
Description: You can use shortcode for display child pages from the page.
Version: 1.7.0
Author URI: http://wpist.me/
Domain Path: /languages
Text Domain: child-pages-shortcode
*/
new childPagesShortcode();
class childPagesShortcode {
private $ver = \'1.1.4\';
function __construct()
{
add_shortcode("child_pages", array(&$this, "shortcode"));
add_action("init", array(&$this, "init"));
add_action("wp_enqueue_scripts", array(&$this, "wp_enqueue_scripts"));
add_filter("plugin_row_meta", array(&$this, "plugin_row_meta"), 10, 2);
// Wrap <li> tags around each template item.
add_filter( \'child-pages-shortcode-template\', \'wpse_113253_child_pages_shortcode_template\' );
// Wrap <div> and <ul> tags around everything.
add_filter( \'child-pages-shortcode-output\',\'wpse_113253_child_pages_shortcode_output\' );
}
public function init()
{
add_post_type_support(\'page\', \'excerpt\');
}
public function wp_enqueue_scripts()
{
$css = apply_filters(
"child-pages-shortcode-stylesheet",
plugins_url("style.css", __FILE__)
);
wp_register_style(
\'child-pages-shortcode-css\',
$css,
array(),
$this->ver,
\'all\'
);
wp_enqueue_style(\'child-pages-shortcode-css\');
$js = apply_filters(
"child-pages-shortcode-js",
plugins_url("script.js", __FILE__)
);
wp_register_script(
\'child-pages-shortcode\',
$js,
array(\'jquery\'),
$this->ver,
false
);
wp_enqueue_script(\'child-pages-shortcode\');
}
public function shortcode($p, $template = null)
{
if( !isset($p[\'id\']) || !intval($p[\'id\']) ){
$p[\'id\'] = get_the_ID();
}
if (!isset($p[\'size\']) || !$p[\'size\']) {
$p[\'size\'] = \'thumbnail\';
}
if (!isset($p[\'width\']) || !intval($p[\'width\'])) {
$p[\'width\'] = "50%";
}
if (!isset($p[\'disable_shortcode\']) || !$p[\'disable_shortcode\']) {
add_filter("child-pages-shortcode-output", "do_shortcode");
}
return $this->display($p, $template);
}
private function display($p, $block_template)
{
global $post;
$html = \'\';
if ($block_template) {
$template = $block_template;
$template = str_replace(\'<p>\', \'\', $template);
$template = str_replace(\'</p>\', \'\', $template);
$template = apply_filters(
\'child-pages-shortcode-template\',
$template,
$p
);
} else {
$template = apply_filters(
\'child-pages-shortcode-template\',
$this->get_template(),
$p
);
$html = sprintf(
\'<div class="row-fluid">\'
);
}
$args = array(
\'post_status\' => \'publish\',
\'post_type\' => \'page\',
\'post_parent\' => $p[\'id\'],
\'orderby\' => \'menu_order\',
\'order\' => \'ASC\',
\'nopaging\' => true,
);
$args = apply_filters(\'child-pages-shortcode-query\', $args, $p);
$pages = get_posts($args);
foreach ($pages as $post) {
setup_postdata($post);
$post = apply_filters(\'child_pages_shortcode_post\', $post);
$url = get_permalink($post->ID);
$img = get_the_post_thumbnail($post->ID, $p[\'size\']);
$img = preg_replace( \'/(width|height)="\\d*"\\s/\', "", $img);
$tpl = $template;
$tpl = str_replace(\'%width%\', esc_attr($p[\'width\']), $tpl);
$tpl = str_replace(\'%post_id%\', intval($post->ID), $tpl);
$tpl = str_replace(\'%post_title%\', $post->post_title, $tpl);
$tpl = str_replace(\'%post_url%\', esc_url($url), $tpl);
$tpl = str_replace(\'%post_thumb%\', $img, $tpl);
if (isset($p[\'disabled_excerpt_filters\']) && $p[\'disabled_excerpt_filters\']) {
$tpl = str_replace(\'%post_excerpt%\', $post->post_excerpt, $tpl);
} else {
$tpl = str_replace(\'%post_excerpt%\', get_the_excerpt(), $tpl);
}
$html .= $tpl;
}
wp_reset_postdata();
if (!$block_template) {
$html .= \'</div><!--row-fluid Child Pages Shortcode-->\';
}
return apply_filters("child-pages-shortcode-output", $html);
}
private function get_template()
{
$html = "\\n";
$html .= \'<li class="span3">\';
$html .= \'<div id="child_page-%post_id%" class="thumbnail">\';
$html .= \'<div class="post_thumb"><a href="%post_url%">%post_thumb%</a></div>\';
$html .= \'<div class="caption">\';
$html .= \'<h4><a href="%post_url%">%post_title%</a></h4>\';
$html .= \'<p>%post_excerpt%</p>\';
$html .= \'</div><!-- .caption -->\';
$html .= \'</div><!-- .child_page-container -->\';
$html .= \'</div><!-- #child_page-%post_id%" -->\';
$html .= "\\n";
if ($tpl = get_post_meta(get_the_ID(), \'child-pages-template\', true)) {
$html = $tpl;
}
return $html;
}
/**
* Wrap <li> tags around each template item.
*/
function wpse_113253_child_pages_shortcode_template( $template ) {
return "<li>$template</li>\\n";
}
/**
* Wrap a <div> and <ul> tags around everything.
*/
function wpse_113253_child_pages_shortcode_output( $html ) {
return "
<div class=\'row-fluid\'>
<ul class=\'thumbnails\'>
$html
</ul><!-- end .thumbnails -->
</div><!-- end .row-fluid -->
";
}
public function plugin_row_meta($links, $file)
{
$pname = plugin_basename(__FILE__);
if ($pname === $file) {
$links[] = sprintf(
\'<a href="%s">Donate</a>\',
\'https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclickhosted_button_id=8RADH554RPKDU\'
);
}
return $links;
}
} // end childPagesShortcode()
// eof