bdbrown

Add Author to AlxTabs Widget

Dec 3rd, 2014
306
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.75 KB | None | 0 0
  1. These changes will add the Author name to Recent and Popular Posts in the AlxTabs widget. It requires editing the alx-tabs.php and functions.php files. You should be using a child theme.
  2.  
  3. 1. Create a new child theme directory.
  4. /functions/widgets
  5.  
  6. 2. Copy /functions/widgets/alx-tabs.php from the parent theme to your child theme.
  7.  
  8. 3. In alx-tabs.php, for each type of tab, there is a section "heading" like <?php if($instance['tab_type']).
  9.  
  10. 4. Add the Author to the Recent Posts section.
  11. in <?php if($instance['recent_enable'])
  12. in <div class="tab-item-inner group">
  13. add this as the last line in the div
  14. <?php if($instance['tabs_author']) { ?><p class="tab-item-author"><?php the_author_posts_link(); ?></p><?php } ?>
  15.  
  16. It should look like this after the edit:
  17. <div class="tab-item-inner group">
  18. <?php if($instance['tabs_category']) { ?><p class="tab-item-category"><?php the_category(' / '); ?></p><?php } ?>
  19. <p class="tab-item-title"><a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a></p>
  20. <?php if($instance['tabs_date']) { ?><p class="tab-item-date"><?php the_time('j M, Y'); ?></p><?php } ?>
  21. <?php if($instance['tabs_author']) { ?><p class="tab-item-author"><?php the_author_posts_link(); ?></p><?php } ?>
  22. </div>
  23.  
  24. 5. Add the Author to the Popular Posts section.
  25. in <?php if($instance['popular_enable'])
  26. same as #4 above
  27.  
  28. 6. Add an instance of the Author.
  29. in /* Widget update section
  30. in public function update($new,$old)
  31. in the first block of lines add this line just above // Recent posts
  32. $instance['tabs_author'] = $new['tabs_author']?1:0;
  33.  
  34. It should look like this after the edit:
  35. public function update($new,$old) {
  36. $instance = $old;
  37. $instance['title'] = strip_tags($new['title']);
  38. $instance['tabs_category'] = $new['tabs_category']?1:0;
  39. $instance['tabs_date'] = $new['tabs_date']?1:0;
  40. $instance['tabs_author'] = $new['tabs_author']?1:0;
  41. // Recent posts
  42.  
  43. 7. Set the default Author checkbox option to checked.
  44. in /* Widget form section
  45. in public function form($instance)
  46. in $defaults = array(
  47. add this line just above // Recent posts
  48. 'tabs_author' => 1,
  49.  
  50. It should look like this after the edit:
  51. public function form($instance) {
  52. // Default widget settings
  53. $defaults = array(
  54. 'title' => '',
  55. 'tabs_category' => 1,
  56. 'tabs_date' => 1,
  57. 'tabs_author' => 1,
  58. // Recent posts
  59.  
  60. 8. Add the "Show author" option in the Tab Info section.
  61. in the Form section
  62. at the bottom in Tab Info
  63. add the following block above the last <hr>
  64. <p>
  65. <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('tabs_author'); ?>" name="<?php echo $this->get_field_name('tabs_author'); ?>" <?php checked( (bool) $instance["tabs_author"], true ); ?>>
  66. <label for="<?php echo $this->get_field_id('tabs_author'); ?>">Show author</label>
  67. </p>
  68.  
  69. It should look like this after the edit:
  70. <h4>Tab Info</h4>
  71. <p>
  72. <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('tabs_category'); ?>" name="<?php echo $this->get_field_name('tabs_category'); ?>" <?php checked( (bool) $instance["tabs_category"], true ); ?>>
  73. <label for="<?php echo $this->get_field_id('tabs_category'); ?>">Show categories</label>
  74. </p>
  75. <p>
  76. <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('tabs_date'); ?>" name="<?php echo $this->get_field_name('tabs_date'); ?>" <?php checked( (bool) $instance["tabs_date"], true ); ?>>
  77. <label for="<?php echo $this->get_field_id('tabs_date'); ?>">Show dates</label>
  78. </p>
  79. <p>
  80. <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('tabs_author'); ?>" name="<?php echo $this->get_field_name('tabs_author'); ?>" <?php checked( (bool) $instance["tabs_author"], true ); ?>>
  81. <label for="<?php echo $this->get_field_id('tabs_author'); ?>">Show author</label>
  82. </p>
  83. <hr>
  84.  
  85. 9. Unless you feel lucky, make a backup of your child theme functions.php file. If it breaks, your site won't load and you won't be able to log on to the back end.
  86.  
  87. 10. Copy the entire block of code for function alx_load() from the parent functions.php to your child theme functions.php (don't include the "if ( ! function_exists" or the "add_action" lines).
  88.  
  89. 11. In the function section "// Load custom widgets", change the first line to be "get_stylesheet_directory"; this will bring in your child alx-tabs.php file; everything else will still be loaded from the parent theme.
  90.  
  91. It should look like this after the edit:
  92. function alx_load() {
  93. // Load theme languages
  94. load_theme_textdomain( 'hueman', get_template_directory().'/languages' );
  95.  
  96. // Load theme options and meta boxes
  97. load_template( get_template_directory() . '/functions/theme-options.php' );
  98. load_template( get_template_directory() . '/functions/meta-boxes.php' );
  99.  
  100. // Load custom widgets
  101. load_template( get_stylesheet_directory() . '/functions/widgets/alx-tabs.php' );
  102. load_template( get_template_directory() . '/functions/widgets/alx-video.php' );
  103. load_template( get_template_directory() . '/functions/widgets/alx-posts.php' );
  104.  
  105. // Load custom shortcodes
  106. load_template( get_template_directory() . '/functions/shortcodes.php' );
  107.  
  108. // Load dynamic styles
  109. load_template( get_template_directory() . '/functions/dynamic-styles.php' );
  110.  
  111. // Load TGM plugin activation
  112. load_template( get_template_directory() . '/functions/class-tgm-plugin-activation.php' );
  113. }
  114.  
  115. That should do it. Now when you check the AlxTabs widget it should have the "Show author" option at the bottom. To initialize it, uncheck, save, check and save. Refresh your site and it should show the author in the widget posts. Style the tab-item-author class as needed.
Advertisement
Add Comment
Please, Sign In to add comment