Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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.
- 1. Create a new child theme directory.
- /functions/widgets
- 2. Copy /functions/widgets/alx-tabs.php from the parent theme to your child theme.
- 3. In alx-tabs.php, for each type of tab, there is a section "heading" like <?php if($instance['tab_type']).
- 4. Add the Author to the Recent Posts section.
- in <?php if($instance['recent_enable'])
- in <div class="tab-item-inner group">
- add this as the last line in the div
- <?php if($instance['tabs_author']) { ?><p class="tab-item-author"><?php the_author_posts_link(); ?></p><?php } ?>
- It should look like this after the edit:
- <div class="tab-item-inner group">
- <?php if($instance['tabs_category']) { ?><p class="tab-item-category"><?php the_category(' / '); ?></p><?php } ?>
- <p class="tab-item-title"><a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a></p>
- <?php if($instance['tabs_date']) { ?><p class="tab-item-date"><?php the_time('j M, Y'); ?></p><?php } ?>
- <?php if($instance['tabs_author']) { ?><p class="tab-item-author"><?php the_author_posts_link(); ?></p><?php } ?>
- </div>
- 5. Add the Author to the Popular Posts section.
- in <?php if($instance['popular_enable'])
- same as #4 above
- 6. Add an instance of the Author.
- in /* Widget update section
- in public function update($new,$old)
- in the first block of lines add this line just above // Recent posts
- $instance['tabs_author'] = $new['tabs_author']?1:0;
- It should look like this after the edit:
- public function update($new,$old) {
- $instance = $old;
- $instance['title'] = strip_tags($new['title']);
- $instance['tabs_category'] = $new['tabs_category']?1:0;
- $instance['tabs_date'] = $new['tabs_date']?1:0;
- $instance['tabs_author'] = $new['tabs_author']?1:0;
- // Recent posts
- 7. Set the default Author checkbox option to checked.
- in /* Widget form section
- in public function form($instance)
- in $defaults = array(
- add this line just above // Recent posts
- 'tabs_author' => 1,
- It should look like this after the edit:
- public function form($instance) {
- // Default widget settings
- $defaults = array(
- 'title' => '',
- 'tabs_category' => 1,
- 'tabs_date' => 1,
- 'tabs_author' => 1,
- // Recent posts
- 8. Add the "Show author" option in the Tab Info section.
- in the Form section
- at the bottom in Tab Info
- add the following block above the last <hr>
- <p>
- <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 ); ?>>
- <label for="<?php echo $this->get_field_id('tabs_author'); ?>">Show author</label>
- </p>
- It should look like this after the edit:
- <h4>Tab Info</h4>
- <p>
- <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 ); ?>>
- <label for="<?php echo $this->get_field_id('tabs_category'); ?>">Show categories</label>
- </p>
- <p>
- <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 ); ?>>
- <label for="<?php echo $this->get_field_id('tabs_date'); ?>">Show dates</label>
- </p>
- <p>
- <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 ); ?>>
- <label for="<?php echo $this->get_field_id('tabs_author'); ?>">Show author</label>
- </p>
- <hr>
- 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.
- 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).
- 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.
- It should look like this after the edit:
- function alx_load() {
- // Load theme languages
- load_theme_textdomain( 'hueman', get_template_directory().'/languages' );
- // Load theme options and meta boxes
- load_template( get_template_directory() . '/functions/theme-options.php' );
- load_template( get_template_directory() . '/functions/meta-boxes.php' );
- // Load custom widgets
- load_template( get_stylesheet_directory() . '/functions/widgets/alx-tabs.php' );
- load_template( get_template_directory() . '/functions/widgets/alx-video.php' );
- load_template( get_template_directory() . '/functions/widgets/alx-posts.php' );
- // Load custom shortcodes
- load_template( get_template_directory() . '/functions/shortcodes.php' );
- // Load dynamic styles
- load_template( get_template_directory() . '/functions/dynamic-styles.php' );
- // Load TGM plugin activation
- load_template( get_template_directory() . '/functions/class-tgm-plugin-activation.php' );
- }
- 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