Advertisement
Guest User

Untitled

a guest
Mar 19th, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. PHP - add to functions.php
  2. ++++++++++++++++++++++++++
  3.  
  4.  
  5. add_action( 'wp_enqueue_scripts', 'gmh_enqueue_scripts' );
  6. function gmh_enqueue_scripts() {
  7. global $post;
  8. $postid = get_the_ID();
  9. if ( is_singular( 'job_listing' ) {
  10. $v1 = get_post_meta($postid, '_gmh_vid', true); //use your own field name
  11. $v2 = get_post_meta($postid, '_gmh_vid2', true); //use your own field name
  12. $v3 = get_post_meta($postid, '_gmh_vid3', true); //use your own field name
  13. $second_tab = get_post_meta($postid, '_your_field', true);
  14.  
  15. $urls = array(
  16. $v1,
  17. $v2,
  18. $v3
  19. );
  20.  
  21. $tab2 = ($second_tab ? true : "");
  22. $populated = array_filter($urls);
  23. $count[] = count($populated);
  24. wp_enqueue_script( 'gmh-js', get_stylesheet_directory_uri() . '/js/gmh.js');
  25. wp_localize_script( 'gmh-js', 'gmhVar', array(
  26. 'tab1' => $count,
  27. 'tab2' => $tab2
  28.  
  29. ) ); //passes our array variables to gmhVar in our script
  30. }
  31. }
  32.  
  33.  
  34.  
  35. JS - replace for 2 tabs
  36. ++++++++++++++++++++++++++
  37.  
  38.  
  39. (function($) {
  40. $(document).ready(function(){
  41. var counted = gmhVar.tab1;
  42. if (counted >= 1) {
  43. $( "<span class='items-counter'>" + counted + "</span>").appendTo( "#listing_tab_video_toggle" );
  44. } else {
  45. $("#listing_tab_video_toggle").addClass('hide');
  46. }
  47.  
  48. var element2 = Boolean(gmhVar.tab2);
  49. if (element2 === false) {
  50. $("#listing_tab_yelp_toggle").addClass('hide');
  51. }
  52.  
  53. });
  54. })(jQuery);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement