Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- Plugin Name: Рандомные записи
- Plugin URL: none
- Description: Случайные записи вызываются шорткодом вида [GetCommentsPosts count="4"] где count количество записей, при равном 0 выведет все
- Author: Владимир Марченко
- */
- function GetCommentsPosts($count=0)
- {
- global $wpdb;
- extract( shortcode_atts( array( 'count' => 0 ), $count ) );
- if ( $count == 0){
- $args = array(
- 'numberposts' => 0,
- 'category' => 0,
- 'orderby' => 'rand',
- 'order' => 'DESC',
- 'include' => array(),
- 'exclude' => array(),
- 'meta_key' => '',
- 'meta_value' =>'',
- 'post_type' => 'functions',
- 'suppress_filters' => true, // подавление работы фильтров изменения SQL запроса
- );
- } else {$args = array(
- 'numberposts' => 5,
- 'category' => 0,
- 'orderby' => 'rand',
- 'order' => 'DESC',
- 'include' => array(),
- 'exclude' => array(),
- 'meta_key' => '',
- 'meta_value' =>'',
- 'post_type' => 'functions',
- 'suppress_filters' => true, // подавление работы фильтров изменения SQL запроса
- );}
- // параметры по умолчанию
- $posts = get_posts( $args );
- $lr = true;
- foreach($posts as $post){ setup_postdata($post);
- // print_r($post);
- $thumbnail = get_the_post_thumbnail($post->ID, array(432,432));
- if ($lr) {
- $echo_comments .='<div class="comment_block">'.$thumbnail.' <div class="comment_title">'.$post->post_title.'<div class="comment_descr">'.$post->post_content.'</div></div></div>';
- $lr = false;
- } else {
- $echo_comments .='<div class="comment_block"> <div class="comment_title">'.$post->post_title.'<div class="comment_descr">'.$post->post_content.'</div></div>'.$thumbnail.'</div>';
- $lr = true;
- }
- }
- echo $echo_comments;
- wp_reset_postdata(); // сброс
- }
- add_action( 'init', 'comments_index' );
- function comments_index()
- {
- $labels = array(
- 'name' => 'Список коментариев',
- 'singular_name' => 'Комментарии',
- 'add_new' => 'Добавить комент',
- 'add_new_item' => 'Добавить новый комент',
- 'edit_item' => 'Редактировать комент',
- 'new_item' => 'Новый комент',
- 'all_items' => 'Все коментарии',
- 'view_item' => 'Просмотр комнтариев на сайте',
- 'search_items' => 'Искать комент',
- 'not_found' => 'Коментариев не найдено.',
- 'not_found_in_trash' => 'В корзине нет коментариев.',
- 'menu_name' => 'Комментарии'
- );
- $args = array(
- 'labels' => $labels,
- 'public' => true,
- 'show_ui' => true,
- 'has_archive' => true,
- 'menu_icon' => get_stylesheet_directory_uri() .'/function_icon.png',
- 'menu_position' => 20,
- 'supports' => array( 'title', 'editor', 'comments', 'author', 'thumbnail')
- );
- register_post_type('functions', $args);
- }
- add_shortcode('GetCommentsPosts', 'GetCommentsPosts');
- //add_shortcode('тег шорткода', 'название функции');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement