Jonah Burke
asked 9 years ago

Hi all, is it possible to pick specific stories to appear in the DW Focus: News Slider widget (rather than a category)?
Alternatively, is it possible to show stories with a certain tag?
Finally, if these are not possible, would DesignWall be interested in having the tag feature contributed?
Thanks,
Jonah

1 Answers
DominicStaff
answered 9 years ago

Sorry about that I have confused with another question, I will remove previous answer, please see the following solution:
Open the dw-focus-slider.php file in the folder path “yourdomain/wp-content/themes/dw-focus/inc/widgets/dw-focus-slider.php”. Then do as the following:
Step 1: Add Tag dropdown in Slider widget backend:
Find line 218 :

<p><label for="<?php echo $this->get_field_id('category'); ?>"><?php _e('Category:','dw_focus'); ?></label><br>
<?php wp_dropdown_categories(array(
'show_option_all' => 'All categories',
'hide_empty' => 0,
'id' => $this->get_field_id('category'),
'name' => $this->get_field_name('category'),
'selected' => $category,
'class' => 'widefat',
'hierarchical' => true,
'walker' => new DW_Walker_CategoryDropdown()
) ); ?>
</p>

Add some code after that :

<p><label for="<?php echo $this->get_field_id('post_tag'); ?>"><?php _e('Tag:','dw_focus'); ?></label><br>
<?php wp_dropdown_categories(array(
'show_option_all' => 'All tags',
'hide_empty' => 0,
'id' => $this->get_field_id('post_tag'),
'name' => $this->get_field_name('post_tag'),
'selected' => $post_tag,
'class' => 'widefat',
'hierarchical' => true,
'taxonomy' => 'post_tag',
'walker' => new DW_Walker_CategoryDropdown()
) ); ?>
</p>

Step2: Add instance post_tag :
Find line 173 :
$instance[‘category’] = (int) $new_instance[‘category’];
Add:
$instance[‘post_tag’] = (int) $new_instance[‘post_tag’];
After that: 
Find line 194 :
$category = isset($instance[‘category’]) ? absint($instance[‘category’]) : 0;
Add:
$post_tag = isset($instance[‘category’]) ? absint($instance[‘post_tag’]) : 0;
After that.
Step 3 : Change WP_query
Find line 40 – 48 :

$r = new WP_Query( apply_filters( 'widget_posts_args', 
array(
'posts_per_page' => $number,
'no_found_rows' => true,
'post_status' => 'publish',
'ignore_sticky_posts' => true,
'cat' => $instance['category'],
'meta_query' => array(array('key' => '_thumbnail_id'))
) ) );

Replace that code with :

$r = new WP_Query( apply_filters( 'widget_posts_args', 
array(
'tax_query' => array(
'relation' => 'OR',
array(
'taxonomy' => 'category',
'field' => 'id',
'terms' => array( $instance['category'] ),
),
array(
'taxonomy' => 'post_tag',
'field' => 'id',
'terms' => array( $instance['post_tag'] ),
),
),
'posts_per_page' => $number,
'no_found_rows' => true,
'post_status' => 'publish',
'ignore_sticky_posts' => true,
'meta_query' => array(array('key' => '_thumbnail_id'))
) ) );

Hope this helps !

Jonah Burke
replied 9 years ago

Thanks, Dominic. Would it be possible for you to add this code to the official, released plugin? We’d rather not make modifications if possible so we can auto-update.

Dominic Staff
replied 9 years ago

We will discuss about this issue in the next version.

Jonah Burke
replied 9 years ago

What’s the chance this feature will appear in the next version, and when would that be? We are trying to decide whether to stick with DW Focus or switch to a different theme, and this is a critical feature for us.

Dominic Staff
replied 9 years ago

Hi,I know what you wish. It’s not easy to let you know exactly when we will update newer version of the theme. However, be assured, we have a technical team and alway be ready to assist and help you to develop this feature for the core theme before releasing the officially new version.Of course, it is the awesome feature, will update it in the upcoming version.

shi weisman
replied 9 years ago

I tried the code listed above but I can’t get it to set the widget to a specific tag. It won’t let me select post_tag or any tag to only display in the the news slider. I added the code and the post_tag shows a drop down on the news slider widget but it won’t let me save any tags. It keeps sorting instantly to all tags. Is there a way to fix this?

dominic Staff
replied 9 years ago

You can send me username & password of your site ( create a private question) for further checking.

Powered by DW Question & Answer Pro