WordPress.org

Ready to get started?Download WordPress

Forums

Adding a banner above posts (2 posts)

  1. chrisntoukas
    Member
    Posted 4 months ago #

    Hello there.

    I was wondering if there is any way that i can add a banner above posts of a specific category.

    Thanks in advance.

  2. Maria Antonietta Perna
    Member
    Posted 4 months ago #

    Hi chrisntoukas,

    One way you can do this is by following these steps:

    1. Create a child theme;
    2. duplicate single.php from the parent to the child (create a file called single.php and copy all of the content from single.php in the parent theme into single.php in the child theme);
    3. In single.php in the child theme, find the place where you want the banner ad to appear and add the following snippet

    <?php if (in_category ('category1')) {  ?>
    	<div class="banner-ad">
    	 This is a banner ad
    	</div>
    
    <?php } ?>

    On the basis of the code above, if we're viewing a post in category 1, a banner ad will be displayed.

    Obviously, you will adapt the category slug (the category name) and the mark-up for the banner ad to your own needs.

    I hope it helps.

Reply

You must log in to post.

About this Topic

Tags

No tags yet.