Advertisement
Guest User

Untitled

a guest
Mar 21st, 2012
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 13.47 KB | None | 0 0
  1. <?php
  2. if ( function_exists('register_sidebar') )
  3. register_sidebar(array(
  4. 'before_widget' => '',
  5. 'after_widget' => '',
  6. 'before_title' => '<p>',
  7. 'after_title' => '</p>',
  8. ));  
  9. function mySearchFilter($query) {
  10.     if ($query->is_search) {
  11.         $query->set('post__not_in', array(158, 150, 146, 138, 142, 12) ); // id of page or post
  12.     }
  13.     return $query;
  14. }
  15. add_filter('pre_get_posts','mySearchFilter');
  16.  
  17. function hls_set_query() {
  18.   $query  = attribute_escape(get_search_query());
  19.  
  20.   if(strlen($query) > 0){
  21.     echo '
  22.      <script type="text/javascript">
  23.        var hls_query  = "'.$query.'";
  24.      </script>
  25.    ';
  26.   }
  27. }
  28.  
  29. function hls_init_jquery() {
  30.   wp_enqueue_script('jquery');
  31. }
  32.  
  33. add_action('init', 'hls_init_jquery');
  34. add_action('wp_print_scripts', 'hls_set_query');
  35. //excerpts
  36.  
  37. function new_excerpt_length($length) {
  38.     return 7;
  39. }
  40. add_filter('excerpt_length', 'new_excerpt_length');
  41. function new_excerpt_more($more) {
  42.     return '...';
  43. }
  44. add_filter('excerpt_more', 'new_excerpt_more');
  45. //enables gallery css
  46. add_filter('gallery_style',
  47.     create_function(
  48.         '$css',
  49.         'return preg_replace("#<style type=\'text/css\'>(.*?)</style>#s", "", $css);'
  50.         )
  51.     ); //enables featured image
  52. add_theme_support('post-thumbnails');
  53.  
  54. //cusom post type newspost
  55. add_action('init', 'newspost_register_post_type');
  56.  
  57. function newspost_register_post_type() {
  58.     register_post_type('newspost', array(
  59.   'public' => true,
  60. 'label' => 'Newsposts',
  61. 'supports' => array('title', 'editor', 'thumbnail', 'excerpt'),
  62.         'taxonomies' => array('category', 'post_tag') // this is IMPORTANT
  63.     ));
  64. }
  65.  
  66. add_filter('pre_get_posts', 'query_post_type');
  67. function query_post_type($query) {
  68.   if(is_category() || is_tag()) {
  69.     $post_type = get_query_var('post_type');
  70.     if($post_type)
  71.         $post_type = $post_type;
  72.     else
  73.         $post_type = array('post','newspost'); // replace cpt to your custom post type
  74.     $query->set('post_type',$post_type);
  75.     return $query;
  76.     }
  77. }
  78.  
  79. //expand mime type options
  80. add_filter('upload_mimes', 'custom_upload_mimes'); 
  81. function custom_upload_mimes ( $existing_mimes=array() ) {
  82.  
  83. // Add file extension 'extension' with mime type 'mime/type'
  84. $existing_mimes['ies'] = 'application/octet-stream';
  85. $existing_mimes['dwg'] = 'application/acad';
  86.  
  87. // and return the new full result
  88. return $existing_mimes;
  89.  
  90.  
  91. }
  92.  
  93. //icons for attachments
  94. function get_attachment_icons($echo = false){
  95.     //PDF
  96.     if ( $files = get_children(array(   //do only if there are attachments of these qualifications
  97.      'post_parent' => get_the_ID(),
  98.      'post_type' => 'attachment',
  99.      'numberposts' => -1,
  100.      'post_mime_type' => 'application/pdf',  //MIME Type condition
  101.      ))){
  102.      foreach( $files as $file ){ //setup array for more than one file attachment
  103.         $file_title = wp_get_attachment_link($file->ID);
  104.         $file_link = wp_get_attachment_url($file->ID);    //get the url for linkage
  105.         $file_name_array=explode("/",$file_link);
  106.         $file_name=array_reverse($file_name_array);  //creates an array out of the url and grabs the filename
  107.         $sAttachmentString .= "<dt class='icon'>";
  108.         $sAttachmentString .= "<a href='$file_link'>";
  109.         $sAttachmentString .= "<img src='".get_bloginfo('template_directory')."/images/File-Extension-Pdf.png'/ width='16' height='16'>";
  110.         $sAttachmentString .= "</a>";
  111.         $sAttachmentString .= "<dd class='caption'>";
  112.         $sAttachmentString .= "<a href='$file_link'>$file_title</a>";
  113.         $sAttachmentString .= "</dd>";
  114.         $sAttachmentString .= "</dt>";
  115.         }
  116.     }
  117.     //DWG
  118.     if ( $files = get_posts(array(   //do only if there are attachments of these qualifications
  119.      'post_parent' => get_the_ID(),
  120.      'post_type' => 'attachment',
  121.      'numberposts' => -1,
  122.      'post_mime_type' => 'application/acad, application/x-acad, application/autocad_dwg, image/x-dwg, application/dwg, application/x-dwg, application/x-autocad, image/vnd.dwg, drawing/dwg',  //MIME Type condition
  123.      ))){
  124.      foreach( $files as $file ){ //setup array for more than one file attachment
  125.         $file_title = wp_get_attachment_link($file->ID);
  126.         $file_link = wp_get_attachment_url($file->ID);    //get the url for linkage
  127.         $file_name_array=explode("/",$file_link);
  128.         $file_name=array_reverse($file_name_array);  //creates an array out of the url and grabs the filename
  129.         $sAttachmentString .= "<dt class='icon'>";
  130.         $sAttachmentString .= "<a href='$file_link'>";
  131.         $sAttachmentString .= "<img src='".get_bloginfo('template_directory')."/images/File-Extension-Dwg.png'/ width='17' height='17'>";
  132.         $sAttachmentString .= "</a>";
  133.         $sAttachmentString .= "<dd class='caption'>";
  134.         $sAttachmentString .= "<a href='$file_link'>$file_title</a>";
  135.         $sAttachmentString .= "</dd>";
  136.         $sAttachmentString .= "</dt>";
  137.         }
  138.     }
  139.     //IES
  140.     if ( $files = get_children(array(   //do only if there are attachments of these qualifications
  141.      'post_parent' => get_the_ID(),
  142.      'post_type' => 'attachment',
  143.      'numberposts' => -1,
  144.      'post_mime_type' => 'application/octet-stream',  //MIME Type condition
  145.      ))){
  146.      foreach( $files as $file ){ //setup array for more than one file attachment
  147.         $file_title = wp_get_attachment_link($file->ID);
  148.         $file_link = wp_get_attachment_url($file->ID);    //get the url for linkage
  149.         $file_name_array=explode("/",$file_link);
  150.         $file_name=array_reverse($file_name_array);  //creates an array out of the url and grabs the filename
  151.         $sAttachmentString .= "<dt class='icon'>";
  152.         $sAttachmentString .= "<a href='$file_link'>";
  153.         $sAttachmentString .= "<img src='".get_bloginfo('template_directory')."/images/File-Extension-Ies.png'/ width='17' height='17'>";
  154.         $sAttachmentString .= "</a>";
  155.         $sAttachmentString .= "<dd class='caption'>";
  156.         $sAttachmentString .= "<a href='$file_link'>$file_title</a>";
  157.         $sAttachmentString .= "</dd>";
  158.         $sAttachmentString .= "</dt>";
  159.         }
  160.     }
  161.     //Excel Documents
  162.     if ( $files = get_children(array(   //do only if there are attachments of these qualifications
  163.      'post_parent' => get_the_ID(),
  164.      'post_type' => 'attachment',
  165.      'numberposts' => -1,
  166.      'post_mime_type' => 'application/vnd.ms-excel',  //MIME Type condition
  167.      ))){
  168.      foreach( $files as $file ){ //setup array for more than one file attachment
  169.         $file_title = wp_get_attachment_link($file->ID);
  170.         $file_link = wp_get_attachment_url($file->ID);    //get the url for linkage
  171.         $file_name_array=explode("/",$file_link);
  172.         $file_name=array_reverse($file_name_array);  //creates an array out of the url and grabs the filename
  173.         $sAttachmentString .= "<dt class='icons'>";
  174.         $sAttachmentString .= "<a href='$file_link'>";
  175.         $sAttachmentString .= "<img src='".get_bloginfo('template_directory')."/images/File-Extension-Xls.png'/>";
  176.         $sAttachmentString .= "</a>";
  177.         $sAttachmentString .= "<br>";
  178.         $sAttachmentString .= "<a href='$file_link'>$file_title</a>";
  179.         $sAttachmentString .= "</dt>";
  180.         }
  181.     }
  182.     //Zipped Files
  183.     if ( $files = get_children(array(   //do only if there are attachments of these qualifications
  184.      'post_parent' => get_the_ID(),
  185.      'post_type' => 'attachment',
  186.      'numberposts' => -1,
  187.      'post_mime_type' => 'application/zip',  //MIME Type condition
  188.      ))){
  189.      foreach( $files as $file ){ //setup array for more than one file attachment
  190.         $file_title = wp_get_attachment_link($file->ID);
  191.         $file_link = wp_get_attachment_url($file->ID);    //get the url for linkage
  192.         $file_name_array=explode("/",$file_link);
  193.         $file_name=array_reverse($file_name_array);  //creates an array out of the url and grabs the filename
  194.         $sAttachmentString .= "<dt class='icons'>";
  195.         $sAttachmentString .= "<a href='$file_link'>";
  196.         $sAttachmentString .= "<img src='".get_bloginfo('template_directory')."/images/File-Extension-Zip.png'/>";
  197.         $sAttachmentString .= "</a>";
  198.         $sAttachmentString .= "<br>";
  199.         $sAttachmentString .= "<a href='$file_link'>$file_title</a>";
  200.         $sAttachmentString .= "</dt>";
  201.         }
  202.     }
  203.  
  204. if($echo){
  205.     echo $sAttachmentString;
  206.   }
  207.   return $sAttachmentString;
  208. }
  209. add_shortcode('attachment icons', 'get_attachment_icons');
  210.  
  211.  
  212.  
  213. ////////////////////
  214.  
  215. //icons for attachments of parent
  216. function get_sibling_icons(){
  217.     //PDF
  218.     global $post;
  219.     if ( $files = get_posts(array(   //do only if there are attachments of these qualifications
  220.      'post_parent' => $post->post_parent,
  221.      'post_type' => 'attachment',
  222.      'numberposts' => -1,
  223.      'post_mime_type' => 'application/pdf',  //MIME Type condition
  224.      ))){
  225.      foreach( $files as $file ){ //setup array for more than one file attachment
  226.         $file_title = wp_get_attachment_link($file->ID);
  227.         $file_link = wp_get_attachment_url($file->ID);    //get the url for linkage
  228.         $file_name_array=explode("/",$file_link);
  229.         $file_name=array_reverse($file_name_array);  //creates an array out of the url and grabs the filename
  230.         $sAttachmentString .= "<dt class='icon'>";
  231.         $sAttachmentString .= "<a href='$file_link'>";
  232.         $sAttachmentString .= "<img src='".get_bloginfo('template_directory')."/images/File-Extension-Pdf.png'/ width='16' height='16'>";
  233.         $sAttachmentString .= "</a>";
  234.         $sAttachmentString .= "<dd class='caption'>";
  235.         $sAttachmentString .= "<a href='$file_link'>$file_title</a>";
  236.         $sAttachmentString .= "</dd>";
  237.         $sAttachmentString .= "</dt>";
  238.         }
  239.     }
  240.     //DWG
  241.     global $post;
  242.     if ( $files = get_posts(array(   //do only if there are attachments of these qualifications
  243.      'post_parent' => $post->post_parent,
  244.      'post_type' => 'attachment',
  245.      'numberposts' => -1,
  246.      'post_mime_type' => 'application/acad, application/x-acad, application/autocad_dwg, image/x-dwg, application/dwg, application/x-dwg, application/x-autocad, image/vnd.dwg, drawing/dwg',  //MIME Type condition
  247.      ))){
  248.      foreach( $files as $file ){ //setup array for more than one file attachment
  249.         $file_title = wp_get_attachment_link($file->ID);
  250.         $file_link = wp_get_attachment_url($file->ID);    //get the url for linkage
  251.         $file_name_array=explode("/",$file_link);
  252.         $file_name=array_reverse($file_name_array);  //creates an array out of the url and grabs the filename
  253.         $sAttachmentString .= "<dt class='icon'>";
  254.         $sAttachmentString .= "<a href='$file_link'>";
  255.         $sAttachmentString .= "<img src='".get_bloginfo('template_directory')."/images/File-Extension-Dwg.png'/ width='17' height='17'>";
  256.         $sAttachmentString .= "</a>";
  257.         $sAttachmentString .= "<dd class='caption'>";
  258.         $sAttachmentString .= "<a href='$file_link'>$file_title</a>";
  259.         $sAttachmentString .= "</dd>";
  260.         $sAttachmentString .= "</dt>";
  261.         }
  262.     }
  263.     //IES
  264.     global $post;
  265.     if ( $files = get_posts(array(   //do only if there are attachments of these qualifications
  266.      'post_parent' => $post->post_parent,
  267.      'post_type' => 'attachment',
  268.      'numberposts' => -1,
  269.      'post_mime_type' => 'application/octet-stream',  //MIME Type condition
  270.      ))){
  271.      foreach( $files as $file ){ //setup array for more than one file attachment
  272.         $file_title = wp_get_attachment_link($file->ID);
  273.         $file_link = wp_get_attachment_url($file->ID);    //get the url for linkage
  274.         $file_name_array=explode("/",$file_link);
  275.         $file_name=array_reverse($file_name_array);  //creates an array out of the url and grabs the filename
  276.         $sAttachmentString .= "<dt class='icon'>";
  277.         $sAttachmentString .= "<a href='$file_link'>";
  278.         $sAttachmentString .= "<img src='".get_bloginfo('template_directory')."/images/File-Extension-Ies.png'/ width='17' height='17'>";
  279.         $sAttachmentString .= "</a>";
  280.         $sAttachmentString .= "<dd class='caption'>";
  281.         $sAttachmentString .= "<a href='$file_link'>$file_title</a>";
  282.         $sAttachmentString .= "</dd>";
  283.         $sAttachmentString .= "</dt>";
  284.         }
  285.     }
  286.     //Excel Documents
  287.         global $post;
  288.     if ( $files = get_posts(array(   //do only if there are attachments of these qualifications
  289.      'post_parent' => $post->post_parent,
  290.      'post_type' => 'attachment',
  291.      'numberposts' => -1,
  292.      'post_mime_type' => 'application/vnd.ms-excel',  //MIME Type condition
  293.      ))){
  294.      foreach( $files as $file ){ //setup array for more than one file attachment
  295.         $file_title = wp_get_attachment_link($file->ID);
  296.         $file_link = wp_get_attachment_url($file->ID);    //get the url for linkage
  297.         $file_name_array=explode("/",$file_link);
  298.         $file_name=array_reverse($file_name_array);  //creates an array out of the url and grabs the filename
  299.         $sAttachmentString .= "<dt class='icons'>";
  300.         $sAttachmentString .= "<a href='$file_link'>";
  301.         $sAttachmentString .= "<img src='".get_bloginfo('template_directory')."/images/File-Extension-Xls.png'/>";
  302.         $sAttachmentString .= "</a>";
  303.         $sAttachmentString .= "<br>";
  304.         $sAttachmentString .= "<a href='$file_link'>$file_title</a>";
  305.         $sAttachmentString .= "</dt>";
  306.         }
  307.     }
  308.     //Zipped Files
  309.         global $post;
  310.     if ( $files = get_posts(array(   //do only if there are attachments of these qualifications
  311.      'post_parent' => $post->post_parent,
  312.      'post_type' => 'attachment',
  313.      'numberposts' => -1,
  314.      'post_mime_type' => 'application/zip',  //MIME Type condition
  315.      ))){
  316.      foreach( $files as $file ){ //setup array for more than one file attachment
  317.         $file_title = wp_get_attachment_link($file->ID);
  318.         $file_link = wp_get_attachment_url($file->ID);    //get the url for linkage
  319.         $file_name_array=explode("/",$file_link);
  320.         $file_name=array_reverse($file_name_array);  //creates an array out of the url and grabs the filename
  321.         $sAttachmentString .= "<dt class='icons'>";
  322.         $sAttachmentString .= "<a href='$file_link'>";
  323.         $sAttachmentString .= "<img src='".get_bloginfo('template_directory')."/images/File-Extension-Zip.png'/>";
  324.         $sAttachmentString .= "</a>";
  325.         $sAttachmentString .= "<br>";
  326.         $sAttachmentString .= "<a href='$file_link'>$file_title</a>";
  327.         $sAttachmentString .= "</dt>";
  328.         }
  329.     }
  330. if($echo){
  331.     echo $sAttachmentString;
  332.   }
  333.   return $sAttachmentString;
  334. }
  335.  
  336. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement