2016-05-20 7 views
1

私はpostidからurlを通って注目画像を取得しようとしています。URLのポストIDからWordPressのポストフィーチャーされたイメージを取得する方法

http://www.example.com/schedule-appointment/?postid=589

私は、URLからpostidを得ることができましたが、すべてはそこから丘ダウンしました。私は単純なものを逃しているに違いない。私はプログラマーではありません...いくつかの助けが大好きです。 WP_Queryのための必要はありません

add_shortcode('CF7_ADD_POST_ID', 'cf7_add_post_id'); 

function cf7_add_post_id(){ 


     $Path=$_SERVER['REQUEST_URI'];     
     $control = array(); 
     $control = explode('?', $Path);  
     $get = $control[1]; 
     $get = explode('=', $get); 
     $get2 = $get[1]; 
     $args = array(
      'post_type' => 'page', 
      'post__in' => $get2, 
     ); 

     // Fire up the Query 
     $the_query = new WP_Query($args); 


     while ($the_query->have_posts()): $the_query->the_post(); 
     $feat_image = wp_get_attachment_url(get_post_thumbnail_id($post->$get2)); 
     echo '$feat_image'; 


}; 

答えて

1

が魅力のように働いたこの

<?php 
add_shortcode('CF7_ADD_POST_ID', 'cf7_add_post_id'); 

function cf7_add_post_id(){ 
    $ID = isset($_GET["postid"]) ? $_GET["postid"] : false; 
    if($ID){ 
     $thumb = wp_get_attachment_image_src(get_post_thumbnail_id($ID), 'full'); 
     $url = $thumb['0']; 
     echo "<img src ='".$url."' alt = 'Image'>"; 
    } 
} 
?> 
+0

をお試しください!投稿のタイトルをどのように取得するのですか? – Dilan

+0

@Dilan 'echo get_the_title($ ID);' :) –

0

、あなたは1つのIDを持っていて、簡単に、これは次のコードを使用して成し遂げることができ、

add_shortcode('CF7_ADD_POST_ID', 'cf7_add_post_id'); 

function cf7_add_post_id(){ 


    $postid = $_GET['postid']; 


    $feat_image = wp_get_attachment_url(get_post_thumbnail_id($postid)); 
    echo '$feat_image'; 

};

関連する問題