the_title
をそのまま使うとechoされます。(先に出力されます。)
the_title(null,null,FALSE)
にするかget_the_title
を使ってください。
Hinaloe様
返答ありがとうございます。
教えて頂いた方法で試したところ、
<?php
if(get_post_meta($post->ID,'mainphoto',true)){
echo '<p><img src="'.get_post_meta($post->ID,'mainphoto',true).'" alt="'.the_title(null,null,FALSE).'"></p>';
}
if(get_post_meta($post->ID,'lower-desc',true)){
echo '<p class="img-desc-bottom">'.get_post_meta($post->ID,'lower-desc',true).'</p> ';
}
?>
で表示する事が出来ました。
ありがとうございます!
nobita様
返答をありがとうございます。
Hinaloe様に教えて頂いた方法で表示出来たのですが、
nobita様が仰る様にhtml要素が追加される可能性もありますので、
the_title_attributeを使用したいと思うのですが、
<?php
if(get_post_meta($post->ID,'mainphoto',true)){
echo '<p><img src="'.get_post_meta($post->ID,'mainphoto',true).'" alt="'.the_title_attribute().'"></p>';
}
if(get_post_meta($post->ID,'lower-desc',true)){
echo '<p class="img-desc-bottom">'.get_post_meta($post->ID,'lower-desc',true).'</p> ';
}
?>
としてみたりしましたが、表示できませんでした。
Hinaloe様の方法と組み合わせて
<?php
if(get_post_meta($post->ID,'mainphoto',true)){
echo '<p><img src="'.get_post_meta($post->ID,'mainphoto',true).'" alt="'.the_title_attribute(null,null,FALSE).'"></p>';
}
if(get_post_meta($post->ID,'lower-desc',true)){
echo '<p class="img-desc-bottom">'.get_post_meta($post->ID,'lower-desc',true).'</p> ';
}
?>
としても、画像の上部に文字が表示されてしまいました。
大変お手数ですが、the_title_attributeを使用して
altに記載できる方法を教えて頂けますと大変助かります。
なにとぞ、宜しくお願い致します。
引数の指定方法が異なります
Codexを読むことが大事です。:)
$args = array(
'before'=>'',
'after'=>'',
'echo' => false,
);
echo 'before '. the_title_attribute( $args ) . ' after';
または、
echo the_title_attribute( 'echo=false' );
nobita様
返答ありがとうございます。
出来ました!
(書き方がおかしい場合は、ご指摘をお願いできますでしょうか?)
<?php
if(get_post_meta($post->ID,'mainphoto',true)){
echo '<p><img src="'.get_post_meta($post->ID,'mainphoto',true).'" alt="';
echo the_title_attribute( 'echo=false' ).'"></p>';
}
if(get_post_meta($post->ID,'lower-desc',true)){
echo '<p class="img-desc-bottom">'.get_post_meta($post->ID,'lower-desc',true).'</p> ';
}
?>
自分の中で、まだしっかり理解出来ておりませんので
勉強していこうと思います。
本当に、ありがとうございます。