• Hi guys!!

    I would like to add a image just on a single page. My web’s structure is HOME, ABOUT, BLOG, PROJECTS and BIO. I would like to add a image as blog’s tittle on Blog page and it should appear just on this page.

    how can I do that??

    thanks!

Viewing 9 replies - 1 through 9 (of 9 total)
  • Thread Starter Pedro

    (@igmosi)

    I guess is using body_class()… but How can i do it??

    Thread Starter Pedro

    (@igmosi)

    Thanks!!

    That means I dont nedd body_class function?? I dont know pretty much about php.. What should be the code?? Should I put on header.php??

    probably yes, the code could be in header.php:

    if you want to use the image as background image, your code could look like this (this is an adapted copy from the default theme):

    <style type="text/css" media="screen">
    <?php
    // Checks to see if BLOG page
    if ( is_page('blog') ) {
    ?>
    #divwiththeimage { background: url("<?php bloginfo('stylesheet_directory'); ?>/images/blogheadimage.jpg") center top no-repeat; }
    <?php } ?>
    </style>

    assuming your image is called blogheadimage.jpg and is saved in the /images folder of your theme.

    if you want to put them image into the body of the page, the code could look like this:
    <img src="<?php bloginfo('template_url'); ?>/images/blogheadimage.jpg" alt="" />
    same assumption for image name and location.

    that is all in general ;if you run into problems, please post a link to your site ??

    Thread Starter Pedro

    (@igmosi)

    Thanks!!

    I want to use the image ino the body of the page, over the frist post, below the header. I would like to use it as blog’s title.

    So, I guess the code
    <img src="<?php bloginfo('template_url'); ?>/images/blogheadimage.jpg" alt="" />
    should be instead of

    background: url("<?php bloginfo('stylesheet_directory'); ?>/images/blogheadimage.jpg") center top no-repeat; }
    <?php }

    https://www.igmosi.com

    thanks for the link – makes life easier.

    backgground would be ok – just adapt the code to the theme:

    <style type="text/css" media="screen">
    #content .narrowcolumn { background: url("https://www.igmosi.com/wp-content/themes/default/images/camera.jpg") center top no-repeat; padding-top: 50px; /*padding should be height of image */ }
    </style>

    btw: your image link gives me a 404 not found.

    if you want that your image is printed with the content, should someone print the page, you need to enter it into the code of page.php (or blog.php if you have a custom page template):

    get_header(); ?>
    
    	<div id="content" class="narrowcolumn">
    
    <img src="<?php bloginfo('template_url'); ?>/images/camera.jpg" alt="" />
    
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    		<div class="post" id="post-<?php the_ID(); ?>">

    the choice is yours ??

    Thread Starter Pedro

    (@igmosi)

    Thanks alchymyth!!

    But if I want just on the blog page should be:

    <?php if ( is_page('blog logged-in') ) {
    ?>
    <img src="https://www.igmosi.com/wp-content/uploads/2010/01/camera2.jpg" alt="camera2" title="camera2" width="407" height="407" class="alignleft size-full wp-image-1994" />
    <?php } ?>

    ??

    Thread Starter Pedro

    (@igmosi)

    I am using that code and it works but not the conditional.

    If I put is_page() it appears on all pages but not in blog page. In others widgets, I am using is_home() to appears on the blog page… but if I use is_home() in that code it doesnt works!.

    What conditional should be??

    Thanks a lot for helping!!

    If I put is_page() it appears on all pages but not in blog page.

    ok, if this is always true, then you can reverse the condition: ( “if it is not a page” )
    if ( !is_page() )
    (how to use it: https://codex.www.ads-software.com/Function_Reference/is_page)

    you also seem to check if the user is logged in:
    (https://codex.www.ads-software.com/Function_Reference/is_user_logged_in)

    in which case, the condition could be:

    if ( !is_page() && is_user_logged_in() )

    you can try condition by putting some code into your header.php:
    (try this with all the conditions you want to check, until you get familiar with how it works ??

    <?php if( is_page() ) { echo 'this is a page'; };
    if( is_page('blog') ) { echo 'this is BLOG'; };
    if( is_home() ) { echo 'this is home'; };
    if ( is_user_logged_in() ) { echo 'user is logged in'; } ;
    ?>

    ——–

    but if I use is_home() in that code it doesnt works!.

    if ( is_page('blog logged-in') )
    i am not sure, but it could be the invalid combination in your conitional that does make it not work.
    try again, just using is_home()

    good luck ??

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Add a image on single page’ is closed to new replies.