post->ID; //$post_id=the_ID(); if(is_page()){ $post_id = $GLOBALS['post']->ID;} $argschildren = array( 'post_type' => 'attachment', 'numberposts' => -1, //'post_mime_type' => 'application/pdf', 'post_parent' => $post_id, 'orderby' => 'menu_order ID' ); //echo 'variable post_id '.$post_id.'
'; //echo 'the ID '; //the_ID(); $parent_permalink = get_permalink( $post_id); $attachments = get_children($argschildren); if ($attachments) { // TEST Y a-t-il des attachments autres que des images? $count=0; foreach ($attachments as $attachment) { if (substr($attachment->post_mime_type, 0, 5) != 'image'){$count++;} } if ($count){ echo $before_widget; echo '
'.$before_title . $options['title1']; if($options['title2']!=''){echo '
'.$options['title2'];} echo $after_title.'
'; foreach ($attachments as $attachment) { if (substr($attachment->post_mime_type, 0, 5) != 'image'){ ?>
post_title; ?>
'; echo $after_widget; } } } } endif; function attachement_widget_control() { $options = $newoptions = get_option('attachement_widget'); // get options // set new options if( $_POST['attachement-widget-submit'] ) { $newoptions['title1'] = strip_tags( stripslashes($_POST['attachement-widget-title1']) ); $newoptions['title2'] = strip_tags( stripslashes($_POST['attachement-widget-title2']) ); } // update options if needed if( $options != $newoptions ) { $options = $newoptions; update_option('attachement_widget', $options); } // output echo '

'._e('Title'); echo ''; echo '

'; echo '

'._e('Title').' 2'; echo ''; echo '

'; echo ''; } // activate and deactivate plugin function attachement_activate() { // options, default values $options = array( 'widget' => array( 'title1' => 'Files attached', 'title2' => 'to this post' ) ); // register option add_option( 'attachement_widget', $options['widget'] ); // activated return; } function attachement_deactivate() { // unregister option delete_option('attachement_widget'); // deactivated return; } // initialization function attachement_init() { // register widget $class['classname'] = 'attachement_widget'; wp_register_sidebar_widget('attachement', __('Attachement'), 'attachement_widget', $class); wp_register_widget_control('attachement', __('Attachement'), 'attachement_widget_control', 'width=200&height=200'); // initialization done return; } // actions add_action( 'activate_'.plugin_basename(__FILE__), 'attachement_activate' ); add_action( 'deactivate_'.plugin_basename(__FILE__), 'attachement_deactivate' ); add_action( 'init', 'attachement_init'); ?>