php - Dynamic home page image in wordpress -
i'm building website friend of mine , i'm stuck on one. want adaptable background image on homepage can customize on customize page in wordpress admin page. code looks this:
get_header(); ?> <div id="slides"> <div class="slides-container"> <img src="<?php bloginfo('template_directory'); ?>/images/home.jpg" alt="cinelli"> </div> <nav class="slides-navigation"> <a href="#" class="next"> <img src="<?php bloginfo('template_directory'); ?>/images/right.png" alt="left"></a> <a href="#" class="prev"> <img src="<?php bloginfo('template_directory'); ?>/images/left.png"alt="right"></a> </nav> </div> <div class="welcometext"> <h1><?php echo get_bloginfo( 'name' );?></h1> <?php echo bloginfo('description');?> </div> <?php get_footer(); ?>
now image tag needs adaptable. possible?
it may easier pull image wordpress page's featured image use customize page.
to enable featured images, add line theme's functions.php file: add_theme_support( 'post-thumbnails' );
now upload image featured image area of wordpress page. can page, need take note of page's id. page id, go edit screen page , @ url in browser. end post.php?post=34&action=edit
number after post=
page's id, in example it's 34.
now modify image code:
<?php $feat_image = wp_get_attachment_url( get_post_thumbnail_id(34, 'full') ); // replace '34' page's id ?> <img src="<?php echo $feat_image; ?>" alt="cinelli">
replace 34
page's id. if using code within loop, can replace 34
$post->id
.
the 'full'
in first line tells size of image use. 'full' use original image upload, or can use 'large', 'medium', 'thumbnail', or custom image size you've set up.
Comments
Post a Comment