Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- if ( function_exists('register_sidebar') )
- register_sidebar(array(
- 'before_widget' => '',
- 'after_widget' => '',
- 'before_title' => '<p>',
- 'after_title' => '</p>',
- ));
- function mySearchFilter($query) {
- if ($query->is_search) {
- $query->set('post__not_in', array(158, 150, 146, 138, 142, 12) ); // id of page or post
- }
- return $query;
- }
- add_filter('pre_get_posts','mySearchFilter');
- function hls_set_query() {
- $query = attribute_escape(get_search_query());
- if(strlen($query) > 0){
- echo '
- <script type="text/javascript">
- var hls_query = "'.$query.'";
- </script>
- ';
- }
- }
- function hls_init_jquery() {
- wp_enqueue_script('jquery');
- }
- add_action('init', 'hls_init_jquery');
- add_action('wp_print_scripts', 'hls_set_query');
- //excerpts
- function new_excerpt_length($length) {
- return 7;
- }
- add_filter('excerpt_length', 'new_excerpt_length');
- function new_excerpt_more($more) {
- return '...';
- }
- add_filter('excerpt_more', 'new_excerpt_more');
- //enables gallery css
- add_filter('gallery_style',
- create_function(
- '$css',
- 'return preg_replace("#<style type=\'text/css\'>(.*?)</style>#s", "", $css);'
- )
- ); //enables featured image
- add_theme_support('post-thumbnails');
- //cusom post type newspost
- add_action('init', 'newspost_register_post_type');
- function newspost_register_post_type() {
- register_post_type('newspost', array(
- 'public' => true,
- 'label' => 'Newsposts',
- 'supports' => array('title', 'editor', 'thumbnail', 'excerpt'),
- 'taxonomies' => array('category', 'post_tag') // this is IMPORTANT
- ));
- }
- add_filter('pre_get_posts', 'query_post_type');
- function query_post_type($query) {
- if(is_category() || is_tag()) {
- $post_type = get_query_var('post_type');
- if($post_type)
- $post_type = $post_type;
- else
- $post_type = array('post','newspost'); // replace cpt to your custom post type
- $query->set('post_type',$post_type);
- return $query;
- }
- }
- //expand mime type options
- add_filter('upload_mimes', 'custom_upload_mimes');
- function custom_upload_mimes ( $existing_mimes=array() ) {
- // Add file extension 'extension' with mime type 'mime/type'
- $existing_mimes['ies'] = 'application/octet-stream';
- $existing_mimes['dwg'] = 'application/acad';
- // and return the new full result
- return $existing_mimes;
- }
- //icons for attachments
- function get_attachment_icons($echo = false){
- //PDF
- if ( $files = get_children(array( //do only if there are attachments of these qualifications
- 'post_parent' => get_the_ID(),
- 'post_type' => 'attachment',
- 'numberposts' => -1,
- 'post_mime_type' => 'application/pdf', //MIME Type condition
- ))){
- foreach( $files as $file ){ //setup array for more than one file attachment
- $file_title = wp_get_attachment_link($file->ID);
- $file_link = wp_get_attachment_url($file->ID); //get the url for linkage
- $file_name_array=explode("/",$file_link);
- $file_name=array_reverse($file_name_array); //creates an array out of the url and grabs the filename
- $sAttachmentString .= "<dt class='icon'>";
- $sAttachmentString .= "<a href='$file_link'>";
- $sAttachmentString .= "<img src='".get_bloginfo('template_directory')."/images/File-Extension-Pdf.png'/ width='16' height='16'>";
- $sAttachmentString .= "</a>";
- $sAttachmentString .= "<dd class='caption'>";
- $sAttachmentString .= "<a href='$file_link'>$file_title</a>";
- $sAttachmentString .= "</dd>";
- $sAttachmentString .= "</dt>";
- }
- }
- //DWG
- if ( $files = get_posts(array( //do only if there are attachments of these qualifications
- 'post_parent' => get_the_ID(),
- 'post_type' => 'attachment',
- 'numberposts' => -1,
- '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
- ))){
- foreach( $files as $file ){ //setup array for more than one file attachment
- $file_title = wp_get_attachment_link($file->ID);
- $file_link = wp_get_attachment_url($file->ID); //get the url for linkage
- $file_name_array=explode("/",$file_link);
- $file_name=array_reverse($file_name_array); //creates an array out of the url and grabs the filename
- $sAttachmentString .= "<dt class='icon'>";
- $sAttachmentString .= "<a href='$file_link'>";
- $sAttachmentString .= "<img src='".get_bloginfo('template_directory')."/images/File-Extension-Dwg.png'/ width='17' height='17'>";
- $sAttachmentString .= "</a>";
- $sAttachmentString .= "<dd class='caption'>";
- $sAttachmentString .= "<a href='$file_link'>$file_title</a>";
- $sAttachmentString .= "</dd>";
- $sAttachmentString .= "</dt>";
- }
- }
- //IES
- if ( $files = get_children(array( //do only if there are attachments of these qualifications
- 'post_parent' => get_the_ID(),
- 'post_type' => 'attachment',
- 'numberposts' => -1,
- 'post_mime_type' => 'application/octet-stream', //MIME Type condition
- ))){
- foreach( $files as $file ){ //setup array for more than one file attachment
- $file_title = wp_get_attachment_link($file->ID);
- $file_link = wp_get_attachment_url($file->ID); //get the url for linkage
- $file_name_array=explode("/",$file_link);
- $file_name=array_reverse($file_name_array); //creates an array out of the url and grabs the filename
- $sAttachmentString .= "<dt class='icon'>";
- $sAttachmentString .= "<a href='$file_link'>";
- $sAttachmentString .= "<img src='".get_bloginfo('template_directory')."/images/File-Extension-Ies.png'/ width='17' height='17'>";
- $sAttachmentString .= "</a>";
- $sAttachmentString .= "<dd class='caption'>";
- $sAttachmentString .= "<a href='$file_link'>$file_title</a>";
- $sAttachmentString .= "</dd>";
- $sAttachmentString .= "</dt>";
- }
- }
- //Excel Documents
- if ( $files = get_children(array( //do only if there are attachments of these qualifications
- 'post_parent' => get_the_ID(),
- 'post_type' => 'attachment',
- 'numberposts' => -1,
- 'post_mime_type' => 'application/vnd.ms-excel', //MIME Type condition
- ))){
- foreach( $files as $file ){ //setup array for more than one file attachment
- $file_title = wp_get_attachment_link($file->ID);
- $file_link = wp_get_attachment_url($file->ID); //get the url for linkage
- $file_name_array=explode("/",$file_link);
- $file_name=array_reverse($file_name_array); //creates an array out of the url and grabs the filename
- $sAttachmentString .= "<dt class='icons'>";
- $sAttachmentString .= "<a href='$file_link'>";
- $sAttachmentString .= "<img src='".get_bloginfo('template_directory')."/images/File-Extension-Xls.png'/>";
- $sAttachmentString .= "</a>";
- $sAttachmentString .= "<br>";
- $sAttachmentString .= "<a href='$file_link'>$file_title</a>";
- $sAttachmentString .= "</dt>";
- }
- }
- //Zipped Files
- if ( $files = get_children(array( //do only if there are attachments of these qualifications
- 'post_parent' => get_the_ID(),
- 'post_type' => 'attachment',
- 'numberposts' => -1,
- 'post_mime_type' => 'application/zip', //MIME Type condition
- ))){
- foreach( $files as $file ){ //setup array for more than one file attachment
- $file_title = wp_get_attachment_link($file->ID);
- $file_link = wp_get_attachment_url($file->ID); //get the url for linkage
- $file_name_array=explode("/",$file_link);
- $file_name=array_reverse($file_name_array); //creates an array out of the url and grabs the filename
- $sAttachmentString .= "<dt class='icons'>";
- $sAttachmentString .= "<a href='$file_link'>";
- $sAttachmentString .= "<img src='".get_bloginfo('template_directory')."/images/File-Extension-Zip.png'/>";
- $sAttachmentString .= "</a>";
- $sAttachmentString .= "<br>";
- $sAttachmentString .= "<a href='$file_link'>$file_title</a>";
- $sAttachmentString .= "</dt>";
- }
- }
- if($echo){
- echo $sAttachmentString;
- }
- return $sAttachmentString;
- }
- add_shortcode('attachment icons', 'get_attachment_icons');
- ////////////////////
- //icons for attachments of parent
- function get_sibling_icons(){
- //PDF
- global $post;
- if ( $files = get_posts(array( //do only if there are attachments of these qualifications
- 'post_parent' => $post->post_parent,
- 'post_type' => 'attachment',
- 'numberposts' => -1,
- 'post_mime_type' => 'application/pdf', //MIME Type condition
- ))){
- foreach( $files as $file ){ //setup array for more than one file attachment
- $file_title = wp_get_attachment_link($file->ID);
- $file_link = wp_get_attachment_url($file->ID); //get the url for linkage
- $file_name_array=explode("/",$file_link);
- $file_name=array_reverse($file_name_array); //creates an array out of the url and grabs the filename
- $sAttachmentString .= "<dt class='icon'>";
- $sAttachmentString .= "<a href='$file_link'>";
- $sAttachmentString .= "<img src='".get_bloginfo('template_directory')."/images/File-Extension-Pdf.png'/ width='16' height='16'>";
- $sAttachmentString .= "</a>";
- $sAttachmentString .= "<dd class='caption'>";
- $sAttachmentString .= "<a href='$file_link'>$file_title</a>";
- $sAttachmentString .= "</dd>";
- $sAttachmentString .= "</dt>";
- }
- }
- //DWG
- global $post;
- if ( $files = get_posts(array( //do only if there are attachments of these qualifications
- 'post_parent' => $post->post_parent,
- 'post_type' => 'attachment',
- 'numberposts' => -1,
- '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
- ))){
- foreach( $files as $file ){ //setup array for more than one file attachment
- $file_title = wp_get_attachment_link($file->ID);
- $file_link = wp_get_attachment_url($file->ID); //get the url for linkage
- $file_name_array=explode("/",$file_link);
- $file_name=array_reverse($file_name_array); //creates an array out of the url and grabs the filename
- $sAttachmentString .= "<dt class='icon'>";
- $sAttachmentString .= "<a href='$file_link'>";
- $sAttachmentString .= "<img src='".get_bloginfo('template_directory')."/images/File-Extension-Dwg.png'/ width='17' height='17'>";
- $sAttachmentString .= "</a>";
- $sAttachmentString .= "<dd class='caption'>";
- $sAttachmentString .= "<a href='$file_link'>$file_title</a>";
- $sAttachmentString .= "</dd>";
- $sAttachmentString .= "</dt>";
- }
- }
- //IES
- global $post;
- if ( $files = get_posts(array( //do only if there are attachments of these qualifications
- 'post_parent' => $post->post_parent,
- 'post_type' => 'attachment',
- 'numberposts' => -1,
- 'post_mime_type' => 'application/octet-stream', //MIME Type condition
- ))){
- foreach( $files as $file ){ //setup array for more than one file attachment
- $file_title = wp_get_attachment_link($file->ID);
- $file_link = wp_get_attachment_url($file->ID); //get the url for linkage
- $file_name_array=explode("/",$file_link);
- $file_name=array_reverse($file_name_array); //creates an array out of the url and grabs the filename
- $sAttachmentString .= "<dt class='icon'>";
- $sAttachmentString .= "<a href='$file_link'>";
- $sAttachmentString .= "<img src='".get_bloginfo('template_directory')."/images/File-Extension-Ies.png'/ width='17' height='17'>";
- $sAttachmentString .= "</a>";
- $sAttachmentString .= "<dd class='caption'>";
- $sAttachmentString .= "<a href='$file_link'>$file_title</a>";
- $sAttachmentString .= "</dd>";
- $sAttachmentString .= "</dt>";
- }
- }
- //Excel Documents
- global $post;
- if ( $files = get_posts(array( //do only if there are attachments of these qualifications
- 'post_parent' => $post->post_parent,
- 'post_type' => 'attachment',
- 'numberposts' => -1,
- 'post_mime_type' => 'application/vnd.ms-excel', //MIME Type condition
- ))){
- foreach( $files as $file ){ //setup array for more than one file attachment
- $file_title = wp_get_attachment_link($file->ID);
- $file_link = wp_get_attachment_url($file->ID); //get the url for linkage
- $file_name_array=explode("/",$file_link);
- $file_name=array_reverse($file_name_array); //creates an array out of the url and grabs the filename
- $sAttachmentString .= "<dt class='icons'>";
- $sAttachmentString .= "<a href='$file_link'>";
- $sAttachmentString .= "<img src='".get_bloginfo('template_directory')."/images/File-Extension-Xls.png'/>";
- $sAttachmentString .= "</a>";
- $sAttachmentString .= "<br>";
- $sAttachmentString .= "<a href='$file_link'>$file_title</a>";
- $sAttachmentString .= "</dt>";
- }
- }
- //Zipped Files
- global $post;
- if ( $files = get_posts(array( //do only if there are attachments of these qualifications
- 'post_parent' => $post->post_parent,
- 'post_type' => 'attachment',
- 'numberposts' => -1,
- 'post_mime_type' => 'application/zip', //MIME Type condition
- ))){
- foreach( $files as $file ){ //setup array for more than one file attachment
- $file_title = wp_get_attachment_link($file->ID);
- $file_link = wp_get_attachment_url($file->ID); //get the url for linkage
- $file_name_array=explode("/",$file_link);
- $file_name=array_reverse($file_name_array); //creates an array out of the url and grabs the filename
- $sAttachmentString .= "<dt class='icons'>";
- $sAttachmentString .= "<a href='$file_link'>";
- $sAttachmentString .= "<img src='".get_bloginfo('template_directory')."/images/File-Extension-Zip.png'/>";
- $sAttachmentString .= "</a>";
- $sAttachmentString .= "<br>";
- $sAttachmentString .= "<a href='$file_link'>$file_title</a>";
- $sAttachmentString .= "</dt>";
- }
- }
- if($echo){
- echo $sAttachmentString;
- }
- return $sAttachmentString;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement