{"id":8909,"date":"2023-01-05T21:26:03","date_gmt":"2023-01-05T21:26:03","guid":{"rendered":"https:\/\/i-wp-dev.com\/?p=8909"},"modified":"2023-01-05T21:35:19","modified_gmt":"2023-01-05T21:35:19","slug":"sozdanie-plugin-dlya-wordpress-chast-3-sozdanie-single-post-shablona-i-vyvod-polej-carbon-fields","status":"publish","type":"post","link":"https:\/\/i-wp-dev.com\/ru\/sozdanie-plugin-dlya-wordpress-chast-3-sozdanie-single-post-shablona-i-vyvod-polej-carbon-fields\/","title":{"rendered":"\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 Plugin \u0434\u043b\u044f WordPress \u0447\u0430\u0441\u0442\u044c 3. \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 Single post \u0448\u0430\u0431\u043b\u043e\u043d\u0430 \u0438 \u0432\u044b\u0432\u043e\u0434 \u043f\u043e\u043b\u0435\u0439 Carbon Fields"},"content":{"rendered":"\n

\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0432\u044b\u0432\u043e\u0434 \u043d\u0430\u0448\u0435\u0433\u043e \u0430\u0432\u0442\u043e\u043c\u043e\u0431\u0438\u043b\u044f \u0438 \u0432\u0441\u0435\u0445 \u043f\u043e\u043b\u0435\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u043b\u0438 \u0432 \u043f\u0440\u043e\u0448\u043b\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435.<\/p>\n\n\n\n

\u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0432<\/strong><\/h3>\n\n\n\n

\u041d\u0430\u0447\u043d\u0435\u043c \u0441 \u0442\u043e\u0433\u043e-\u0447\u0442\u043e \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043a\u043e\u0440\u043d\u0435 \u043d\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u043f\u0430\u043f\u043a\u0443 assets<\/em> \u0438 \u0441\u043a\u043e\u043f\u0438\u0440\u0443\u0435\u043c \u0442\u0443\u0434\u0430 \u0432\u0441\u0435 \u0444\u0430\u0439\u043b\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0440\u0438\u0448\u043b\u0438 \u043d\u0430\u043c \u0441 \u0432\u0435\u0440\u0441\u0442\u043a\u043e\u0439<\/p>\n\n\n\n

\u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0443\u0436\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0432 \u0444\u0430\u0439\u043b Main.php<\/em> \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044e init \u0445\u0443\u043a \u0434\u043b\u044f \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0432 \u0438 \u0441\u0442\u0438\u043b\u0435\u0439<\/p>\n\n\n\n

add_action( 'wp_enqueue_scripts', [ $this, 'add_scripts' ] );<\/code><\/pre>\n\n\n\n

\u0418 \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u044d\u0442\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u044e<\/p>\n\n\n\n

public function add_scripts(): void {
\n   wp_enqueue_script( 'ecl_build', ECL_URL <\/em>. '\/assets\/js\/build.js', [ 'jquery' ], ECL_VERSION<\/em>, true );
\n   wp_enqueue_script( 'html5shiv', '\/\/oss.maxcdn.com\/libs\/html5shiv\/3.7.0\/html5shiv.js', [], '3.7.0', false );
\n   wp_enqueue_script( 'respond', '\/\/oss.maxcdn.com\/libs\/respond.js\/1.4.2\/respond.min.js', [], '1.4.2', false );
\n
\n   wp_script_add_data( 'html5shiv', 'conditional', 'lt IE 9' );
\n   wp_script_add_data( 'respond', 'conditional', 'lt IE 9' );
\n
\n   wp_enqueue_style( 'ecl_main', ECL_URL <\/em>. '\/assets\/css\/main.css', '', ECL_VERSION <\/em>);
\n
\n   $global_style = ':root{ --color-one:#f26b36; --color-two:#be542a;}';
\n   wp_add_inline_style( 'ecl_main', $global_style );
\n}<\/code><\/pre>\n\n\n\n

wp_enqueue_script<\/em> \u2013 \u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u0442 \u0441\u043a\u0440\u0438\u043f\u0442<\/p>\n\n\n\n

wp_script_add_data<\/em> \u2013 \u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442 \u0443\u0441\u043b\u043e\u0432\u0438\u044f \u043f\u0440\u0438 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0438 \u0441\u043a\u0440\u0438\u043f\u0442\u0430  <\/p>\n\n\n\n

wp_enqueue_style<\/em> \u2013 \u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u0442 \u0441\u0442\u0438\u043b\u0438<\/p>\n\n\n\n

wp_add_inline_style<\/em> \u2013 \u0412\u044b\u0432\u043e\u0434\u0438\u0442 \u0432 \u0448\u0430\u043f\u043a\u0438 \u0441\u0442\u0438\u043b\u0438 \u0438\u043d\u043b\u0430\u0439\u043d<\/p>\n\n\n\n

<\/p>\n\n\n\n

\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0444\u0438\u043b\u044c\u0442\u0440\u0430 \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0448\u0430\u0431\u043b\u043e\u043d\u0430 \u0432\u044b\u0432\u043e\u0434\u0430<\/strong><\/h3>\n\n\n\n

\u041f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u043c \u043a \u0444\u0430\u0439\u043b\u0443 AddCPT.php <\/em>\u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0444\u0438\u043b\u044c\u0442\u0440 \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044e init<\/em><\/p>\n\n\n\n

add_filter( 'template_include', [ $this, 'add_single_car_page' ] );<\/code><\/pre>\n\n\n\n

\u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0443\u0441\u043b\u043e\u0432\u0438\u044f \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0448\u0430\u0431\u043b\u043e\u043d\u0430<\/p>\n\n\n\n

\/**
\n * Add single car template.
\n *
\n * @param <\/strong>string <\/em>$template
\n <\/em>*
\n * @return <\/strong>string
\n *\/
\n<\/em>public function add_single_car_page( string $template ): string {
\n
\n   if ( is_singular( 'cars' ) && ! locate_template( [ 'single-cars.php' ] ) ) {
\n      return ECL_PATH <\/em>. '\/template\/single-cars.php';
\n   }
\n
\n   return $template;
\n}<\/code><\/pre>\n\n\n\n

\u0412 \u0443\u0441\u043b\u043e\u0432\u0438\u0438 \u043c\u044b \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u044d\u0442\u043e \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0430 \u0430\u0432\u0442\u043e\u043c\u043e\u0431\u0438\u043b\u044f \u0438 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0448\u0430\u0431\u043b\u043e\u043d single-<\/em>cars.<\/em>php<\/em>  \u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u043e\u0439 \u0442\u0435\u043c\u0435.<\/p>\n\n\n\n

\u0415\u0441\u043b\u0438 \u0448\u0430\u0431\u043b\u043e\u043d\u0430 \u043d\u0435\u0442 \u0442\u043e \u043e\u043d \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u0441 \u043f\u0430\u043f\u043a\u0438 template <\/em>\u00a0\u0441 \u043a\u043e\u0440\u043d\u0435\u0432\u043e\u0439 \u043f\u0430\u043f\u043a\u0438 \u043d\u0430\u0448\u0435\u0433\u043e \u043f\u043b\u0430\u0433\u0438\u043d\u0430<\/p>\n\n\n\n

<\/p>\n\n\n\n

is_singular<\/em> \u2013 \u041f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 \u043f\u0440\u043e\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u043b\u0438 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0430 \u0437\u0430\u043f\u0438\u0441\u0438<\/p>\n\n\n\n

locate_template<\/em> — \u041d\u0430\u0445\u043e\u0434\u0438\u0442 \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u044f\u0449\u0438\u0439 \u0441\u0435\u0440\u0432\u0435\u0440\u043d\u044b\u0439 \u043f\u0443\u0442\u044c \u043a \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u043c\u0443 \u0444\u0430\u0439\u043b\u0443 \u0448\u0430\u0431\u043b\u043e\u043d\u0430. \u041f\u0440\u0438 \u043f\u043e\u0438\u0441\u043a\u0435 \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0434\u043e\u0447\u0435\u0440\u043d\u044f\u044f \u0442\u0435\u043c\u0430.<\/p>\n\n\n\n

\u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0432\u0435\u0440\u0441\u0442\u043a\u0438<\/strong><\/h3>\n\n\n\n

\u0421\u043e\u0437\u0434\u0430\u0435\u043c \u043f\u0430\u043f\u043a\u0443 template \u0432 \u043a\u043e\u0440\u043d\u0435 \u043d\u0430\u0448\u0435\u0433\u043e \u043f\u043b\u0430\u0433\u0438\u043d\u0430 \u0438 \u0432 \u043d\u0435\u0439 \u0444\u0430\u0439\u043b single-cars.php<\/em><\/p>\n\n\n\n

\u041a\u043e\u043f\u0438\u0440\u0443\u0435\u043c \u0442\u0443\u0434\u0430 \u043d\u0430\u0448\u0435 \u0432\u0435\u0440\u0441\u0442\u043a\u0443 \u0435\u0435 \u043c\u043e\u0436\u0435\u043c \u043d\u0430\u0439\u0442\u0438 \u043f\u043e \u0441\u0441\u044b\u043b\u043a\u0435: https:\/\/drive.google.com\/file\/d\/1dF94sQjEREAOG3jLGMr3OqX4wSCwMc6n\/view?usp=share_link<\/a><\/p>\n\n\n\n

<\/p>\n\n\n\n

\u041f\u043e\u043b\u043d\u044b\u0439 \u043a\u043e\u0434 \u0444\u0430\u0439\u043b\u0430 \u043f\u043e \u0441\u0441\u044b\u043b\u043a\u0435 https:\/\/gitlab.com\/AlsconWeb\/ease-car-listing\/-\/blob\/16d71d9a5677e4944619b3069aac5f8ffde98320\/template\/single-cars.php<\/a><\/p>\n\n\n\n

<\/p>\n\n\n\n

carbon_<\/em>get_<\/em>the_<\/em>post_<\/em>meta(\u201c\u0418\u043c\u044f \u043f\u043e\u043b\u044f \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c\u201d)<\/em> \u2013 \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0432 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u043c \u0446\u0438\u043a\u043b\u0435<\/p>\n\n\n\n

\u0415\u0441\u043b\u0438 \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u044d\u0442\u043e \u043f\u043e\u043b\u0435 \u0432 \u043d\u0435 \u0446\u0438\u043a\u043b\u0430 \u0442\u043e\u0433\u0434\u0430 \u043d\u0443\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c<\/p>\n\n\n\n

carbon_<\/em>get_<\/em>post_<\/em>meta(\u201c\u0418\u0414 \u043f\u043e\u0441\u0442\u0430 \u043a \u043a\u043e\u0442\u043e\u0440\u043e\u043c\u0443 \u043f\u0440\u0438\u0432\u044f\u0437\u0430\u043d\u043e \u043f\u043e\u043b\u0435\u201d, \u201c\u0418\u043c\u044f \u043f\u043e\u043b\u044f \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c\u201d)<\/em><\/p>\n\n\n\n

numfmt_create<\/em> \u00a0\u2014\u00a0\u0421\u043e\u0437\u0434\u0430\u0451\u0442 \u0441\u0440\u0435\u0434\u0441\u0442\u0432\u043e \u0444\u043e\u0440\u043c\u0430\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0447\u0438\u0441\u0435\u043b<\/p>\n\n\n\n

<\/p>\n\n\n\n

\n