WordPress.org

Ready to get started?Download WordPress

Forums

How to add a colored box to the top of each page (that is not the frontpage) (3 posts)

  1. bysukro
    Member
    Posted 10 months ago #

    Hi,
    I am working on a site where I need to add a <div> with some content in it at the top of each static page.

    The <div> should be one color on some pages and another on other pages.
    The CSS works fine, but my code doesn't...it just adds both the divs on all pages except the frontpage.

    I have this code so far:

    <?php if( !is_front_page() ) { //if we are not on the front page ?>
    
    	<div class="row">
               	if(is_page('ydelser-2'))
    		{
    			<div class="hidden-phone top_box">
    				We will add content here
    			</div>
    		} ?>
    
    		elseif(is_page('blog-2'))
    		{
    			<div class="hidden-phone top_box_blog">
    				We will add more content here
    		     	</div>
    		} ?>
    	</div>
    
    <?php } ?>

    Can anyone solve this riddle for me...?

  2. alchymyth
    Forum Moderator
    Posted 10 months ago #

    enable DEBUG while customizing your site: http://codex.wordpress.org/Debugging_in_WordPress

    you need to re-open php tags after the html code;

    example:

    <?php if( !is_front_page() ) { //if we are not on the front page ?>
    
    	<div class="row">
               	<?php if(is_page('ydelser-2'))
    		{ ?>
    			<div class="hidden-phone top_box">
    				We will add content here
    			</div>
    		<?php } 
    
    		elseif(is_page('blog-2'))
    		{ ?>
    			<div class="hidden-phone top_box_blog">
    				We will add more content here
    		     	</div>
    		<?php } ?>
    	</div>
    
    <?php } ?>
  3. bysukro
    Member
    Posted 10 months ago #

    Hi alhymyth,
    Thank you ever so much! I will make sure to enable debugging.. It worked perfectly!

Reply

You must log in to post.

About this Topic