1
WordPressで最新のブログ投稿を呼び出すショートコードを作成しました。 タイトルと内容を<h2>
と<p>
に改めましたが、これは適用されていません。 htmlは生成されていますが、必要なタグはありません。私は間違って何を書いていますかWordPressのショートコード問題
これは私のコードです:
<?php
//blog posts shortcode
function my_recent_post()
{
global $post;
$html = "";
$my_query = new WP_Query(array(
'post_type' => 'post',
'cat' => '4',
'posts_per_page' => 1
));
if($my_query->have_posts()) : while($my_query->have_posts()) : $my_query->the_post();
$html .= "<span>" . the_post_thumbnail('medium', array('class' => 'img-responsive')) . "</span>";
$html .= "<h2>" . the_title() . "</h2>";
$html .= "<p>" . the_excerpt() . "</p>";
endwhile; endif;
return $html;
}
add_shortcode('blog', 'my_recent_post');
?>
を試してみてください。私のコードを使ってみることはできますか? –