2016-07-22 14 views
0

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(); 
} 

答えて

0

初期化$htmlしたり、事前に定義された値の一部と$postType一致することを確認してください。"articles""tutorials""case-studies"、または"software"

+0

postTypeは一致していますが、フロントエンドにHTMLが送信されます。問題は、wordpressはajax環境でショートコードを許可しないことです。ページ上のショートコード全体をテキストとして表示するだけです。しかし、これらのショートコードはシステムにとって非常に重要なので、これを実装する最良の方法を見つけなければなりません。 –

1

あなたのコードでは、正規表現でショートコードを検索し、各ショートコードに対してdo_shortcode関数を呼び出して、ショートコード処理の結果を取得して$ html変数に挿入します。

+0

はい、これは私の計画でした。ショートコードテキストを切り詰めて実装するための正規表現文字列検索。誰かがもっと効率的なやり方をしたいと思っています。 –

+0

wp_remote_retrieve_body()でhtmlのポストを取得しようとしていて、次にconten partを抽出してみてください。 – stweb

関連する問題