Sometimes it is necessary to write widget that will display post data for an associated single post or page. Lets say a map associated with some custom fields on a post.
This snippet should help, this is an example and just part of the widget code, see http://codex.wordpress.org/Widgets_API on the full Widget experience
/** * Front-end display of widget. * * @see WP_Widget::widget() * * @param array $args Widget arguments. * @param array $instance Saved values from database. */ public function widget( $args, $instance ) { if (is_single()) { echo $args['before_widget']; global $post; echo the_ID(); echo $args['after_widget']; } }
by
Tags:
Leave a Reply