When using Post Type Switcher the tags get left behind (this will move them ALL which isn’t always what you want). UPDATE wp_term_taxonomy SET taxonomy=’portfolio_tag’ WHERE taxonomy=’post_tag’ UPDATE wp_term_taxonomy SET taxonomy=’portfolio’ WHERE taxonomy=’category’
Grid of Taxonomies
Some options to add a grid of taxonomy pages. The first doesn’t include pageing the second requires adding a second post type to hold the pages.
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 | // no pageing with this one function jma_series_grid ($atts){ ob_start(); extract( shortcode_atts( array( ), $atts ) ); $series_array = get_terms( 'series' ); foreach ($series_array as $series) {//get values from add fields to tax plugin $series_im_array = get_tax_meta($series->term_id,'image_field_id'); $series_text = get_tax_meta($series->term_id,'wysiwyg_field_id'); $series_date = get_tax_meta($series->term_id,'date_field_ids'); echo '<div class="grid-item col-sm-4 series-grid-item">'; echo '<a href="'; echo get_term_link( $series, 'series' ); echo '">'; echo wp_get_attachment_image( $series_im_array['id'], 'tb_grid'); echo '</a>'; echo '<h3 class="news-title"><a href="'; echo get_term_link( $series, 'series' ); echo '">'; echo $series->name; echo '</a></h3>'; echo '</div>'; } // Reset the global $the_post as this query will have stomped on it wp_reset_postdata(); $x = ob_get_contents(); ob_end_clean(); return $x; } add_shortcode('series_grid', 'jma_series_grid'); function jma_new_series_grid ($atts){ ob_start(); extract( shortcode_atts( array( 'post_type' => 'series_page',//default post type 'tax' => false,//a comma seperated list of taxonomies ), $atts ) ); if($tax){ $tax = explode(',', $tax); $tax_query = array( array( 'taxonomy' => $post_type, 'field' => 'term_id', 'terms' => $tax, ), ); }else{ $tax_query =null; } $args = array( 'post_type' => $post_type, 'tax_query' => $tax_query[0], 'orderby' => 'name', 'order' => 'ASC', 'posts_per_page' => 2 ); if ( get_query_var('paged') ) {//for pageing $args['paged'] = get_query_var('paged'); } else if ( get_query_var('page') ) { $args['paged'] = get_query_var('page'); } else { $args['paged'] = 1; } $the_query = new WP_Query( $args ); // The Loop if ( $the_query->have_posts() ) { while ( $the_query->have_posts() ) { $the_query->the_post(); echo '<div class="grid-item col-sm-4 series-grid-item">'; echo '<a href="'; echo the_permalink(); echo '">'; echo the_post_thumbnail( 'tb_grid'); echo '</a>'; echo '<h3 class="news-title"><a href="'; echo the_permalink(); echo '">'; echo the_title(); echo '</a></h3>'; echo '</div>'; } echo '<div class="clear"></div>'; echo themeblvd_pagination( $the_query->max_num_pages ); $x = ob_get_contents(); ob_end_clean(); return $x; } else { echo 'sorry no results';// no posts found } /* Restore original Post Data */ wp_reset_postdata(); } add_shortcode('new_series_grid', 'jma_new_series_grid'); |
Placeholder Text with jQuery
This is for the constant contact widget:
0 1 2 3 4 5 6 7 8 9 10 | jQuery(document).ready(function($){ /* Put any theme-specific JS here... */ $ccwidget = $( '.widget_sf_widget_constantcontact' ); $ccwidget.find('label' ).css('display', 'none'); $ccwidget.find('input[name="fnm"]' ).attr('placeholder', 'First Name'); $ccwidget.find('input[name="lnm"]' ).attr('placeholder', 'Last Name'); $ccwidget.find('input[name="eml"]' ).attr('placeholder', 'Email'); }); |
Query Revision (pre_get_posts)
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 | function jma_add_custom_taxonomy_query( $query ) { if( $query->is_admin || !$query->is_main_query() || true == $query->query_vars['suppress_filters'] ) return; //order cats by title (use 'name' for slug) if( $query->is_category(array(148,160,161)) ) { $query->set('orderby', 'title'); $query->set('order', 'ASC'); } } add_action( 'pre_get_posts', 'jma_add_custom_taxonomy_query' ); |
No Frills Pdf Button
0 1 2 3 4 5 6 7 8 9 10 11 12 13 | function pdf_button_filter( $content ) { $pre_content = $post_content = '<a class="pdf-button btn" href="javascript:pdf_url=location.href;location.href=\'http://pdfmyurl.com?s=l&url=\'+escape(pdf_url)">A pdf button!</a>'; $content = $pre_content . $content . $post_content; return $content; } function add_pdf_button_content(){//whatever template condition you want here //if(is_single())//for just posts //if(is_page())//for just pages if(is_singular( 'park' ))// park is the custom post type add_filter('the_content', 'pdf_button_filter', 1); } add_action('template_redirect', 'add_pdf_button_content'); |
Display List of Related Pages from Hierarchy in Sidebar
Linked pages related to the current page. If is root page shows itself as title with all children below. Else shows immediate parent as title with all pages at its level below (depth can be changed, with -1 showing all without hierarchy).
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | function jma_sidebar_addon() { global $post; if($post->post_parent) { $children = wp_list_pages('title_li=&child_of='.$post->post_parent.'&echo=0&depth=1'); }else{ $children = wp_list_pages('title_li=&child_of='.$post->ID.'&echo=0&depth=1'); } ?> <?php if ($children) { ?> <div class="maincontent"> <h3>More <?php echo get_the_title($post->post_parent);?></h3> <ul class="blog-list"> <?php echo $children;?> </ul> </div><?php } } add_action('themeblvd_sidebar_sidebar_right_before', 'jma_sidebar_addon'); |
Get Image ID from Source
Finds the image id given the source. Or returns false.
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | function get_attachment_id_from_src( $attachment_url = '' ) { global $wpdb; $attachment_id = false; // If there is no url, return. if ( '' == $attachment_url ) return $attachment_id; $query = "SELECT ID FROM {$wpdb->posts} WHERE guid='$attachment_url'"; if($wpdb->get_var($query)){ $attachment_id = $wpdb->get_var($query); }else{ // If this is the URL of an auto-generated thumbnail, get the URL of the original image $attachment_url = preg_replace( '/-\d+x\d+(?=\.(jpg|jpeg|png|gif)$)/i', '', $attachment_url ); //then run the query again $query = "SELECT ID FROM {$wpdb->posts} WHERE guid='$attachment_url'"; if($wpdb->get_var($query)){ $attachment_id = $wpdb->get_var($query); } } return $attachment_id; } |
Multi-site Menu (experimental)
Starting in 4.7 using REST API – This is JumpStart specific. On “host” site:
0 1 2 3 4 5 6 7 8 9 10 11 12 13 | function get_menu() { # Change 'menu' to your own navigation slug. return wp_nav_menu(themeblvd_get_wp_nav_menu_args('primary')); } //https://hosturl.com/wp-json/myroutes/menu add_action('rest_api_init', function () { register_rest_route('myroutes', '/menu', array( 'methods' => 'GET', 'callback' => 'get_menu', )); }); |
On “receiving” site:
0 1 2 3 4 5 6 7 8 9 10 | function jma_child_header_menu_addon() { $response = wp_remote_get('https://hosturl.com/wp-json/myroutes/menu'); /*echo '<pre>'; print_r($response); echo '</pre>';*/ echo str_replace('null', '', $response['body']) ; } add_action('themeblvd_header_menu_addon', 'jma_child_header_menu_addon'); |
JQuery to add current classes (coming soon):
Display Posts by Category [shortcode]
Suppose we want to display a list of post links in the sidebar that are in “child” categories of the “News” category (ie “Boating News” followed by its posts, “Fishing News” followed by its posts, in this case from the last 90 days because of the filter). We could include this code in functions.php:
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | add_filter('widget_text', 'do_shortcode');//FOR WIDGET SHORTCODE function filter_where($where = '') { //posts in the last 90 days $where .= " AND post_date > '" . date('Y-m-d', strtotime('-90 days')) . "'"; return $where; } function jma_news_posts($atts){ ob_start(); extract( shortcode_atts( array( 'parent_cat_id' => 3, 'number_displayed' => 3, ), $atts ) ); add_filter('posts_where', 'filter_where'); $children = get_categories( array('child_of' => $parent_cat_id) ); foreach ($children as $child) { echo '<h3 class="news-title"><a href="'; echo get_category_link( $child->cat_ID ); echo '">'; echo $child->cat_name; echo '</a></h3>'; $x = new WP_Query('category_name=' . $child->slug . '&posts_per_page=' . $number_displayed); echo '<ul class="news-bar">'; while ( $x->have_posts() ) : $x->the_post(); echo '<li class="sidebar-recent-posts">'; echo '<a class="side-post-title" href="'; the_permalink(); echo '">'; the_title(); echo '</a></li>'; endwhile; echo '</ul>'; } // Reset the global $the_post as this query will have stomped on it wp_reset_postdata(); $x = ob_get_contents(); ob_end_clean(); return $x; } add_shortcode('add_news_with_kids','jma_news_posts'); |
[…]