Wordpressでページにランダムな背景を与えるカスタムページタイプを作成しようとしています。(つまり、ホームページ上の素敵な大きな画像)。私はそれを動かしています!しかし、大きな画像を返していますが、すばやく追加して画像全体のサイズのURLを表示する方法はありますか?
よろしくお願いします!
(私は完全なコードを貼り付けたので、それが役立つ場合は誰でも自分のサイトでそれを使用できますか?)
<?php
/**
* Template Name: Fullscreen Random
*/
get_header();
?>
<?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
<style media="screen" type="text/css">
body {
background: url(<?php
$args = array( 'post_type' => 'attachment', 'numberposts' => 1, 'orderby' => 'rand', 'post_status' => null, 'post_parent' => 5 );
$attachments = get_posts( $args );
if ($attachments) {
foreach ( $attachments as $attachment ) {
echo $attachment->guid;
}
}
?>) no-repeat center center fixed;
webkit-background-size: cover;
moz-background-size: cover;
o-background-size: cover;
background-size: cover;
}
#menu {background:rgba(0, 0, 0, 0.2)!important;}
* {color:white!important;}
</style>
<?php endwhile; ?>
<? get_footer(); ?>