Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // adiciciona o thickbox no campo imagem
- add_action( 'admin_footer', 'wpmidia_link_image_scripts' );
- function wpmidia_link_image_scripts(){
- global $current_screen;
- if( $current_screen->id == 'link' ):
- add_thickbox();
- ?>
- <script type="text/javascript">
- jQuery(document).ready(function($) {
- var fileInput;
- var header_clicked = false;
- $('#link_image').click(function() {
- fileInput = $('#link_image');
- //formfield = jQuery('#upload_image').attr('name');
- //post_id = jQuery('#post_ID').val();
- tb_show('', 'media-upload.php?type=image&TB_iframe=true');
- header_clicked = true;
- return false;
- });
- window.original_send_to_editor = window.send_to_editor;
- window.send_to_editor = function(html){
- if (fileInput) { console.log(html);
- fileurl = $('img',html).attr('src');
- //fileurl = $(html).attr('src');
- console.log(fileurl);
- fileInput.val(fileurl);
- header_clicked = false;
- tb_remove();
- } else {
- window.original_send_to_editor(html);
- }
- };
- });
- </script>
- <?php
- endif;
- }
- /********************************************************
- Shortcode
- Como usar: dentro do post ou página, coloque:
- [links]
- Se quiser escolher qual categoria de links, coloque:
- [links category=1] -- 1, 2 ou 3... será o ID da categoria de links =)
- ********************************************************/
- function wpmidia_links_shortcode( $atts ){
- extract( shortcode_atts(
- array( 'category' => 2 ), $atts
- )
- );
- $bookmark = get_bookmarks(array('category' => $category));
- if( $bookmark ){
- echo '<div class="bookmark clearfix">';
- foreach( $bookmark as $link ){
- echo '<div class="link">';
- if( !empty($link->link_image) ){
- echo ' <div class="link_image"><img src="'.$link->link_image.'" width="150px" height="150px" /></div>';
- }
- echo ' <div class="link_desc"><p>'.$link->link_description.'</p><p>Link: <a href="'.$link->link_url.'" target="_blank">'.$link->link_name.'</a></p></div>';
- echo '</div>';
- }
- echo '</div>';
- } else {
- // mensagem se não houver links cadastrados...
- echo __('<p>Nenhum link cadastrado na base de dados</p>', 'labterra');
- }
- }
- add_shortcode( 'links', 'wpmidia_links_shortcode' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement