<?php if (!isset($html)) { $html = ""; } //==============================================AUTHENTIFICATION========================= $userinfo_html = ""; $t3 = __("Enter Your Name", 'qna-forum'); $t4 = __("Enter Your Email Address", 'qna-forum'); if (!is_user_logged_in()) { if (get_option('q_loginrequired_ask') == "TRUE") { $html = "<p>" . __("Please login to ask a question", 'qna-forum') . "</p>"; $html .= q_loginform(get_permalink()); return $html; } elseif (get_option('q_loginrequired_ask') == "name-and-email") { //textboxes for name and email $userinfo_html .= <<<HTML \t\t\t\t<div class="question-user-details"> \t\t\t\t\t<input type="text" class="question-title-box" value="{$qname}" name="name" onfocus="if(this.value == '{$t3}'){this.value = '';}" onblur="if(this.value == ''){this.value = '{$t3}';}" /> \t\t\t\t\t<input type="text" class="question-title-box" value="{$qemail}" name="email" onfocus="if(this.value == '{$t4}'){this.value = '';}" onblur="if(this.value == ''){this.value = '{$t4}';}" /> HTML; if (get_option('users_can_register') == 1) { $userinfo_html .= "Or <a href='" . wp_login_url(get_permalink()) . "'>log in</a>"; } $userinfo_html .= "</div>"; } } //==========================================================OUTPUT============================ $html .= $userinfo_html; //include user name and email textboxes if required $t1 = __("Enter Question Title", 'qna-forum');
function q_list_questions($atts, $content) { global $q_question_post_type; $performquery = true; //allows query to be avoided in certian cases //set up parameters for the query $args['post_type'] = $q_question_post_type; $args['post_status'] = 'publish'; if (isset($atts['author'])) { if ($atts['author'] == "%" && is_user_logged_in()) { global $current_user; get_currentuserinfo(); $args['author'] = $current_user->ID; } elseif ($atts['author'] != "%") { $args['author'] = $atts['author']; } else { $performquery = false; //if aksing for current user but current user isnt logged in } } if (isset($atts['category_name'])) { $args['category_name'] = $atts['category_name']; } if (isset($atts['category_id'])) { $args['category_id'] = $atts['category_id']; } $args['posts_per_page'] = get_option('q_num_questions') or '5'; if (isset($atts['questions'])) { $args['posts_per_page'] = $atts['questions']; } //====================================================================style the loop $divstyles = ""; $titlestyles = ""; if (isset($atts['bordercolor'])) { $divstyles = "border: 3px solid " . $atts['bordercolor'] . ";"; $titlestyles .= "background-color:" . $atts['bordercolor'] . ";"; } if (isset($atts['title-color'])) { $titlestyles .= "color:" . $atts['title-color'] . ";"; } if (isset($atts['style'])) { $divstyles .= $atts['style']; } $loophtml = ''; $loophtml .= "<div class='question-cat-menu'>"; $loophtml .= '<select name="event-dropdown" onchange=\'document.location.href=this.options[this.selectedIndex].value;\'><option value="">' . __('Select Category', 'qna-forum') . '</option>'; $categories = get_categories(); foreach ($categories as $category) { $loophtml .= '<option value="/?cat=' . $category->term_id . '&post_type=' . $q_question_post_type . '">' . $category->cat_name; $loophtml .= ' (' . $category->category_count . ')'; $loophtml .= '</option>'; } $loophtml .= '</select>'; $loophtml .= '</div>'; /* // categories================================== $loophtml = "<div class='question-form-bottom'>" . __('Category', 'qna-forum') . "\n<select name='category' id='category"; $categories = get_categories(array( 'type' => 'post', 'orderby' => 'count', 'order' => 'DESC', 'hide_empty' => 0 )); foreach($categories as $cat) { if (get_option('q_cat_' . $cat->term_id) == "TRUE") { $loophtml .= '<option value="' . $cat->term_id . '">' . $cat->cat_name . '</option>'; } } $loophtml .= "</select>\n</div>"; */ //========================================================if loop is not to be performed if ($performquery == false) { $loophtml .= "<div class='question-list' style='" . $divstyles . "'>"; $loophtml .= "<span class='question-list-title' style='{$titlestyles}'>" . __('Login or Register', 'qna-forum') . "</span><div style='margin:10px'><p>" . __('To see your questons or ask new one please log in', 'qna-forum') . "</p>"; $loophtml .= q_loginform(get_permalink()) . "</div></div>"; return $loophtml; } //===========================================================================perform query $q_query = new WP_Query($args); //the loop ==================== $loophtml .= "<div class='question-list' style='{$divstyles}'>"; $loophtml .= "<span class='question-list-title' style='{$titlestyles}'>{$content}</span>"; $loophtml .= "<ul class='q_question_list'>"; if ($q_query->have_posts()) { while ($q_query->have_posts()) { $q_query->next_post(); $question = get_post($q_query->post); $answerCount = get_comments_number($question->ID); $author = $question->post_author ? get_the_author_meta('display_name', $question->post_author) : get_post_meta($question->ID, 'name', true); $post_date = human_time_diff(strtotime($question->post_date_gmt)); $temp_c = get_the_category($question->ID); $cat_name = $temp_c[0]->cat_name; $loophtml .= "<li><span class='list-question-title'><a class='list-answer-link' href='" . get_permalink($question->ID) . "'>" . $question->post_title . "</a></span><span>"; $loophtml .= sprintf(_n("%d answer", "%d answers", $answerCount, 'qna-forum'), $answerCount); $loophtml .= " | " . __('Asked by', 'qna-forum') . "<b>{$author}</b>"; $loophtml .= " | {$post_date} " . __('ago in', 'qna-forum') . " <a href='" . get_category_link($temp_c[0]->cat_ID) . "?post_type=question'>{$cat_name}</a></span>"; $loophtml .= "</li>"; } } $loophtml .= "</ul>"; $loophtml .= "<span class='q_view_more'>" . qarchive_link(array(), __('View All Questions', 'qna-forum')) . '</span></div>'; return $loophtml; }