6ответ(ов) в теме
function last_posts_forum(){ global $post; global $wpdb; $comments=$wpdb->get_results("SELECT * FROM wp_sfposts ORDER BY post_date DESC LIMIT 5"); $comment_list = '<div class="widget_comments widget"> <div class="caption"><h3>Последнее на форуме</h3></div>'; $comment_list .= '<ul class="home-list">'; foreach ($comments as $comment) { $slug_topic = $wpdb->get_var("SELECT topic_slug FROM wp_sftopics WHERE topic_id = '$comment->topic_id'"); $slug_forum = $wpdb->get_var("SELECT forum_slug FROM wp_sfforums WHERE forum_id = '$comment->forum_id'"); $com_link = sp_build_url($slug_forum, $slug_topic,'',$comment->post_id); $comment_list .= '<li>'; $comment_list .= '<div class="avatar" style="width:50px">'.get_avatar( $comment->user_id, 50 ).'</div>'; $get_the_comment_length = 120; if(( iconv_strlen($txt=strip_tags($comment->post_content), 'utf-8') > $get_the_comment_length )) { $txt=iconv_substr($txt, 0, $get_the_comment_length, 'utf-8'); $txt = preg_replace('@(.*)s[^s]*$@s', '\1', $txt); } $comment_list .= '<span class="comment">'.$txt.'...</span>'; $comment_list .= '<a href='.$com_link.'> Читать далее...</a> </li>'; } $comment_list .= '</ul></div>'; return $comment_list; } add_shortcode('last-posts-forum','last_posts_forum');
В нужном месте разместить шорткод last-posts-forum
Тема закрыта. Публикация новых сообщений запрещена.