Задать вопрос
  • Какие плагины для Wordpress позволяют фильтровать данные?

    @Kypidon4ik
    Refguser, у него в тегах вопроса WP, какой opencart (рукалицо)
  • Какие плагины для Wordpress позволяют фильтровать данные?

    @Kypidon4ik
    Refguser, а кто сказал на чем именно ему нужны фильтры ? Чел показал скрин я лишь показал как это можно сделать (1 из вариантов). В тз не было формулировки без woo
  • После подключения Sass никаких измений в HTML?

    @Kypidon4ik
    Нам на кофейной гуще гадать ? Где код ? Что значит в гугле нет решений ?
  • Объясните почему в одном случае предпросмотр работает корректно, в другом же нет?

    @Kypidon4ik Автор вопроса
    WP Panda, в точку
    <?php
    $meri_args = array(
        'post_status' => 'publish',
        'posts_per_page' => 2,
        'post_type' => 'news',
        'post__not_in' => array($post->ID),
    );
    
    $meri_posts = get_posts($meri_args);
    ?>
  • Объясните почему в одном случае предпросмотр работает корректно, в другом же нет?

    @Kypidon4ik Автор вопроса
    WP Panda, да
    <?php foreach ($meri_posts as $post) : ?>
    <?php render_news_whole_post($post->ID); ?> // и далее код исполняется который выше 
    <?php endforeach; ?>
  • Объясните почему в одном случае предпросмотр работает корректно, в другом же нет?

    @Kypidon4ik Автор вопроса
    WP Panda, спасибо, но заголовок все также не изменен пока я не сохраню его
  • Объясните почему в одном случае предпросмотр работает корректно, в другом же нет?

    @Kypidon4ik Автор вопроса
    <?php
    
    require_once(COMPONENTS_PATH . "icons/camera-icon.php");
    require_once(COMPONENTS_PATH . "icons/video-content-icon.php");
    require_once(COMPONENTS_PATH . 'line-news-list-item.php');
    
    require_once(COMPONENTS_PATH . 'content-exist-markers.php');
    
    function render_news_whole_post($id, $cat = NULL)
    {
        $single_post = get_post($id);
    	gt_set_post_view($id);
        $author_id = $single_post->post_author;
        $taxonomies = get_my_taxonomies($id);
        if (!empty($taxonomies)) {
            $primary_category = get_post_primary_category($id, $taxonomies);
            if(!empty($primary_category['primary_category'])){
                $primary_category = $primary_category['primary_category'];
                $cat_link = home_url();
                $cat_link .= '/';
                $cat_link .= $primary_category->taxonomy;
                $cat_link .= '/';
                $cat_link .= $primary_category->slug;
            }
        }
        ?>
        <div class="post" data-url="<?php echo get_permalink($id)?>">
            <div class="post-header">
                <div class="content-exists">
                    <div class="content">
                        <?php $exist_markers = render_content_exist_markers($id); ?>
                        <?php if ($exist_markers): ?>
                            <?php echo $exist_markers; ?>
                        <?php endif; ?>
                    </div>
                    <?php if (isset($cat_link)): ?>
                        <div class="tags">
                            <a href="<?php echo $cat_link; ?>" class="tags__link">
                            <span>
                                <?php echo $primary_category->name; ?>
                            </span>
                            </a>
                        </div>
                    <?php endif; ?>
                </div>
                <div class="title">
    				<span>
    					<?php //echo get_the_title($single_post->ID); ?>
    					<?php echo get_the_title(); ?>
    				</span>
                </div>
                <div class="share">
                    <div class="date">
    					<span>
    						<?php echo date("H:i", strtotime($single_post->post_date)); ?>
    					</span>
                        <span>
    						<?php echo date("d.m.Y", strtotime($single_post->post_date)); ?>
    					</span>
                    </div>
                </div>
    			<?php if (function_exists('nvvc_visitors_views_shortcode'))
    			{
    			    echo nvvc_visitors_views_shortcode($id);
    			}
    	        else
    			{
    				echo gt_in_post_view($id);
    			}
    			?>
            </div>
            <?php
            //$content = apply_filters('the_content', $single_post->post_content, $single_post->ID);
            ?>
            <div class="page-content">
                <?php// echo $content; ?> 
    			<?php the_content(); ?>
                <?php $is_advertising = carbon_get_post_meta($single_post->ID, 'news_is_advertising'); ?>
                <?php if ($is_advertising) : ?>
                    <div class="adv__info">
                        <span class="adv_icon__box"><?php render_advertising_icon(); ?></span>
                        <span class="adv_text__box"><?php echo carbon_get_post_meta($single_post->ID, 'news_text_advertising'); ?></span>
                    </div>
                <?php endif; ?>
            </div>
            <div class="footer-content">
                <div class="author-info">
                    <div class="author-image">
                        <?php echo get_avatar($author_id); ?>
                    </div>
                    <div class="author-details">
                        <span class="label">Автор материалов</span>
                        <span class="name"><?php echo the_author_meta('display_name', $author_id); ?></span>
                        <a href="<?php echo get_author_posts_url($author_id); ?>" class="other-posts">Все новости автора</a>
                    </div>
                </div>
                <?php echo share_links($id); ?>
            </div>
        </div>
        <?php
    }
  • Объясните почему в одном случае предпросмотр работает корректно, в другом же нет?

    @Kypidon4ik Автор вопроса
    У Worpdress есть такая штука как предпросмотр записи , он не корректно работает
  • Почему не заходит в админку WordPress?

    @Kypidon4ik
    pet1987, Может скрипт в самой теме ? Попробуй поставить дефолтную тему
  • Почему не заходит в админку WordPress?

    @Kypidon4ik
    pet1987, Ну выпели все плагины сайта и заходи
  • Почему не заходит в админку WordPress?

    @Kypidon4ik
    Задайте вопрос хостингу, может ТП не тянет ?
    Сайт вообще открывается ?
  • Как разрешить сохранение cookie в google chrome?

    @Kypidon4ik
    Все же на скриншоте, для управление фаилами куки перейдите в настройки
  • Почему продолжает индексироваться сайт?

    @Kypidon4ik
    Роботы проходятся по вашему сайту не каждую минуту , или ждите или через вебмастер как написал Ankhena
  • Где проблема в коде плагина?

    @Kypidon4ik Автор вопроса
    Исправленный код плагина

    <?php
    /*
     *Plugin Name: News Views and Visitors Counter
     *Plugin URI: https://example.com/
     *Description: This plugin counts the number of unique visitors of each news post.
     *Version: 0.4
     *Author: Strah Roman
     *Author URI: https://vk.com/strah_roman
     *License: GPLv2 or later
     *License URI: https://www.gnu.org/licenses/gpl-2.0.html
    */
    register_activation_hook(__FILE__, 'nvvc_create_table');
    add_action('admin_menu', 'nvvc_unique_visitors_counter');
    function nvvc_unique_visitors_counter()
    {
    	add_menu_page(
    		"Статистика по новостям",
    		"Статистика новости (+уникальные)",
    		"edit_others_posts",
    		"nvvc-unique-visitors-counter",
    		"nvvc_unique_visitors_counter_page"
    	);
    }
    
    function nvvc_create_table()
    {
    // Set up the database table for tracking views and visitors.
    	global $wpdb;
    	$table_name = $wpdb->prefix . 'news_stats';
    	$charset_collate = $wpdb->get_charset_collate();
    	$sql = "CREATE TABLE $table_name (
        id BIGINT(20) NOT NULL AUTO_INCREMENT,
        post_id BIGINT(20) NOT NULL,
        views BIGINT(20) DEFAULT 0,
        unqviews BIGINT(20) DEFAULT 0,
    	ip VARCHAR(64) NOT NULL,
        date DATE NOT NULL,
        PRIMARY KEY  (id)
    ) $charset_collate;";
    	require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
    	dbDelta($sql);
    }
    
    // Define the function that will run when the post is displayed
    function nvvc_count_views($id)
    {
    	global $wpdb;
    	$table_name = $wpdb->prefix . 'news_stats';
    	$ip = $_SERVER['REMOTE_ADDR'];
    	$today = date('Y-m-d');
    	$check_ip = $wpdb->get_results($wpdb->prepare(
    		"SELECT * FROM $table_name WHERE post_id = %d AND ip = %s AND date = %s",
    		$id,
    		$ip,
    		$today
    	));
        // Check if the IP address has already visited the post today
    	if (empty($check_ip)) {
            // If not, insert a new row in the database to count the visitor
    		$wpdb->query(
    			$wpdb->prepare(
    				"INSERT INTO $table_name (post_id, views, unqviews, ip, date) VALUES (%d, %d, %d, %s, %s)",
    				$id,
    				1,
    				1,
    				$ip,
    				$today
    			)
    		);
    	} else {
    		// Update the view count in the database
    		$wpdb->query($wpdb->prepare(
    			"UPDATE $table_name SET views = views + 1 WHERE post_id = %d AND ip = %s AND date = %s",
    			$id,
    			$ip,
    			$today
    		));
    	}
    }
    
    function nvvc_unique_visitors_counter_page() 
    {
        global $wpdb;
        $table_name = $wpdb->prefix . 'news_stats';
        // Check if the user has permission to access this page
        if (!current_user_can("edit_others_posts")) {
            wp_die("You do not have sufficient permissions to access this page.");
        }
        
        // Check if a query has been submitted
        if (isset($_POST["limit_count"])
            and isset($_POST["date_from"])
            and isset($_POST["date_to"])
            and isset($_POST["limit_count"])) {
            $limit_count = $_POST["limit_count"];
            $date_to = $_POST["date_to"];
            $date_from = $_POST["date_from"];
            if (strtotime($date_from) > strtotime($date_to)) {
                echo '<div class="error"><p> Значение "Дата от" не может быть больше значания "Дата до" </p></div>';
            }
            $sql = $wpdb->prepare(
                "SELECT post_id, SUM(views) AS total_views, SUM(unqviews) AS unique_views 
                 FROM $table_name nvvc JOIN $wpdb->posts wpp ON nvvc.post_id = wpp.ID 
                 WHERE wpp.post_date BETWEEN %s AND %s
                 GROUP BY post_id
                 ORDER BY unique_views DESC LIMIT %d",
                $date_from . " 00:00:00",
                $date_to . " 23:59:59",
                $limit_count
            );
            $results = $wpdb->get_results($sql);
            // Prepare the table for displaying the results
            echo '<table>';
            echo '<thead><tr><th>Post ID</th><th>Title</th><th>URL</th><th>Unique views</th><th>Total views</th></tr></thead>';
            echo '<tbody>';
            if ($results) {
                // Iterate over the results and display them in the table
    			$sample_total=0;
    			$sample_total_unq=0;
                foreach ($results as $result) {
    				$sample_total=$sample_total+$result->total_views;
    				$sample_total_unq=$sample_total_unq+$result->unique_views;
                    echo '<tr>';
                    echo '<td>' . $result->post_id . '</td>';
    				echo '<td>' . get_the_title($result->post_id) . '</td>';
    				echo '<td>' . get_permalink($result->post_id) . '</td>';
    				echo '<td>' . $result->unique_views . '</td>';
                    echo '<td>' . $result->total_views . '</td>';
                    echo '</tr>';
                }
            } else {
                // Display a message if no results were found
                echo '<tr><td colspan="3">No results found.</td></tr>';
            }
    		echo '<div class="updated"><p>Общее кол-во просмотров (по выборке): ' . $sample_total . '</p></div>';
    		echo '<div class="updated"><p>Общее кол-во уникальных посетителей (по выборке): ' . $sample_total_unq . '</p></div>';
            echo '</tbody>';
            echo '</table>';
        } 
    ?>
    <div class="wrap">
            <h1>Посещалка сайта</h1>
            <form method="post">
    		    <label for="custom_query">Дата от</label>
    			</br>
    			<input id="date_from" type="date" name="date_from" value="<?php echo date("Y-m-d",strtotime("-1 day")); ?>">
    			</br>
    			<label for="custom_query">Дата до</label>
    			</br>
    			<input id="date_to" type="date" name="date_to" value="<?php echo date(
           "Y-m-d",
           strtotime("-1 day")
       ); ?>">
    			</br>
    			<label for="custom_query">Лимит вывода</label>
    			</br>
    			<input id="limit_count" type="number" name="limit_count" value="100" min="1" max="300">			
    			</br>
                <input type="submit" value="Enter" class="button button-primary">
            </form>
        </div>
    <?php	
    }

  • Где проблема в коде плагина?

    @Kypidon4ik Автор вопроса
    Алексей Уколов, я видимо что то упустил , сделал как по ссылке выше , все равно не выходит что-то
    код

    <?php
    /*
     *Plugin Name: News Views and Visitors Counter
     *Plugin URI: https://example.com/
     *Description: This plugin counts the number of unique visitors of each news post.
     *Version: 0.4
     *Author: Strah Roman
     *Author URI: https://vk.com/strah_roman
     *License: GPLv2 or later
     *License URI: https://www.gnu.org/licenses/gpl-2.0.html
    */
    register_activation_hook(__FILE__, 'nvvc_create_table');
    add_action('admin_menu', 'nvvc_unique_visitors_counter');
    function nvvc_unique_visitors_counter()
    {
    	add_menu_page(
    		"Статистика по новостям",
    		"Статистика новости",
    		"edit_others_posts",
    		"nvvc-unique-visitors-counter",
    		"nvvc_unique_visitors_counter_page"
    	);
    }
    
    function nvvc_create_table()
    {
    // Set up the database table for tracking views and visitors.
    	global $wpdb;
    	$table_name = $wpdb->prefix . 'news_stats';
    	$charset_collate = $wpdb->get_charset_collate();
    	$sql = "CREATE TABLE $table_name (
        id BIGINT(20) NOT NULL AUTO_INCREMENT,
        post_id BIGINT(20) NOT NULL,
        views BIGINT(20) DEFAULT 0,
        unqviews BIGINT(20) DEFAULT 0,
    	ip VARCHAR(64) NOT NULL,
        date DATETIME NOT NULL,
        PRIMARY KEY  (id)
    ) $charset_collate;";
    	require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
    	dbDelta($sql);
    }
    
    // Define the function that will run when the post is displayed
    function nvvc_count_views($id)
    {
    	global $wpdb;
    	$table_name = $wpdb->prefix . 'news_stats';
    	$ip = $_SERVER['REMOTE_ADDR'];
    	$today = date('Y-m-d H:i:s');
    	$check_ip = $wpdb->prepare(
    		"SELECT ip FROM %s WHERE post_id = %d AND ip = %s AND date = %s DESC LIMIT 1",
    		$table_name,
    		$id,
    		$ip,
    		$today
    	);
    	$results_check_ip=$wpdb->get_results($check_ip);
        
        // Check if the IP address has already visited the post today
    	if (empty($results_check_ip)) {
            // If not, insert a new row in the database to count the visitor
    		$wpdb->query(
    			$wpdb->prepare(
    				"INSERT INTO %s (post_id, views, unqviews, ip, date) VALUES (%d, %d, %d, %s, %s)",
    				$table_name,
    				$id,
    				1,
    				1,
    				$ip,
    				$today
    			)
    		);
    	} else {
    		// Update the view count in the database
    		$wpdb->query($wpdb->prepare(
    			"UPDATE %s SET views = views+1 WHERE post_id = %d AND ip = %s AND date = %s",
    			$table_name,
    			$id,
    			$ip,
    			$today
    		));
    	}
    }
    
    function nvvc_unique_visitors_counter_page() 
    {
       global $wpdb;
        $table_name = $wpdb->prefix . 'news_stats';
        // Check if the user has permission to access this page
        if (!current_user_can("edit_others_posts")) {
            wp_die("You do not have sufficient permissions to access this page.");
        }
        
        // Check if a query has been submitted
        if (isset($_POST["limit_count"])
            and isset($_POST["date_from"])
            and isset($_POST["date_to"])
            and isset($_POST["limit_count"])) {
            $limit_count = $_POST["limit_count"];
            $date_to = $_POST["date_to"];
            $date_from = $_POST["date_from"];
            if (strtotime($date_from) > strtotime($date_to)) {
                echo '<div class="error"><p> Значение "Дата от" не может быть больше значания "Дата до" </p></div>';
            }
            $sql = $wpdb->prepare(
                "SELECT post_id, SUM(views) AS total_views, SUM(unqviews) AS unique_views 
                 FROM $table_name nvvc JOIN $wpdb->posts wpp ON nvvc.post_id = wpp.ID 
                 WHERE wpp.post_date BETWEEN %s AND %s
                 GROUP BY post_id
                 ORDER BY views DESC LIMIT %d",
                $date_from,
                $date_to,
                $limit_count
            );
            $results = $wpdb->get_results($sql);
            // Prepare the table for displaying the results
            echo '<table>';
            echo '<thead><tr><th>Post ID</th><th>Total views</th><th>Unique views</th></tr></thead>';
            echo '<tbody>';
            if ($results) {
                // Iterate over the results and display them in the table
                foreach ($results as $result) {
                    echo '<tr>';
                    echo '<td>' . $result->post_id . '</td>';
                    echo '<td>' . $result->total_views . '</td>';
                    echo '<td>' . $result->unique_views . '</td>';
                    echo '</tr>';
                }
            } else {
                // Display a message if no results were found
                echo '<tr><td colspan="3">No results found.</td></tr>';
            }
            echo '</tbody>';
            echo '</table>';
        } 
    ?>
    <div class="wrap">
            <h1>Посещалка сайта</h1>
            <form method="post">
    		    <label for="custom_query">Дата от</label>
    			</br>
    			<input id="date_from" type="date" name="date_from" value="<?php echo date("Y-m-d",strtotime("-1 day")); ?>">
    			</br>
    			<label for="custom_query">Дата до</label>
    			</br>
    			<input id="date_to" type="date" name="date_to" value="<?php echo date(
           "Y-m-d",
           strtotime("-1 day")
       ); ?>">
    			</br>
    			<label for="custom_query">Лимит вывода</label>
    			</br>
    			<input id="limit_count" type="number" name="limit_count" value="100" min="1" max="300">			
    			</br>
                <input type="submit" value="Enter" class="button button-primary">
            </form>
        </div>
    <?php	
    }


    PS Вывод в админку sql запроса работает корректно , проблема с добавление записей в таблицу
  • Где проблема в коде плагина?

    @Kypidon4ik Автор вопроса
    Правильно ли я понимаю что запросы все кроме Select нужно обернуть в $wpdb->query() ? А для Select $wpdb->get_results() ?