WordPress.org

Ready to get started?Download WordPress

Forums

Placement of banners (19 posts)

  1. Daniel Nielsen
    Member
    Posted 2 years ago #

    Hi,
    On my webpage MMAmania.dk i want to place banner at the top like on this test page i have Test Page but on the "test page" it is placed in the header.php and is therefore, one each page. And this I would like to avoid, as there are some pages where it will not be optimal.

    I hope someone can help me with this

  2. Daniel Nielsen
    Member
    Posted 2 years ago #

    If you have problems accessing the site, I've taken a screenshot which you can find on this link here

  3. suprim
    Member
    Posted 2 years ago #

    I also want this to know

  4. bknutson
    Member
    Posted 2 years ago #

    It depends on what page(s) you want the banner to display on. You can edit the header.php with an if statement. This if statement will insert the banner on the front page only:

    <?php if (is_front_page()) { ?>
    // code to insert banner
    <?php } ?>

    You could also use if (is_single( '' )) or if (is_page( '' )) or others to insert on only certain posts/pages (obviously inserting the proper post number or page number between the quotes).

  5. Daniel Nielsen
    Member
    Posted 2 years ago #

    Thanks, that helps! But where do i find the page numbers?

  6. bknutson
    Member
    Posted 2 years ago #

    If you edit a post in the admin, look at the URL. For example:

    .../wp-admin/post.php?post=8&action=edit

    The above URL shows "post=8", so your if statement would be

    <?php if (is_page( '8' )) { ?>
    // code to insert banner
    <?php } ?>
  7. Daniel Nielsen
    Member
    Posted 2 years ago #

    Can I combine this with the front page? I apologize for the newbie questions, but can it be made such that it is on every post or should I go and fix the code for each time I make a new post?

  8. bknutson
    Member
    Posted 2 years ago #

    Do you only want the banner to show on the front page, or every page other than the front page, or some combination of pages and the front page?

  9. Daniel Nielsen
    Member
    Posted 2 years ago #

    I want to show the banner on the front page and on each post, maybe later also on other pages.

  10. bknutson
    Member
    Posted 2 years ago #

    It sounds like you want it to show up on all pages except a few, am I correct?

    You could try something like this:

    <?php if ( !is_page( '8' ) || !is_page( '10' ) || !is_page( '12' ) ) { ?>
    // code to insert banner
    <?php } ?>

    Should put the header on all pages that are not page_id 8, 10 or 12.

  11. Daniel Nielsen
    Member
    Posted 2 years ago #

    Thanks for you time, but now I have tried this, but it still shows in our team page. (it is page 28)

    <?php if ( !is_page( '9' ) || !is_page( '23' ) || !is_page( '28' ) || !is_page( '901' ) || !is_page( '700' ) || !is_page( '126' ) || !is_page( '2327' ) || !is_page( '148' ) || !is_page( '1544' ) ) { ?>
    // My code
    <?php } ?>
  12. bknutson
    Member
    Posted 2 years ago #

    Try !is_single( '28')

  13. Daniel Nielsen
    Member
    Posted 2 years ago #

    it's the same result

  14. bknutson
    Member
    Posted 2 years ago #

    Are these "pages" or posts? If they are posts, do they all have a custom post type?

    Any other information you can provide me would make it easier for me to troubleshoot...sorry I haven't solved it yet!

  15. Daniel Nielsen
    Member
    Posted 2 years ago #

    It's pages, you can see the team page here

    I changed the code back to

    <?php if (is_front_page()) { ?>
    // code to insert banner
    <?php } ?>

    The pages that I did not want the banner displayed on is 9, 23, 28, 901, 700, 126, 2327, 148, 1544

    If there is other information you need? There is no reason to apologize, I'm just glad you bother to help me.

  16. Daniel Nielsen
    Member
    Posted 2 years ago #

    I've tried both !is_page(' 28 ') and !is_single(' 28 ') and banner will be shown no matter what

  17. bknutson
    Member
    Posted 2 years ago #

    Well...you could use jQuery to hide the banner...but this of course isn't the best solution (users with js turned off will see the banner). It should work though

    <?php if ( is_page( '9' ) || is_page( '23' ) || is_page( '28' ) || is_page( '901' ) || is_page( '700' ) || is_page( '126' ) || is_page( '2327' ) || is_page( '148' ) || is_page( '1544' ) ) { ?>
    <script type="text/javascript">
    	$(document).ready(function() {
    		$('#banner').hide();
    	});
    </script>
    <?php } ?>
  18. Daniel Nielsen
    Member
    Posted 2 years ago #

    I found out how to do it

    <?php if ( !is_page( array( 42, 54, 6 ) )  ) { ?>
    //My code
    <?php } ?>

    Thanks for your help

  19. bknutson
    Member
    Posted 2 years ago #

    Ah! Don't know why I didn't think of that. Nice work!

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.