harsh deshmukh
asked 6 years ago

Hi There,
What is the short code of DW-QA Popular Questions and Related Questions.
I want to display recent questions and answer somewhere in my home page. Can you please help/suggest..??
 
Regards,
Harsh
 

harsh deshmukh
replied 6 years ago

As we have already widgets available.However I am looking for short code for the same.

Regards,
Harsh

5 Answers
DominicStaff
answered 6 years ago

Hi Harsh !
Currently, we do not have the short code for these yet. Will try to make in later updated versions.

harsh deshmukh
replied 6 years ago

Hi Dominic,

At this point of time it will be helpful if you just tell me what are the functions or the codes that is being used for Popular Questions and Related Question Widget. I just fell to dig into and try to get my job done.

harsh deshmukh
replied 6 years ago

I think widget.php is being called.. 🙂

harsh deshmukh
answered 6 years ago

Hi Dominic,  I tried below to create a short code, change in code can be seen in bold letters.I went to dw-question and answer/inc/widget.php and edited the code as below and latter i put [dwqa_shortcode] in my page/post to call this. I Think I am missing something. Can You please work a bit to get it done.    referance: http://codex.wordpress.org/Shortcode_API
 
 
class dwqa_Related_Question_Widget extends WP_Widget { /**
* Constructor
*
* @return void
**/
//[dwqa_shortcode]
function dwqa_Related_Question_Widget() {
$widget_ops = array( ‘classname’ => ‘dwqa-related-question’, ‘description’ => __(‘Show a list of questions that related to a question. Just show in single question page’,’dwqa’) );
$this->WP_Widget( ‘dwqa-related-question’, __(‘DWQA Related Questions’,’dwqa’), $widget_ops );
} function widget( $args, $instance ) {
extract( $args, EXTR_SKIP );
$instance = wp_parse_args( $instance, array(
‘title’ => ”,
‘number’ => 5
) );
$post_type = get_post_type();
if( is_single() && ( $post_type == ‘dwqa-question’ || $post_type == ‘dwqa-answer’ ) ) { echo $before_widget;
echo $before_title;
echo $instance[‘title’];
echo $after_title;
echo ‘<div class=”related-questions”>’;
dwqa_related_question( false, $instance[‘number’] );
echo ‘</div>’;
echo $after_widget;
}
} function update( $new_instance, $old_instance ) { // update logic goes here
$updated_instance = $new_instance;
return $updated_instance;
} function form( $instance ) {
$instance = wp_parse_args( $instance, array(
‘title’ => ”,
‘number’ => 5
) );
?>
<p><label for=”<?php echo $this->get_field_id(‘title’) ?>”><?php _e(‘Widget title’) ?></label>
<input type=”text” name=”<?php echo $this->get_field_name(‘title’) ?>” id=”<?php echo $this->get_field_id(‘title’) ?>” value=”<?php echo $instance[‘title’] ?>” class=”widefat”>
</p>
<p><label for=”<?php echo $this->get_field_id(‘number’) ?>”><?php _e(‘Number of posts’) ?></label>
<input type=”text” name=”<?php echo $this->get_field_name(‘number’) ?>” id=”<?php echo $this->get_field_id(‘number’) ?>” value=”<?php echo $instance[‘number’] ?>” class=”widefat”>
</p>
<?php
}
}
add_action( ‘widgets_init’, create_function( ”, “register_widget( ‘dwqa_Related_Question_Widget’ );” ) );
add_shortcode(‘dwqa_shortcode’,’dwqa_Related_Question_Widget’);

BigHug
answered 6 years ago

Hi Harsh,
Your code above is a widget class, and I dont think it will work for shortcode. I added  here the shortcode for popular questions features:

 function dwqa_shortcode_popular_questions( $atts ){

    extract( shortcode_atts( array(
        'number' => 5,
        'title' => __('Popular Questions','dwqa')
    ), $atts ) );

    $args = array(
        'posts_per_page'       => $number,
        'order'             => 'DESC',
        'orderby'           => 'meta_value_num',
        'meta_key'           => '_dwqa_views',
        'post_type'         => 'dwqa-question',
        'suppress_filters'  => false
    );
    $questions = new WP_Query( $args );
    $html = '';

    if( $title ) {
        $html .= '<h3>';
        $html .= $title;
        $html .= '</h3>';
    }
    if( $questions->have_posts() ) {
        $html .= '<div class="dwqa-popular-questions">';
        $html .= '<ul>';
        while ( $questions->have_posts() ) { $questions->the_post();
            $html .= '<li><a href="'.get_permalink( get_the_ID() ).'" title="'.__('Link to','dwqa').' '.get_the_title().'">'.get_the_title().'</a></li>';
        }   
        $html .= '</ul>';
        $html .= '</div>';
    }
    wp_reset_query();
    wp_reset_postdata();
    return $html;
}
add_shortcode( 'dwqa-popular-questions', 'dwqa_shortcode_popular_questions' );

  Please put it in “<plugins-folder>/dw-question-answer/inc/shortcodes.php” ( you can refer to this link for more info https://github.com/designwall/DW-Question-Answer/blob/58f84e70af444fdd3db56361dc9147ed295eab13/inc/shortcodes.php ) .
How to use this shortcode ? 
[dwqa-popular-questions number="5" title="Popular Questions" ]

with number:  The number of questions that will be displayed
       title:        Title displayed before list questions
Regards

harsh deshmukh
replied 6 years ago

Hi Rambu,

Thanks.. Great Job..:)

Cool..!!!!!!

Regards,
Harsh

harsh deshmukh
answered 6 years ago

Hi Rambu,
Need One more help.
How we can get shortcode for recent question and recent answer: I tried for recent answer as below, but output is not coming correctly:
http://harsh031.0fees.net/ Please see recent answer field in my website.(here I am getting link for the answer) Code used is as below here i have removed the meta_key value in $args array:
function dwqa_shortcode_recent_answers( $atts ){ extract( shortcode_atts( array(
‘number’ => 5,
‘title’ => __(”,’dwqa’)
), $atts ) ); $args = array(
‘posts_per_page’ => $number,
‘order’ => ‘DESC’,
‘orderby’ => ‘meta_value_num’,
‘post_type’ => ‘dwqa-answer’,
‘suppress_filters’ => false
);
$answers = new WP_Query( $args );
$html = ”; if( $title ) {
$html .= ‘<h3>’;
$html .= $title;
$html .= ‘</h3>’;
}
if( $answers->have_posts() ) {
$html .= ‘<div class=”dwqa-recent-answers”>’;
$html .= ‘<ul>’;
while ( $answers->have_posts() ) { $answers->the_post();
$html .= ‘<li><a href=”‘.get_permalink( get_the_ID() ).'” title=”‘.__(‘Link to’,’dwqa’).’ ‘.get_the_title().'”>’.get_the_title().'</a></li>’;
}
$html .= ‘</ul>’;
$html .= ‘</div>’;
}
wp_reset_query();
wp_reset_postdata();
return $html;
}
add_shortcode( ‘dwqa-recent-answers’, ‘dwqa_shortcode_recent_answers’ ); and called it in same way we have done for popular question.
[dwqa-recent-answer number=”5″ ]   Please help/suggest.

BigHug
answered 6 years ago

Hi Harsh,
Hope this helps:

 function dwqa_shortcode_latest_answers( $atts ){

    extract( shortcode_atts( array(
        'number' => 5,
        'title' => __('Latest Answers','dwqa')
    ), $atts ) );

    $args = array(
        'posts_per_page'       => $number,
        'post_type'         => 'dwqa-answer',
        'suppress_filters'  => false
    );
    $questions = new WP_Query( $args );
    $html = '';

    if( $title ) {
        $html .= '<h3>';
        $html .= $title;
        $html .= '</h3>';
    }
    if( $questions->have_posts() ) {
        $html .= '<div class="dwqa-latest-answers">';
        $html .= '<ul>';
        while ( $questions->have_posts() ) { $questions->the_post();
            $answer_id = get_the_ID();
            $question_id = get_post_meta( $answer_id, '_question', true );
            if( $question_id ) {
                $html .= '<li>'.__('Answer at','dwqa').' <a href="'.get_permalink( $question_id ).'#answer-'.$answer_id.'" title="'.__('Link to','dwqa').' '.get_the_title( $question_id ).'">'.get_the_title( $question_id ).'</a></li>';
            }
        }   
        $html .= '</ul>';
        $html .= '</div>';
    }
    wp_reset_query();
    wp_reset_postdata();
    return $html;
}
add_shortcode( 'dwqa-latest-answers', 'dwqa_shortcode_latest_answers' );

Regards

harsh deshmukh
replied 6 years ago

Hi Rambu,

Heartily thinking you for your response 🙂
Its working fine, However I was thing of getting answer content rather than whatever we are getting here.

BigHug
replied 6 years ago

In order to get the answer content, you can try this: Replace

"$html .= '<li>'.__('Answer at','dwqa').' <a href="'.get_permalink( $question_id ).'#answer-'.$answer_id.'" title="'.__('Link to','dwqa').' '.get_the_title( $question_id ).'">'.get_the_title( $question_id ).'</a></li>';"
by

"$html .= '<li>'.__('Answer at','dwqa').' <a href="'.get_permalink( $question_id ).'#answer-'.$answer_id.'" title="'.__('Link to','dwqa').' '.get_the_title( $question_id ).'">'.get_the_content( $answer_id ).'</a></li>';".

harsh deshmukh
replied 6 years ago

Thanks ..:)

Mohi Uddin
answered 4 years ago

I have create a questions answers website. My website is: http://answers.itinfoworld.org
I have to problems one is, subscriber can not see his posted questions and answers. I think it would be better if a subscriber could see his posted questions at a glance by clicking on his profile.

My another questions is: I can not fined any wedges DW categories to show.

dominic Staff
replied 4 years ago
  • If the subscriber of your site can not see the question and answer, you can log in to Dashboard > Q&A > Settings > Permission.
    After changing the permission, please check and let us know, if you still face there issue.

  • About the dwqa categories section as our site in here. The feature you mentioned are custom codes and made for only DesignWall website. If you want to have it, we are ready to help you as a custom work with a charge of fee.
    In case that you are still interested in the feature, please kindly let us know, we will check and estimate the time.
    Regards,
Mohi Uddin
answered 4 years ago

dw question answer plugins tag and categories is not working in my website. http://answers.itinfoworld.org/

Please help me.

dominic Staff
replied 4 years ago

About this issue, please send me username & password of your site (via private answer ) for further checking.

Powered by DW Question & Answer Pro