0

In my single.php I have 3 tabs one for description, others for comments and reviews my question is when I submit the comments, the first tab is always selected. My code:

            <div id="product-information">
                <div id="tabs" class="htabs">
                    <a href="#tab-description" class="selected">Description</a> 
                    <a href="#tab-comment" class="">Comments</a>
                    <a href="#tab-review" class="">Reviews</a> 
                </div>

                <div id="tab-description" class="tab-content" style="display: block;">
                    <?php the_content(); ?>          
                </div>

                <div id="tab-comment" class="tab-content" style="display: none;">
                    <?php if ( comments_open() || true): ?>
                        <?php comments_template( '', true ); ?>
                    <?php endif ?>
                </div>

                 <div id="tab-review" class="tab-content" style="display: none;">
                    <h1>REVIEW</h1>
                </div>

             </div>

How can I pass the attribute class="selected" dynamically?

  • This question likely is not specific to WordPress and hence out of scope here. Regardless, there's got to be some javascript that goes with this. You'd have to post that as well. – Johannes Pille Sep 21 '13 at 18:55
  • I d'not see the usefulness of javascript here, because the problem is after sending th comments form, otherwise i manage well the change of the tabs in javascript. – Abdeel Sep 21 '13 at 19:06
1

i think the best solution is to add an get attribute, in this case we don't need javascript like this: your single.php :

            <div id="product-information">
            <div id="tabs" class="htabs">
                <a href="<?php the_permalink(); ?>&tab=description" class="<?php echo !isset($_GET['tab']) || ($_GET['tab'] == 'description') ? 'selected':''; ?>">Description</a> 
                <a href="<?php the_permalink(); ?>&tab=comment" class="<?php echo isset($_GET['tab']) && ($_GET['tab'] == 'comment') ? 'selected':''; ?>">Comments</a>
                <a href="<?php the_permalink(); ?>&tab=review" class="<?php echo isset($_GET['tab']) && ($_GET['tab'] == 'review') ? 'selected':''; ?>">Reviews</a> 
            </div>

            <div id="tab-description" class="tab-content" style="display: <?php echo !isset($_GET['tab']) || ($_GET['tab'] == 'description') ? 'block;':'none;'; ?>">
                <?php the_content(); ?>          
            </div>

            <div id="tab-comment" class="tab-content" style="display: <?php echo isset($_GET['tab']) && ($_GET['tab'] == 'comment') ? 'block;':'none;'; ?>">
                <?php if ( comments_open() || true): ?>
                    <?php comments_template( '', true ); ?>
                <?php endif ?>
            </div>

             <div id="tab-review" class="tab-content" style="display: <?php echo isset($_GET['tab']) && ($_GET['tab'] == 'review') ? 'block;':'none;'; ?>;">
                <h1>REVIEW</h1>
            </div>

         </div>

and in your function.php add this:

    if ( ! function_exists( 'redirect_after_comment' ) ) {
function redirect_after_comment($location)
{
    return get_permalink().'&tab=comment';
}
   }
   add_filter('comment_post_redirect', 'redirect_after_comment');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.