我真的一点线索都没有。
我一直在忙着开发一个自定义WordPress站点,使用自定义插件和小部件实现一些自定义功能,但我遇到了一个障碍。
无论我做什么,我都无法运行下面插件中的小部件。
http://pastebin.com/HzZwyi3T
该插件的结构与另一个非常相似的插件完全相同。我已经将小部件功能复制并粘贴到主题页本身,所以我知道它可以工作。我试过重复一些调试,但都没能显示出来。这个小部件直接拒绝运行——但是自定义帖子类型正在注册,所以这个插件正在运行,而不是小部件组件。
哦,页面顶部有一个有效的插件声明,我只是没有复制并粘贴到这里。
在这一点上,任何帮助都将不胜感激!
编辑:让我进一步澄清。小部件本身实际上显示在外观>小部件中。但在页面本身上,没有显示任何内容,甚至没有回声。
编辑:要求我将代码粘贴到此处。可以在下面找到:
<?php
/************************************************
INITIAL THEME REGISTRATIONS
************************************************/
// add the project post type
add_action(\'init\', \'codex_news_release_init\');
// change the default WordPress messages associated with this post type
add_filter(\'post_updated_messages\', \'codex_news_release_updated_messages\');
// this action calls the function to register the widget functionality and controls
add_action("plugins_loaded", "widget_news_releases_manager_init");
// this function registers the widget functionality and controls
function widget_news_releases_manager_init() {
wp_register_sidebar_widget(ALL_NEWS_RELEASES_WIDGET_ID,
__(\'All News Releases\'), \'widget_all_news_releases\');
}
/************************************************
REGISTER THE \'NEWS RELEASE\' POST TYPE
************************************************/
// this function will register the \'News Release\' post type and...
// ...change some of the default button text to reflect it.
function codex_news_release_init() {
$labels = array(
\'name\' => _x(\'News Release\', \'post type general name\'),
\'singular_name\' => _x(\'News Release\', \'post type singular name\'),
\'menu_name\' => _x(\'News Releases\', \'admin menu\'),
\'name_admin_bar\' => _x(\'News Release\', \'add new on admin bar\'),
\'add_new\' => _x(\'Add New\', \'news_release\'),
\'add_new_item\' => __(\'Add New News Release\'),
\'new_item\' => __(\'New News Release\'),
\'edit_item\' => __(\'Edit News Release\'),
\'view_item\' => __(\'View News Release\'),
\'all_items\' => __(\'All News Releases\'),
\'search_items\' => __(\'Search News Releases\'),
\'parent_item_colon\' => __(\'Parent News Releases:\'),
\'not_found\' => __(\'No news releases found.\'),
\'not_found_in_trash\' => __(\'No news releases found in Trash.\')
);
$args = array(
\'public\' => true,
\'labels\' => $labels,
\'rewrite\' => array(\'slug\' => \'news_release\'),
\'supports\' => array(\'title\'),
);
register_post_type( \'news_release\', $args );
}
// this function will change the default WordPress messages associated with this post type...
// ...from generic \'post updated\', for example, to a more appropriate \'news release updated\'
function codex_news_release_updated_messages($messages) {
$post = get_post();
$post_type = get_post_type( $post );
$post_type_object = get_post_type_object( $post_type );
$messages[\'news_release\'] = array(
0 => \'\', // Unused. Messages start at index 1.
1 => __(\'News Release updated.\'),
2 => __(\'Custom field updated.\'),
3 => __(\'Custom field deleted.\'),
4 => __(\'News Release updated.\'),
/* translators: %s: date and time of the revision */
5 => isset($_GET[\'revision\'] ) ? sprintf( __( \'News Release restored to revision from %s\'), wp_post_revision_title( (int) $_GET[\'revision\'], false ) ) : false,
6 => __(\'News Release published.\'),
7 => __(\'News Release saved.\'),
8 => __(\'News Release submitted.\'),
9 => sprintf(
__( \'News Release scheduled for: <strong>%1$s</strong>.\'),
// translators: Publish box date format, see http://php.net/date
date_i18n( __( \'M j, Y @ G:i\'), strtotime( $post->post_date ) )
),
10 => __( \'News Release draft updated.\')
);
if ( $post_type_object->publicly_queryable ) {
$permalink = get_permalink( $post->ID );
$view_link = sprintf(\' <a href="%s">%s</a>\', esc_url($permalink ), __(\'View news release\'));
$messages[$post_type][1] .= $view_link;
$messages[$post_type][6] .= $view_link;
$messages[$post_type][9] .= $view_link;
$preview_permalink = add_query_arg(\'preview\', \'true\', $permalink);
$preview_link = sprintf(\' <a target="_blank" href="%s">%s</a>\', esc_url($preview_permalink ), __(\'Preview news release\'));
$messages[$post_type][8] .= $preview_link;
$messages[$post_type][10] .= $preview_link;
}
return $messages;
}
/************************************************
WIDGET FUNCTIONALITY
************************************************/
function widget_all_news_releases(){
echo "WAAAAZZZZUP???!?!?!!!?!?";
wp_enqueue_style(\'all-news-releases-style\', plugins_url(\'styles/all_news_releases_style.css\', __FILE__));
display_all_news_releases();
}
function display_all_news_releases(){
$args = array(
\'posts_per_page\' => -1,
\'post_type\' => \'news_release\',
\'post_status\' => \'publish\'
);
query_posts($args);
$i = 0;
while (have_posts()) : the_post(); ?>
<?php
$i++;
if($i % 2 == 0){
$open = false;
$close = true;
} else {
$open = true;
$close = false;
}
$custom_fields = get_post_custom();
?>
<?php if($open == true) : ?>
<div class="row even_less_padding">
<?php endif; ?>
<div class="small-12 large-6 columns">
<a target="_blank" href="<?php the_permalink(); ?>">
<h4 class="small_story_head blue_dark"><?php the_title(); ?></h4>
</a>
</div>
<?php if($open == false) : ?>
</div>
<?php endif; ?>
<?php endwhile;
if($i % 2 != 0) : ?>
</div>
<?php endif;
wp_reset_query();
}
?>