Wordpressの投稿に属性と内容のショートコードを使用しています。これらのショートコードは必要なので使用する必要があります。私はインデックスと単一のページをajaxingしています。ポストのコンテンツを出力してクライアント側に戻ったときにショートコードが機能しないため、単一のポストをajaxingする際に問題が発生しています。ループ外でajaxショートコードを作成する方法
方法を強制するための提案はありますか?デフォルト値を持つ
function ajaxsingle() {
global $wpdb;
$postID = $_POST[ 'postID' ];
$post = get_post($postID);
$postType = get_post_type($postID);
$slug = $post->post_name;
$title = get_the_title($postID);
$thumbnailUrl = wp_get_attachment_url(get_post_thumbnail_id($postID));
$excerpt = apply_filters('the_excerpt', get_post_field('post_excerpt', $postID));
$sidebar = the_widget('post-inner-sidebar');
$post_content = $post->post_content;
$imgBackground = "../wp-content/themes/webdev/img/";
$imgBackground .= get_post_field('post_name', get_post($postID));
$imgBackground .= "_preview.jpg";
if ($postType == "articles" || $postType == "tutorials") {
$html = '<div id="blogWrap" style="background: linear-gradient(to right, rgba(255,255,255,0) 29%,rgba(255,255,255,0.9) 29%,rgba(255,255,255,0.9) 100%), url('.$imgBackground.'); opacity: 0;"><div id="articleHeader"><div id="headerLogo" style="background: url('.$thumbnailUrl.'), linear-gradient(to right, rgba(248,194,121,1) 0%,rgba(248,194,121,1) 100%)"></div><div id="excerptIntro"><div id="excerptInner"><h1>'.$title.'</h1><div class="leftQuotemark tutorials-leftQuotemark"></div><p>'.$excerpt.'</p><div class="rightQuotemark tutorials-rightQuotemark"></div></div></div></div><div id="blogInnerWrap"><div id="adContentWrap">'.$sidebar.'</div><div id="tutorialContent">'.$post_content.'</div></div></div></div>';
} else if ($postType == "case-studies"){
$html = '<div id="blogWrap" style="background: linear-gradient(to right, rgba(255,255,255,0) 29%,rgba(255,255,255,0.9) 29%,rgba(255,255,255,0.9) 100%), url('.$imgBackground.'); opacity: 0;"><div id="blogInnerWrap">'.$post_content.'</div></div></div>';
} else if ($postType == "software") {
$html = '<div id="blogWrap" style="background: linear-gradient(to right, rgba(255,255,255,0) 29%,rgba(255,255,255,0.9) 29%,rgba(255,255,255,0.9) 100%), url('.$imgBackground.'); opacity: 0;"><div id="softwareHeader"><div id="headerLogo" style="background-image: url('.$thumbnailUrl.'); ?>")></div><div id="excerptIntro"><h1>'.$title.'</h1><div class="leftQuotemark software-leftQuotemark"></div><p>'.$excerpt.'</p><div class="rightQuotemark software-rightQuotemark"></div></div></div><div id="blogInnerWrap">'.$post_content.'</div></div></div>';
}
echo $html;
wp_die();
}
postTypeは一致していますが、フロントエンドにHTMLが送信されます。問題は、wordpressはajax環境でショートコードを許可しないことです。ページ上のショートコード全体をテキストとして表示するだけです。しかし、これらのショートコードはシステムにとって非常に重要なので、これを実装する最良の方法を見つけなければなりません。 –