• Resolved DeveWeb

    (@deveweb)


    hi guys, i need help, i trie ti Added this code in my theme in fuctions.php

    function sponsor_banner($post) {
      static $already_run = false;
      if (is_category('uncategorized')) {
        if ( !$already_run) {
    ?>
    <img src="/path/to/banner.jpg">
    <?php
          $already_run = true;
        }
      }
    }
    add_action('the_post', 'sponsor_banner');

    but when I try to add a new o edit some category, I do not see any changes or add something extra to the sponsor code, I use the Arras theme, wodpress 3.2.1 spanish version, Arras will be the theme difficult to add this code?.. Please guys i need help to solvent this.! SOS

Viewing 15 replies - 1 through 15 (of 20 total)
  • I’ve just tried this on a test site with twentyten and it works fine:

    Before the first post in category ‘uncategorised’, it outputs an image. That’s it. It doesn’t do anything else.

    Are you perhaps expecting something else?

    Thread Starter DeveWeb

    (@deveweb)

    thanks a lot Mike for you answer but i dont see this image, i trie to add this code in twintyten theme for test the code but i dont see any image, in what line number in specific put the code? can you explain me step by step Please..!! ??

    Just to clarify further, this code will display the banner image before the first post on the category archive page for the specififed category.

    So you won’t see it on your home page, or on a single post page. Only on the archive page for the specific category.

    With that knowledge, the code just needs to be copied into functions.php. At the end will do, just before the closing ?> tag (if there is one – it’s ok if there isn’t).

    You need to change the name of the category ‘your-category-here’ and the path to the banner image ‘/path/to/your-banner-here.jpg’ and presumably make it into a link to the sponsor or wherever.

    function sponsor_banner($post) {
      static $already_run = false;
      if (is_category('your-category-here')) {
        if ( !$already_run) {
    ?>
    <img src="/path/to/your-banner-here.jpg">
    <?php
          $already_run = true;
        }
      }
    }
    add_action('the_post', 'sponsor_banner');
    Thread Starter DeveWeb

    (@deveweb)

    ready i solvent the code

    function sponsor_banner($post) {
      static $already_run = false;
      if (is_category('sociedad')) {
        if ( !$already_run) {
    ?>
    <a href="https://www.domainsponsor.com/" target="_blank"><img src="/wordpress/wp-content/publicidad/usa.jpg" /></a>
    <?php
          $already_run = true;
        }
      }
    }
    add_action('the_post', 'sponsor_banner');

    thanksssss a lot Mike you are the Best.!! ??

    but when I try to duplicate the code to add a another sponsor to another category gives me an error. how to duplicate the code and I do not throw error?

    // Sponsor 1
    function sponsor_banner($post) {
      static $already_run = false;
      if (is_category('ciencia')) {
        if ( !$already_run) {
    ?>
    <a href="https://www.domain.com/" target="_blank"><img src="/wp-content/publicidad/usa.jpg" /></a>
    <?php
          $already_run = true;
        }
      }
    }
    add_action('the_post', 'sponsor_banner');
    
    // Sponsor 2
    function sponsor_banner($post) {
      static $already_run = false;
      if (is_category('comunidad')) {
        if ( !$already_run) {
    ?>
    <a href="https://www.domain.com/" target="_blank"><img src="/wp-content/publicidad/usa.jpg" /></a>
    <?php
          $already_run = true;
        }
      }
    }
    add_action('the_post', 'sponsor_banner');

    Try this:

    function sponsor_banner($post) {
      static $already_run = false;
      if ( !$already_run) {
        if (is_category('sociedad')) {
    ?>
    <a href="https://www.domainsponsor.com/" target="_blank"><img src="/wordpress/wp-content/publicidad/usa.jpg" /></a>
    <?php
          $already_run = true;
        } else if (is_category('category2')) {
    ?>
    <a href="https://www.sponsor2.com/" target="_blank"><img src="/wordpress/wp-content/publicidad/image2.jpg" /></a>
    <?php
          $already_run = true;
        }
      }
    }
    add_action('the_post', 'sponsor_banner');
    Thread Starter DeveWeb

    (@deveweb)

    Excellent Mike yeap work perfecttttt.!!! Really Dude thanks a lot you safe my life, you are the best.!!

    Thread Starter DeveWeb

    (@deveweb)

    Mike another question. to use that code but appear after every post, at the bottom, which would have to change the code? thanks my Friend.!!

    something like this:

    function sponsor_banner_after($post) {
      static $already_run = false;
      if ( !$already_run) {
        if (is_category('category-1')) {
    ?>
    <a href="https://www.sponsor1.com/" target="_blank"><img src="/path/to/image1.jpg" /></a>
    <?php
          $already_run = true;
        } else if (is_category('category-2')) {
    ?>
    <a href="https://www.sponsor2.com/" target="_blank"><img src="/path/to/image2.jpg" /></a>
    <?php
          $already_run = true;
        }
      }
    }
    add_action('loop_end', 'sponsor_banner_after');
    Thread Starter DeveWeb

    (@deveweb)

    wooowww Mike you are the best, work perfect… to complete the website of news, I just need to place a sponsor in the header, it’s getting harder .. I might suggest?
    thanks a lot for you big help Bro.!!

    you have any email to send you later the link the my website for you get me your opinion.?

    There is contact form on my site here https://zed1.com/contact-zed1

    Thread Starter DeveWeb

    (@deveweb)

    okis thanks a lot Mike.. i will contact you about your site.!!

    Thread Starter DeveWeb

    (@deveweb)

    ilanm47

    (@ilanm47)

    Hi,

    Saw your thread and I wonder what is wrong with my piece of code. I’m trying to give different header to each category by pasting this in the header.php.

    [please mark your code, following the forum guidelines for posting code]

    <?php if (is_category( 'concepts' )) \{ ?>
    <img src="https://www.portfolio.clickmarketing.co.il/wp-content/uploads/header_concSmall.jpg" width="940" alt="<?php bloginfo('name'); ?> header image" />
    <?php \} elseif (is_category( 'tools' )) \{ ?>
    <img src="https://www.portfolio.clickmarketing.co.il/wp-content/uploads/header_toolsSmall.jpg" width="940" alt="<?php bloginfo('name'); ?> header image" />
    <?php \} ?>

    Please assist.

    Thanks
    Ilan

    Mike Little

    (@mikelittle)

    If you really have the backslash before the curly brace “\{“, then the code won’t work, you should just have curly brace “{“.

    If you correct that, then code should work to output an image on the category archive page for category concepts and category tools.

    ilanm47

    (@ilanm47)

    Thanks but I don’t see any change, Does it appears only on archived posts? I would like it to appear on any post.

    Is it enough just to delete backslash before the question mark or does it appears in other places? <?php if (is_category( ‘concepts’ )) { ?>

Viewing 15 replies - 1 through 15 (of 20 total)
  • The topic ‘Need to add sponsor banner before posts on Category archive page SOS’ is closed to new replies.