Compare commits
14 Commits
00b7dbd0b7
...
master
Author | SHA1 | Date | |
---|---|---|---|
a10ce9018b | |||
9a72b52c93 | |||
fd894e1ace | |||
830c66689b | |||
793f6914f0 | |||
dd365de9ff | |||
35d1270a4b | |||
c1cdedb758 | |||
95462c02ba | |||
c09a941d3f | |||
640ee20f26 | |||
fd7603c63b | |||
42b8c3b8f1 | |||
c6069b6f0d |
11
api-readmi.txt
Normal file
11
api-readmi.txt
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
API
|
||||||
|
|
||||||
|
API принимает запросы по URL /wp-json/api-posts/v1/endlessPosts
|
||||||
|
|
||||||
|
Через GET-запрос принимает значение permalink, выводит информацию по посту чей permalink пришёл, далее 10 пермалинков и
|
||||||
|
ID постов из совпадающих категорий.
|
||||||
|
|
||||||
|
UPD: Принимает значение paged, отвечает за смену страниц во время поисков постов. Принимает int номера страницы.
|
||||||
|
|
||||||
|
Пример:
|
||||||
|
/wp-json/api-posts/v1/endlessPosts?permalink=http://pamtest.ru/641-kak-zarabatyvat-bolshe-na-osago-i-ipotechnom-strahovanii/
|
103
wp-content/themes/simple-theme/api-posts/api-posts.php
Normal file
103
wp-content/themes/simple-theme/api-posts/api-posts.php
Normal file
@ -0,0 +1,103 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
add_action('rest_api_init', 'endlessPosts');
|
||||||
|
|
||||||
|
function endlessPosts()
|
||||||
|
{
|
||||||
|
register_rest_route('api-posts/v1', "/endlessPosts", array(
|
||||||
|
'methods' => WP_REST_Server::READABLE,
|
||||||
|
'callback' => 'getEndlessPostsResults'
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
function getEndlessPostsResults($data)
|
||||||
|
{
|
||||||
|
global $wpdb;
|
||||||
|
|
||||||
|
$link = $data['permalink'];
|
||||||
|
$paged = $data['paged'];
|
||||||
|
|
||||||
|
if ($paged < 0){
|
||||||
|
$paged = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
$result = [];
|
||||||
|
|
||||||
|
$tag_slug = url_to_postid($link); //Получаем айди поста по пермалинку
|
||||||
|
$tags = get_the_tags($tag_slug); //Получаем тэги по айди
|
||||||
|
$i = 0;
|
||||||
|
$postSlugs = [];
|
||||||
|
|
||||||
|
if (!$tags){
|
||||||
|
$tags = 'null';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is_array($tags) && count($tags) > 0) {
|
||||||
|
$postSlugs = array_column($tags, 'term_id');
|
||||||
|
} else {
|
||||||
|
// Handle the case when no tags are found
|
||||||
|
$postSlugs = array(); // or some other default value
|
||||||
|
}
|
||||||
|
|
||||||
|
$id_from_permalink = explode('/', $link);
|
||||||
|
$id_from_permalink = explode('-', $id_from_permalink[3]);
|
||||||
|
|
||||||
|
$id = $id_from_permalink[0];
|
||||||
|
|
||||||
|
$requestedPostFromPermalink = get_post($id);
|
||||||
|
|
||||||
|
$requestedPost = [
|
||||||
|
'id' => $requestedPostFromPermalink->ID,
|
||||||
|
"post_author" => $requestedPostFromPermalink->post_author,
|
||||||
|
"post_date" => $requestedPostFromPermalink->post_date,
|
||||||
|
"post_date_gmt" => $requestedPostFromPermalink->post_date_gmt,
|
||||||
|
"post_content" => $requestedPostFromPermalink->post_content,
|
||||||
|
"post_title" => $requestedPostFromPermalink->post_title,
|
||||||
|
"post_excerpt" => $requestedPostFromPermalink->post_excerpt,
|
||||||
|
"post_status" => $requestedPostFromPermalink->post_status,
|
||||||
|
"comment_status" => $requestedPostFromPermalink->comment_status,
|
||||||
|
"ping_status" => $requestedPostFromPermalink->ping_status,
|
||||||
|
"post_password" => $requestedPostFromPermalink->post_password,
|
||||||
|
"post_name" => $requestedPostFromPermalink->post_name,
|
||||||
|
"to_ping" => $requestedPostFromPermalink->to_ping,
|
||||||
|
"pinged" => $requestedPostFromPermalink->pinged,
|
||||||
|
"post_modified" => $requestedPostFromPermalink->post_modified,
|
||||||
|
"post_modified_gmt" => $requestedPostFromPermalink->post_modified_gmt,
|
||||||
|
"post_content_filtered" => $requestedPostFromPermalink->post_content_filtered,
|
||||||
|
"post_parent" => $requestedPostFromPermalink->post_parent,
|
||||||
|
"guid" => $requestedPostFromPermalink->guid,
|
||||||
|
"menu_order" => $requestedPostFromPermalink->menu_order,
|
||||||
|
"post_type" => $requestedPostFromPermalink->post_type,
|
||||||
|
"post_mime_type" => $requestedPostFromPermalink->post_mime_type,
|
||||||
|
"comment_count" => $requestedPostFromPermalink->comment_count,
|
||||||
|
"filter" => $requestedPostFromPermalink->filter,
|
||||||
|
];
|
||||||
|
|
||||||
|
$result[] = ['requested-post' => $requestedPost];
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
$args = array( // Создаем массив с параметрами запроса
|
||||||
|
'tag__and' => $postSlugs,
|
||||||
|
'posts_per_page' => 10,
|
||||||
|
'paged' =>$paged,
|
||||||
|
'orderby'=>'date',
|
||||||
|
'order'=> 'DESC'
|
||||||
|
);
|
||||||
|
|
||||||
|
$posts = new WP_Query($args); // Инициализация запроса
|
||||||
|
while ( $posts->have_posts() ) {
|
||||||
|
$posts->the_post();
|
||||||
|
$result[] = array(
|
||||||
|
'id' => get_the_ID(),
|
||||||
|
'permalink' => get_the_permalink(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//"http://pamtest.ru/702-oformlenie-osago-na-a-b-c-d-otkryto-vsem-agenta/"
|
||||||
|
|
||||||
|
//"http://pamtest.ru/294-6-j-urok-kak-strahovomu-agentu-zadavat-voprosy-i-rabotat-s-vozrazheniyami/"
|
5
wp-content/themes/simple-theme/api-template.php
Normal file
5
wp-content/themes/simple-theme/api-template.php
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<?php
|
||||||
|
/*
|
||||||
|
* Template name: api-template
|
||||||
|
* description: >-
|
||||||
|
*/
|
1
wp-content/themes/simple-theme/assets/index-DLNOOjXC.css
Normal file
1
wp-content/themes/simple-theme/assets/index-DLNOOjXC.css
Normal file
@ -0,0 +1 @@
|
|||||||
|
body{min-height:100vh;display:flex;flex-direction:column;align-items:center;position:relative;overflow-x:hidden;overflow-y:auto;font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen,Ubuntu,Cantarell,Fira Sans,Droid Sans,Helvetica Neue,sans-serif;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale}p,span,h1,h2,h3,h4,h5,h6,a{margin:0;padding:0}code{font-family:source-code-pro,Menlo,Monaco,Consolas,Courier New,monospace}.container{width:1440px;margin:0 auto;overflow-x:hidden}:before,:after{margin:0;padding:0;box-sizing:border-box}@media (max-width: 1441px){.container{width:100%}}.test{width:100%;display:flex;flex-direction:column;gap:30px;box-sizing:border-box}.article{width:1200px;padding:20px;display:flex;flex-direction:column;gap:15px;box-sizing:border-box;margin:0 auto}.article-top{display:flex;flex-direction:column;gap:12px}.article-top_image{width:100%;height:600px;position:relative}.article-top_image img{object-fit:cover;position:absolute;width:100%;height:100%}.article-body{width:100%}.article-body img{width:100%;height:auto}.article-body p{font-size:16px;line-height:26px}.article-body h1{font-size:36px;line-height:45px}.article-body span{font-size:12px;line-height:20px;font-weight:500;color:#767676}.article p{font-size:16px;line-height:26px}.article h1{font-size:36px;line-height:45px}.article span{font-size:12px;line-height:20px;font-weight:500;color:#767676}@media (max-width: 1500px){.article{width:60%}.article-top_image{height:400px}.article p{font-size:14px;line-height:24px}.article h1{font-size:34px;line-height:43px}}@media (max-width: 1025px){.article{width:70%}.article-top_image{height:300px}.article p{line-height:22px}}@media (max-width: 769px){.article{width:80%;padding:10px;gap:5px}.article-top_image{height:250px}.article h1{font-size:30px;line-height:40px}}@media (max-width: 551px){.article{width:93%;padding:0}.article h1{font-size:28px;line-height:35px}}@media (max-width: 426px){.article{width:97%}.article-top{gap:10px}.article-top_image{height:200px}.article span{font-size:12px;line-height:16px}}
|
45
wp-content/themes/simple-theme/assets/index-jMypZ83L.js
Normal file
45
wp-content/themes/simple-theme/assets/index-jMypZ83L.js
Normal file
File diff suppressed because one or more lines are too long
@ -1,5 +1,27 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
require get_theme_file_path('/api-posts/api-posts.php');
|
||||||
|
|
||||||
|
// Add rewrite rule
|
||||||
|
add_action('init', function () {
|
||||||
|
add_rewrite_rule('api-template/?$', 'index.php?static_template=api-template', 'top');
|
||||||
|
flush_rewrite_rules(); // Only needed for local development
|
||||||
|
});
|
||||||
|
|
||||||
|
// Whitelist the custom query var
|
||||||
|
add_filter('query_vars', function($queryVars) {
|
||||||
|
$queryVars[] = 'static_template';
|
||||||
|
return $queryVars;
|
||||||
|
});
|
||||||
|
|
||||||
|
// Conditionally render the custom template
|
||||||
|
add_action('template_include', function($template) {
|
||||||
|
if (get_query_var('static_template') == 'api-template') {
|
||||||
|
return get_template_directory(). '/api-template.php';
|
||||||
|
}
|
||||||
|
return $template;
|
||||||
|
});
|
||||||
|
|
||||||
// ? get variables (globally)
|
// ? get variables (globally)
|
||||||
function gV($gv)
|
function gV($gv)
|
||||||
{
|
{
|
||||||
|
@ -26,7 +26,9 @@ $container_class = isset($args['container_class']) ? $args['container_class'] :
|
|||||||
// window.location.replace("http://www.w3schools.com");
|
// window.location.replace("http://www.w3schools.com");
|
||||||
</script>
|
</script>
|
||||||
<title><?php echo $title; ?><?php if ($PAGEN > 1) echo ". Страница " . $PAGEN; ?></title>
|
<title><?php echo $title; ?><?php if ($PAGEN > 1) echo ". Страница " . $PAGEN; ?></title>
|
||||||
|
<link rel="stylesheet" crossorigin href="../../../wp-includes/js/endlessposts/index-8tue7roC.css.css">
|
||||||
<script>console.log('title', document.title);</script>
|
<script>console.log('title', document.title);</script>
|
||||||
|
<script type="module" crossorigin src="../../../wp-includes/js/endlessposts/index-DbN6FUVS.js"></script>
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<link rel="canonical" href="#" class="yoast-seo-meta-tag">
|
<link rel="canonical" href="#" class="yoast-seo-meta-tag">
|
||||||
|
@ -40,11 +40,9 @@ switch ($tax_id) {
|
|||||||
|
|
||||||
?>
|
?>
|
||||||
<?php $tags = get_the_tags(); $tag = $tags[0]->slug; $same_id = get_the_ID(); ?><span id="catcat" data-tag ="<?php echo $tag; ?>" data-sameid="<?php echo $same_id; ?>" ></span>
|
<?php $tags = get_the_tags(); $tag = $tags[0]->slug; $same_id = get_the_ID(); ?><span id="catcat" data-tag ="<?php echo $tag; ?>" data-sameid="<?php echo $same_id; ?>" ></span>
|
||||||
<main <?php post_class('site-main'); ?> role="main">
|
<main <?php post_class('site-main'); ?> role="main">
|
||||||
<script>
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
<div class="single-article-post" id="article.id">
|
<div class="single-article-post" id="article.id">
|
||||||
<div class="projects-list-wrap"> <!-- begin of wrapper -->
|
<div class="projects-list-wrap"> <!-- begin of wrapper -->
|
||||||
<span class="data-wrapper" data-title="<?php the_title(); ?>" data-url="<?php the_permalink(); ?>" data-description="<?php echo get_post_meta(get_the_ID(), '_yoast_wpseo_metadesc', true); ; ?>">
|
<span class="data-wrapper" data-title="<?php the_title(); ?>" data-url="<?php the_permalink(); ?>" data-description="<?php echo get_post_meta(get_the_ID(), '_yoast_wpseo_metadesc', true); ; ?>">
|
||||||
@ -59,7 +57,6 @@ switch ($tax_id) {
|
|||||||
<span class="breadcrump-separator">—</span>
|
<span class="breadcrump-separator">—</span>
|
||||||
<span class="breadcrumb_last" aria-current="page"><?php the_title(); ?></span></span>
|
<span class="breadcrumb_last" aria-current="page"><?php the_title(); ?></span></span>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<div class="ppd-container article-container">
|
<div class="ppd-container article-container">
|
||||||
<div class="article-header">
|
<div class="article-header">
|
||||||
<h1 class="article-title"><?php the_title(); ?></h1>
|
<h1 class="article-title"><?php the_title(); ?></h1>
|
||||||
@ -155,7 +152,7 @@ switch ($tax_id) {
|
|||||||
// $content = apply_filters( 'the_content', get_the_content() );
|
// $content = apply_filters( 'the_content', get_the_content() );
|
||||||
// echo $content;
|
// echo $content;
|
||||||
?>
|
?>
|
||||||
|
<div id="root" style="width: 100%;"></div>
|
||||||
<div class="article-details__social article-details__social-bottom">
|
<div class="article-details__social article-details__social-bottom">
|
||||||
<button class="show-commmentsform">Оставить комментарий</button>
|
<button class="show-commmentsform">Оставить комментарий</button>
|
||||||
<?php
|
<?php
|
||||||
|
Reference in New Issue
Block a user