Switch up the Thumbnail Image based on the selected category

While testing a shopping site I created, I encountered an issue with changing the banners at the top of the page based on the category the user is viewing.

This site is hosted on a server on my localhost, not using wordpress by the way.

<div class="item">
  <div class="image">
    <img src="assets/images/banners/cat-banner-1.jpg" alt="" class="img-responsive">
  </div>
  <div class="container-fluid">
    <div class="caption vertical-top text-left">
      <div class="big-text">
        <br />
      </div>

      <?php $sql=mysqli_query($con,"select categoryName  from category where id='$cid'");
while($row=mysqli_fetch_array($sql))
{
    ?>

      <div class="excerpt hidden-sm hidden-md">
        <?php echo htmlentities($row['categoryName']);?>
      </div>
      <?php } ?>

    </div>
    <!-- /.caption -->
  </div>
  <!-- /.container-fluid -->
</div>

I attempted to use PHP for making the banner section responsive like this:

<div class="image">

<?php if (is_category( 'Entertainment' )) : ?><img class="round_corners hover-shadow" src="assets/images/banners/cat-banner-1.jpg"/><?php endif;?>

<?php if (is_category( 'Science' )) : ?><img class="round_corners hover-shadow" src="assets/images/banners/cat-banner-2.jpg"/><?php endif;?>

<?php if (is_category( 'Lifestyle' )) : ?><img class="round_corners hover-shadow" src="assets/images/banners/cat-banner-3.jpg"/><?php endif;?>
  </div>

I understand that my approach was not very efficient, but it was the best I could come up with and unfortunately, it did not work.

What changes do I need to make in the PHP code to switch the banner images for different categories? Is there a way to achieve this without relying on PHP?

Answer №1

php

<?php 

if $is_category == 'Entertainment' {

<img class="round_corners hover-shadow" src="assets/images/banners/cat-banner-1.jpg"/>

}else if{ $is_category =='Science' {

<img class="round_corners hover-shadow" src="assets/images/banners/cat-banner-2.jpg"/>

}else{ $is_category =='Lifestyle' {

<img class="round_corners hover-shadow" src="assets/images/banners/cat-banner-3.jpg"/>

}

?>

css

.round_corners { 
some format 
}
.hover-shadow {
some style
} 

html

display $is_category

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Looking to eliminate the bullet point next to the labels on a highcharts graph?

I have implemented a Highcharts solid gauge in my project, and you can view a sample image https://i.stack.imgur.com/QQQFn.png However, I am facing an issue where unwanted grey bullets are appearing in the test environment but not locally. I have checked ...

Best Practices for Integrating PHP Code into an HTML File for Contact Form Placement

My current setup involves an html file named index.html, which contains the code for my contact form fields such as name and email. Is there a way to include PHP code in this file without converting it to index.php? ...

jQuery regex failing to display latest changes

I am running into some issues with my custom jQuery snippet that is supposed to dynamically display the results. Each H2 tag contains an image, and I want to ensure the image is positioned correctly next to the word "test." Here is the script in question: ...

ASP.NET MVC2 JsonResult: Sorry, this request has been denied

Although this question may sound familiar, I just can't seem to get over it. This section pertains to my Controller Action: public JsonResult AddToCart(int pId, int qty = 1, int optVal = 0) { AjaxActionResult response = new AjaxActionResult(); r ...

What are the best practices for running node in VSCode?

$ node test.js internal/modules/cjs/loader.js:883 throw err; ^ I have exhausted all possible solutions, including checking the PATH route for Node.js, restarting, and using different files. Despite the fact that I am able to retrieve the version when ...

Tips for correcting the `/Date(xxxxxxxxxxxxx)/` formatting issue in asp.net mvc

As a programming novice, I am trying to display data from my database server on the web using a datatable in asp.net mvc. After following a tutorial video on YouTube, I encountered an issue where the date and time columns in my table are displaying as /Dat ...

jQuery Autocomplete - Showing array of options upon selecting input field in Internet Explorer

After encountering an issue with the autocomplete feature in a web application, I posted a question on Stack Overflow. The provided answer solved the problem in Chrome, but unfortunately, it did not work in Internet Explorer 8 or 9, and possibly earlier ve ...

The filter function in JavaScript's Array is malfunctioning on Internet Explorer version 7

My web application includes a jQuery plugin that is functioning correctly in Internet Explorer 10 and 11. However, it is not working in IE 7. Upon investigation, I discovered that the value of the filter method is showing as undefined. The line of code th ...

When utilizing the getIntersectionList function, IE 9 may experience a malfunction and cease functioning

I am currently working with SVG code and JavaScript, trying to achieve a specific intersection result. <svg id="svgSurface" width="500" height="500"> <defs> <marker id="Triangle" viewBox="0 0 20 20" refX="0" refY="0" markerUnits ...

What is the best way to connect a string to a scoped variable in a view?

I'm looking to connect a string to a scope variable that will be determined by user input in an input field located within a specific view. The goal is for the combined string and scope variable value to appear in another div within the view. Here&ap ...

Disabling the scrollbar in Selenium screenshots

When using Chromedriver to capture screenshots of webpages, my code effectively does the job. However, I am now facing an issue with removing the unsightly scrollbars from the image. Is it feasible to inject CSS into the webpage in order to achieve this? W ...

C#: Issues with loading static content in MVC on various environments with IIS

Within my C# MVC 4.5 Website, I recently introduced a new folder to host CMS-type applications separately from the main site. While everything seemed fine during local testing, issues arose after deploying the updates to the DEV environment. A closer look ...

When attempting to change the text in the textarea by selecting a different option from the dropdown list, the text is not updating

I am facing an issue with three multi-select dropdown lists. When a user selects options from these lists and then presses the submit button, the selected text should display in a textarea. However, if the user manually changes some text in the textarea ...

Swap out the content in a text input box with the text chosen from a suggested autocomplete option

I am working on a text input box with auto-complete options displayed below it. I want to enable users to navigate through the options using keyboard arrows and "select" one, causing it to change color. How can I update the text in the input box with the s ...

AJAX loading footer content before images are fully loaded

I am a beginner when it comes to ajax and I'm facing an issue where the footer loads before the images, causing the images to overlap the footer. The problem is illustrated in the image below. <!doctype html> <html lang="en"> <head ...

Tips for maintaining grid width when columns are rearranged in the column menu

Is it possible to stop jqgrid from changing its width to full screen after column selection? I attempted the code below, following guidance from How to change column name in column chooser pop up in jqgrid? My aim was to create a column switcher function ...

Alert: The function mysqli_query() requires the first parameter to be of type mysqli, but a string was provided in the file path E:OficinaxampphtdocsFormulario-Oficinalistartecnicas.php on

I am facing an issue with my code Alert: mysqli_query() function is expecting the first parameter to be of type mysqli, but a string was provided in E:\Oficina\xampp\htdocs\Formulario-Oficina\listartecnicas.php on line 6 Additi ...

Utilizing Promises with Multiple .then() in JavaScript

I'm currently in the process of creating an array structure. In this structure, we have different parts and each part contains articles. What I've done is create a promise to gather all the parts using .then(), then I need to iterate through eac ...

When using PHP's json_encode function with an array of objects, it may result in

In my PHP code, I have an array that looks like this when using var_dump: array(135) { [0]=> object(Book)#138 (2) { ["id"]=> string(36) "93ec4cd6-49a3-4dc6-94f1-00295cc9cdaf" ["title"]=> string(33) "title 1" } [1]=> o ...

Hover effect for child element not activating CSS3 Transition

I need my list item to activate a css3 transition on its child element .pusher when it is hovered over. I usually achieve this using JS, but I want to try implementing it with css3 transitions. After reading some other questions on SO, I attempted to do it ...