这是我的第一个插件,或多或少是从头开始的,我想我几乎可以让它工作了,但还没有完全实现。该插件的目的是获取所有子页面,显示它们的缩略图、标题等。现在我编写了插件,它给了我0个输出。。。为什么?可能有很多事情我都做错了,但我决定开始在get\\u页面部分寻找错误。如果我添加print_r(\'$child_query\')
和$child_query = get_pages($args);
这不应该至少输出一些东西吗?
问为什么print_r(\'$child_query\')
不返回任何内容?
我的代码有问题的代码。。。
<?php
/*
Plugin Name: Child Pages Querry
Author: Sten Winroth
Plugin URI:
Description:
Version: 1.0
Author URI:
Domain Path: /languages
Text Domain:
*/
new childPagesQuerry();
class childPagesQuerry {
private $ver = \'1.0\';
function __construct(){
add_action("init", array(&$this, "init"));
add_shortcode(\'child_query\', \'child_query_frontend\');
}
public function init()
{
add_post_type_support(\'page\', \'excerpt\');
}
private function child_query(){
// Determine parent page ID
$parent_page_id = ( \'0\' != $post->post_parent ? $post->post_parent : $post->ID );
// Get child pages as array
$args = array(
\'child_of\' => $parent_page_id,
\'post_type\' => \'page\',
\'orderby\' => \'menu_order\',
\'order\' => \'ASC\',
\'posts_per_page\' => 100,
);
$child_query = get_pages($args);
print_r($child_query);
$child_pages = array();
while ( $child_query->have_posts()) {
$child_query->the_post();
if ( \'\' != get_the_title() ) {
$title = get_the_title();
$excerpt = get_the_excerpt();
$id = get_the_ID();
$thumbnail = get_the_post_thumbnail(\'(thumbnail\');
$permalink = get_permalink();
$child_pages[] = array(\'title\' => $title, \'excerpt\' => $excerpt, \'id\' => $id, \'thumbnail\' => $thumbnail, \'permalink\' => $permalink);
}
}
} //end child_query
private function child_query_frontend($child_pages) {
echo \'<div class="row-fluid">\';
echo \'<ul class="thumbnails">\';
foreach ($child_pages as $key => $value) {
?>
<li class="span3">
<div class="thumbnail">
<img src="<?php echo $value[\'thumbnail\']; ?>" alt="" height="42" width="42">
<div class="caption">
<h3><?php echo $value[\'title\']; ?></h3>
<p><?php echo $value[\'excerpt\'] ?></p>
<p><a class="btn btn-primary" href="<?php echo $value[\'permalink\']; ?>">Läs mer.</a></p>
</div>
</div>
</li>
<?php }
echo \'</ul><!--thumbnails-->\';
echo \'</div><!--row-fluid-->\';
} //end frontend
}// end class