WordPress.org

Forums

Adding different banner images to categories (7 posts)

  1. n.allen
    Member
    Posted 1 year ago #

    I've taken over our company ecommerce site. I'd like to add a different banner image for each category, not page. That I can do easily with HTML. I have HTML/CSS experience, but no PHP experience. I've read several forum discussions and tutorials, and tried several ideas (including a plugin), but nothing works. Right now we only have seven categories. What's the easiest way to do it and where do I place the code? Thanks in advance for your help!

  2. n.allen
    Member
    Posted 1 year ago #

  3. Evan Herman
    Member
    Posted 1 year ago #

    Read up on is_category function provided by WordPress. You'll need to adjust the correct .php WordPress template file.

    https://codex.wordpress.org/Function_Reference/is_category

  4. n.allen
    Member
    Posted 1 year ago #

    Thanks for the response, but this makes no sense to me.

  5. Evan Herman
    Member
    Posted 1 year ago #

    It's a very intricate set up process and too much to go into detail here without you having any previous knowledge of PHP.

    You're best bet is to find a plugin suitable to achieve this.

  6. n.allen
    Member
    Posted 1 year ago #

    Great! So, you've told me that it's difficult since I have no PHP knowledge and told me to find a suitable plugin without suggesting one. Yes, I'm pretty frustrated trying to figure something out that seems to be easy, but getting little help. Thanks so much.

  7. Evan Herman
    Member
    Posted 1 year ago #

    How can it be easy if you have no PHP knowledge?

  8. Evan Herman
    Member
    Posted 1 year ago #

    Heres the code that I provided someone else , with a similar issue to yours.

    <?php
    	global $post;
    	if ( in_category('2', $post->ID) ) {
    	  echo 'category 2!';
    	} elseif ( is_category('3', $post->ID) ) {
    	  echo 'category 3!';
    	} elseif ( in_category('4', $post->ID) ) {
    	  echo 'category 4!';
    	} else {
    	  echo 'NO CATEGORY!';
    	}
    ?>

    It's cross checking the current page with the category ID. That is placed inside of header.php.

    Depending on which category your post or page is in, it will print out something different.

  9. n.allen
    Member
    Posted 1 year ago #

    Frustrated, not mad. I tried something similar to what you've provided here, but will try this. Thanks so much.

  10. alchymyth
    Forum Moderator
    Posted 1 year ago #

    generally, you would need to locate the template and code where the header image gets generated; and then implement the conditional php code.

    however, you seem to be using a theme which is not from https://wordpress.org/themes/, and this forum can therefore not help you much. http://codex.wordpress.org/Forum_Welcome

    try to contact the developer of your theme for support (possibly via themeforest http://themeforest.net/item/xmarket-responsive-wordpress-ecommerce-theme/3558432/support )

  11. n.allen
    Member
    Posted 1 year ago #

    Yes, it's XMarket. The designer from our outsourced company chose it

Topic Closed

This topic has been closed to new replies.

About this Topic