{"id":4127,"date":"2024-11-10T19:58:05","date_gmt":"2024-11-10T19:58:05","guid":{"rendered":"https:\/\/forestgreen-jay-845795.hostingersite.com\/?p=4127"},"modified":"2025-02-28T23:13:13","modified_gmt":"2025-02-28T20:13:13","slug":"%d0%b7%d0%b0%d0%ba%d1%80%d0%b5%d0%bf%d0%b8%d1%82%d1%8c-%d1%81%d0%bf%d0%b5%d1%86%d0%b8%d1%84%d0%b8%d1%87%d0%b5%d1%81%d0%ba%d1%83%d1%8e-%d0%b7%d0%b0%d0%bc%d0%b5%d1%82%d0%ba%d1%83","status":"publish","type":"post","link":"https:\/\/newsbee.blog\/wp-tips\/2024\/11\/10\/4127\/","title":{"rendered":"\u0417\u0430\u043a\u0440\u0435\u043f\u0438\u0442\u044c \u0432 \u0432\u0435\u0440\u0445\u0443 \u0431\u043b\u043e\u0433\u0430 \u0432\u044b\u0431\u0440\u0430\u043d\u043d\u0443\u044e \u0437\u0430\u043c\u0435\u0442\u043a\u0443"},"content":{"rendered":"<p>\u0414\u0430\u043d\u043d\u044b\u0439 \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442 \u043a\u043e\u0434\u0430 \u0434\u043b\u044f \u0440\u0430\u0437\u043c\u0435\u0449\u0435\u043d\u0438\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043f\u043b\u0430\u0433\u0438\u043d\u0430 Code Snippets \u0437\u0430\u043a\u0440\u0435\u043f\u0438\u0442\/\u043f\u0440\u0438\u043b\u0435\u043f\u0438\u0442 \u043b\u044e\u0431\u0443\u044e \u0437\u0430\u043c\u0435\u0442\u043a\u0443 \u0432 \u0432\u0435\u0440\u0445\u0443 \u0432\u0430\u0448\u0435\u0433\u043e \u0431\u043b\u043e\u0433\u0430 \u0438 \u043e\u0442\u043c\u0435\u043d\u0438\u0442 \u043f\u0440\u0438\u0432\u0438\u043b\u0435\u0433\u0438\u0438 &#171;\u043f\u0440\u0438\u043b\u0435\u043f\u043b\u0435\u043d\u043d\u044b\u0445&#187; \u0437\u0430\u043f\u0438\u0441\u0435\u0439, \u0442.\u0435. \u043e\u043d\u0438 \u0437\u0430\u0439\u043c\u0443\u0442 \u043c\u0435\u0441\u0442\u043e \u0432 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u0438 \u0441 \u0434\u0430\u0442\u043e\u0439 \u0438 \u0432\u0440\u0435\u043c\u0435\u043d\u0435\u043c \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u0438.<\/p>\n<p>\u0418\u043d\u044b\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438, \u0432\u0441\u0435 \u043f\u0440\u0438\u043b\u0435\u043f\u043b\u0435\u043d\u043d\u044b\u0435 \u0437\u0430\u043c\u0435\u0442\u043a\u0438 \u043e\u0441\u0442\u0430\u043d\u0443\u0442\u0441\u044f &#171;\u043f\u0440\u0438\u043b\u0435\u043f\u043b\u0435\u043d\u043d\u044b\u043c\u0438&#187;, \u0445\u043e\u0442\u044f \u0438 \u043d\u0435 \u0431\u0443\u0434\u0443\u0442 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u044c\u0441\u044f \u0432 \u0442\u043e\u043f\u0435.<\/p>\n<p>\u041d\u0438\u0436\u0435 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u044d\u0442\u043e\u0442 \u0441\u043d\u0438\u043f\u043f\u0435\u0442.<\/p>\n<p>\u0415\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0441\u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0437\u0434\u0435\u0441\u044c:<\/p>\n<div class=\"code-block-wrapper\" style=\"position: relative;\">\n        <button class=\"copy-button\" id=\"copy_code_block_69f97dc829ce4\" data-target=\"code_block_69f97dc829ce4\" style=\"\n            position: absolute; \n            top: 10px; \n            right: 10px; \n            background: #0073aa; \n            color: #fff; \n            border: none; \n            padding: 5px 10px; \n            cursor: pointer; \n            font-size: 12px;\n            border-radius: 5px;\">Copy<\/button><\/p>\n<pre><code id=\"code_block_69f97dc829ce4\">\r\nfunction custom_post_ordering($query) {\r\n    \/\/ Only modify the main query on the home page\r\n    if ($query-&gt;is_home() &amp;&amp; $query-&gt;is_main_query()) {\r\n        \/\/ ID of the post you want to show first\r\n        $featured_post_id = 123; \/\/ \u0417\u0430\u043c\u0435\u043d\u0438\u0442\u0435 \u043d\u0430 \u0441\u0432\u043e\u0439 \u043f\u043e\u0441\u0442 \u0441 ID\r\n        \r\n        \/\/ Remove all sticky post functionality\r\n        $query-&gt;set(&#039;ignore_sticky_posts&#039;, 1);\r\n        \r\n        \/\/ Set posts per page\r\n        $posts_per_page = get_option(&#039;posts_per_page&#039;);\r\n        $query-&gt;set(&#039;posts_per_page&#039;, $posts_per_page);\r\n        \r\n        \/\/ Get the current page number\r\n        $paged = (get_query_var(&#039;paged&#039;)) ? get_query_var(&#039;paged&#039;) : 1;\r\n        $query-&gt;set(&#039;paged&#039;, $paged);\r\n        \r\n        \/\/ Modify the query only on the first page\r\n        if ($paged === 1) {\r\n            add_filter(&#039;the_posts&#039;, function($posts, $q) use ($featured_post_id, $posts_per_page) {\r\n                if (!$q-&gt;is_main_query() || !$q-&gt;is_home()) {\r\n                    return $posts;\r\n                }\r\n                \r\n                \/\/ Get the featured post\r\n                $featured_post = get_post($featured_post_id);\r\n                \r\n                if (!$featured_post || $featured_post-&gt;post_status !== &#039;publish&#039;) {\r\n                    return $posts;\r\n                }\r\n                \r\n                \/\/ Remove featured post if it&#039;s already in the results\r\n                $filtered_posts = array_filter($posts, function($post) use ($featured_post_id) {\r\n                    return $post-&gt;ID !== $featured_post_id;\r\n                });\r\n                \r\n                \/\/ Add featured post at the beginning\r\n                array_unshift($filtered_posts, $featured_post);\r\n                \r\n                \/\/ Ensure we maintain the correct number of posts per page\r\n                return array_slice($filtered_posts, 0, $posts_per_page);\r\n                \r\n            }, 10, 2);\r\n        }\r\n    }\r\n}\r\nadd_action(&#039;pre_get_posts&#039;, &#039;custom_post_ordering&#039;);\r\n\r\n\/**\r\n * Optional: Remove all sticky post functionality globally\r\n *\/\r\nfunction remove_sticky_posts() {\r\n    remove_filter(&#039;the_posts&#039;, &#039;_wp_rearrange_sticky_posts&#039;);\r\n}\r\nadd_action(&#039;init&#039;, &#039;remove_sticky_posts&#039;);\r\n<\/code><\/pre>\n<\/p><\/div>\n<p>\u041d\u0435 \u0431\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u0438\u0442\u0435!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u0414\u0430\u043d\u043d\u044b\u0439 \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442 \u043a\u043e\u0434\u0430 \u0434\u043b\u044f \u0440\u0430\u0437\u043c\u0435\u0449\u0435\u043d\u0438\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043f\u043b\u0430\u0433\u0438\u043d\u0430 Code Snippets \u0437\u0430\u043a\u0440\u0435\u043f\u0438\u0442\/\u043f\u0440\u0438\u043b\u0435\u043f\u0438\u0442 \u043b\u044e\u0431\u0443\u044e \u0437\u0430\u043c\u0435\u0442\u043a\u0443 \u0432 \u0442\u043e\u043f\u0435.<\/p>\n <a class=\"read-more-button\" href=\"https:\/\/newsbee.blog\/wp-tips\/2024\/11\/10\/4127\/\">\u0427\u0438\u0442\u0430\u0442\u044c \u0434\u0430\u043b\u0435\u0435<\/a>","protected":false},"author":1,"featured_media":4519,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[41],"tags":[39],"class_list":["post-4127","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-snippets","tag-snippets"],"_links":{"self":[{"href":"https:\/\/newsbee.blog\/wp-tips\/wp-json\/wp\/v2\/posts\/4127","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/newsbee.blog\/wp-tips\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/newsbee.blog\/wp-tips\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/newsbee.blog\/wp-tips\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/newsbee.blog\/wp-tips\/wp-json\/wp\/v2\/comments?post=4127"}],"version-history":[{"count":16,"href":"https:\/\/newsbee.blog\/wp-tips\/wp-json\/wp\/v2\/posts\/4127\/revisions"}],"predecessor-version":[{"id":5745,"href":"https:\/\/newsbee.blog\/wp-tips\/wp-json\/wp\/v2\/posts\/4127\/revisions\/5745"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/newsbee.blog\/wp-tips\/wp-json\/wp\/v2\/media\/4519"}],"wp:attachment":[{"href":"https:\/\/newsbee.blog\/wp-tips\/wp-json\/wp\/v2\/media?parent=4127"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/newsbee.blog\/wp-tips\/wp-json\/wp\/v2\/categories?post=4127"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/newsbee.blog\/wp-tips\/wp-json\/wp\/v2\/tags?post=4127"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}