camyen
asked 9 years ago

Hello there,

How can I add a ‘Answer’ tab on BP admin bar just like the ‘Question’tab?

Best,

1 Answers
Allen
answered 9 years ago

@Yan Yan : hi, i think all the answer will be recorded in activity tab when you integrate BuddyPress with DW-Question answer , you can see the guide in this link : http://www.designwall.com/guide/dw-question-answer-plugin/
Search for BuddyPress Integration.

And if you want to create a new tab on BP admin bar, you can try this:
-Step 1 : First , in your theme , create New directory and name it : buddypress. In there, you need to create a file name functions.php . And in your theme functions.php file , you need to add this code :

if ( class_exists( 'BuddyPress' ) ) {
    require_once locate_template( '/buddypress/functions.php' );
}
  • Step2 : New you need to add some code in buddypress/functions.php file :
    add_action( 'bp_setup_nav', 'dw_evo_bp_nav_adder' );
    function dw_evo_bp_nav_adder() {
    bp_core_new_nav_item(
        array(
            'name' => __( 'Answer', 'design-wall' ),
            'slug' => 'answer',
            'position' => 21,
            'show_for_displayed_user' => true,
            'screen_function' => 'answer_list',
            'item_css_id' => 'answer',
            'default_subnav_slug' => 'public',
        ) );
    }
    function answer_list() {
    add_action( 'bp_template_content', 'profile_answer_archive' );
    bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ) );
    }
    function profile_answer_archive() {
    echo "template";
    }

    _ in this step , function profile_answer_archive() is the place you write the template of Answer archive page for user.
    step 3 : new in dir buddypress create new dir : members, in members create single and in single you create plugins.php and add some code :

<?php do_action( 'bp_before_member_plugin_template' ); ?>

<?php if ( ! bp_is_current_component_core() ) : ?>

<div class="item-list-tabs no-ajax" id="subnav">
    <ul>
        <?php bp_get_options_nav(); ?>

        <?php do_action( 'bp_member_plugin_options_nav' ); ?>
    </ul>
</div>

<?php endif; ?>

<?php do_action( 'bp_template_content' ); ?>

<?php do_action( 'bp_after_member_plugin_template' ); ?>

hope this help. Glad

camyen
replied 9 years ago

@nobita

Thank you for your message. I followed your guideline but an error message shown on my wp-admin page. It’s failed to call buddypress/function.php

Let me explain my theme’s BP repository first. I’ve a child theme. The parent theme has a buddypress-function.php in the dir ‘buddypress’ and a plugins.php in the dir ‘buddypress/members/single’.

Below is my attempt:

  1. I added the code in the first block above to my child theme’s fuction.php
  2. I created a brand new function.php in the parent theme’s dir ‘buddypress’ and added the code in the second block above.
  3. I added the code in the third block above to the parent theme’s dir ‘buddypress/members/single/plugins.php’

Did I miss something?

nobita
replied 9 years ago

@camyen: hi , i think in this situation , it could be wrong direction to function.php of buddy press. You can read more about adding new nav to BP admin bar here : https://codex.buddypress.org/developer/function-examples/core/bp_core_new_nav_item/

And i think , in your situation , you just need to add the 2nd block’s code to : buddypress-function.php in the parent theme. Hope this help. If you still have trouble with this, please , kindly send me your site and login rights so i can help you implement it. Glad

camyen
replied 9 years ago

@nobita
I’ve added ‘Answer’ nav to BP admin bar. However, my answers are not showing on there excepted two lines of ‘template’. Beside, the ‘Question’ nav display duplicated question there. Any idea?

nobita
replied 9 years ago

@Camyen: hi , that just the first step to get it , As you see in that function

function profile_answer_archive() {
echo "template";
}

the function profile_answer_archive(){} is where you place the code that will get all the answer from each user. And you need to customize that function in order to get all answer of an user. i’ll spend time to help you with this. it’ll be better if you send my your site so i can check the duplicated question. glad

camyen
replied 9 years ago

Please pass me your email address, I can create an account for you. Thanks.

camyen
replied 9 years ago

@nobita I’ve solved the duplicated question issue. Let’s come back to the ‘Answer’ Nav. on BP admin bar. Do you have any solution?

nobita
replied 9 years ago

@camyen : good to here that from you , the Answer Nav is quite a new feature. Because you have to querry all the answer of an user just like question. The thing is what you want it look like? have you seen the activity nav? it’s has the all the answer of user recorded in there. i think it’s quite like the Answer nav. you can check the activity nav in this guide :
http://www.designwall.com/guide/dw-question-answer-plugin/
Search for BuddyPress Integration.

camyen
replied 9 years ago

Yes, it is what I want. A separate ‘Answer Nav’ which shows the answers of user just like the questions. The Activity Nav shows all my friends’ activity. I’d like something else to show answer only. Any idea?

nobita
replied 9 years ago

@camyen: hi , you can try add this code to profile_answer_archive{} function:

function profile_answer_archive() { ?>
        <div class="answer-list"> 
            <?php 
                global $dwqa_options;
                $answer = get_posts(  array(
                  'posts_per_page' => -1,
                  'author'         => bp_displayed_user_id(),
                  'post_type'      => 'dwqa-answer'
                ));
            ?>
            <?php  if( ! empty($answer) ) : ?>

                <?php   foreach ($answer as $ans) : ?>
                <div class="answer-<?php echo $ans->ID; ?>"> 
                    You have an <a href="<?php echo $ans->guid; ?>"><?php echo $ans->post_title ?></a> at <?php echo $ans->post_date; ?> and have <?php echo $ans->comment_count ?> comment/s
                    <p>Answer Content : <?php echo $ans->post_content; ?></p>
                </div>
                </br>
                <?php endforeach; ?>

            <?php else: ?>
                <p> You don't have any answer </p>
            <?php endif; ?>

        </div>
<?php
}

Hope this help, I’m just not good at css so i hope you can add some css code to make this look cool.

camyen
replied 9 years ago

Great! Thank you @nobita

camyen
replied 9 years ago
nobita
replied 9 years ago

@camyen : ok then, i’ll check it and answer you at that question.

Powered by DW Question & Answer Pro