我正在制作一个自定义帖子小部件,该小部件链接到自定义帖子类型评论,其中包含 boxart、dev、publicer 等信息,但它不会显示。有人可以告诉我我做错了什么吗?
看起来该请求在 singel.php 中的小部件中是不可能的,它是否有效但在其他小部件文件中却没有。
<?php
/**
* Plugin Name: Custom review informatio Widget
*/
add_action( 'widgets_init', 'box_review_load_widgets' );
function box_review_load_widgets() {
register_widget( 'BOX_Review_Widget' );
}
class BOX_review_Widget extends WP_Widget {
/**
* Widget setup.
*/
function BOX_Review_Widget() {
/* Widget settings. */
$widget_ops = array( 'classname' => 'box_review_widget', 'description' => __('Laat meer informatie over de game zien', 'box_review_widget') );
/* Widget control settings. */
$control_ops = array( 'width' => 250, 'height' => 350, 'id_base' => 'box_review_widget' );
/* Create the widget. */
$this->WP_Widget( 'box_review_widget', __('Box: Review informatie', 'box_review_widget'), $widget_ops, $control_ops );
}
/**
* How to display the widget on the screen.
*/
function widget( $args, $instance, $gameinfo, $reviewinfo ) {
extract( $args );
/* Our variables from the widget settings. */
$title = apply_filters('widget_title', $instance['title'] );
/* Before widget (defined by themes). */
echo $before_widget;
/* Display the widget title if one was input (before and after defined by themes). */
if ( $title )
echo $before_title . $title . $after_title;
?>
<div class="side-item">
<?php
function curPageURL() {
$pageURL = 'http';
if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80") {
$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
} else {
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
}
return $pageURL;
}
?>
<?php
$reviewinfo = get_post_meta($post->ID, 'gamebox', true);
foreach ($reviewinfo as $gameinfo ){
echo '<center><img src="' . $gameinfo['boxart'] . '" width="200" border="4" /></center><br />';
echo '<div class="fb-like" data-href="';
echo curPageURL() ;
echo '" data-send="false" data-width="283" data-show-faces="false"></div>';
echo '<strong>Genre: </strong>' . $gameinfo['genre'] . '<br />';
echo '<strong>Releasedatum: </strong>' . $gameinfo['releasedatum'] . '<br />';
echo '<strong>Franchise: </strong>' . $gameinfo['franchise'] . '<br />';
echo '<strong>Ontwikkelaar: </strong>' . $gameinfo['ontwikkelaar'] . '<br />';
echo '<strong>Uitgever: </strong>' . $gameinfo['uitgever'] . '<br />';
echo '<strong>Beschikbaar op: </strong><br />' . $gameinfo['beschikbaar-op'] . '<br />';
echo '<strong>PEGI: </strong>' . $gameinfo['pegi'] . '<br />';
}
?>
</p>
</div>
<?php
/* After widget (defined by themes). */
echo $after_widget;
}
/**
* Update the widget settings.
*/
function update( $new_instance, $old_instance ) {
$instance = $old_instance;
/* Strip tags for title and name to remove HTML (important for text inputs). */
$instance['title'] = strip_tags( $new_instance['title'] );
return $instance;
}
function form( $instance ) {
/* Set up some default widget settings. */
$defaults = array( 'title' => __('Game Informatie'));
$instance = wp_parse_args( (array) $instance, $defaults ); ?>
<!-- Widget Title: Text Input -->
<p>
<label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e('Title:', 'hybrid'); ?></label>
<input id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" value="<?php echo $instance['title']; ?>" style="width:90%;" />
</p>
<?php
}
}
?>