Modify image content in HTML without the need for additional web pages

Seeking your assistance, I have recently built a website using a free HTML/CSS template that I stumbled upon. However, I am encountering an issue.

I am interested in setting up a gallery on the site, but I have an extensive collection of images spread across various categories. I am unsure if there is a way to avoid creating multiple pages for each category.

I envision having a single HTML file with a data container where, based on the selected category, the corresponding images and text will be dynamically loaded without the need to create individual pages for each category.

As someone relatively new to websites, I am unfamiliar with suitable tools or methods to achieve this objective. Are you aware of any techniques that can help me accomplish this task? Is it even feasible?

Answer №1

Definitely, PHP would be the way to go for this task - You can create a dynamic single page with generated content.

It might not be practical to cover an entire category-based gallery in one response, but a quick search online should yield plenty of simple PHP galleries you can explore.

Many of these solutions utilize SQL databases to display the gallery view, complete with thumbnails and more.

Answer №2

An easy way to organize photos in the same category is by placing them under a single div and using Jquery to show or hide based on your selection.

Here's an example of how you can achieve this:

<input type="radio" value="category1" name="type" />Category 1
<input type="radio" value="category2" name="type"/> Category 2

<div class="category1" style="display:none;">
    <ul>
        <li><img src="photo1.jpg"/>Photo 1</li>
        <li><img src="photo2.jpg"/>Photo 2</li>
    </ul>
</div>

<div class="category2" style="display:none;">
    <ul>
        <li><img src="photo3.jpg"/>Photo 3</li>
        <li><img src="photo4.jpg"/>Photo 4</li>
    </ul>
</div>

To implement this functionality, here is the corresponding JavaScript:

$(document).ready(function(){
    $('input[type="radio"]').click(function(){
        if($(this).attr("value")=="category1"){
            $(".category2").hide();
            $(".category1").show();
        }
        if($(this).attr("value")=="category2"){
            $(".category1").hide();
            $(".category2").show();
        }

    });
});

You also have the option to use anchor links instead of radio buttons. Feel free to explore different alternatives for your project.

Check out a live demo on JSFiddle.

Answer №3

Instead of providing ready-to-use code, here's an idea for you to consider implementing on your website.

Imagine organizing your pictures by storing image URLs in a multi-dimensional array based on different categories and subcategories. Then, dynamically populate your gallery based on the selection made from a dropdown menu, all within one page.

The dropdown menu would display the various categories as selectable options.

Here is an example HTML structure:

<select id="menu">
    <option value="0">Select Category</option>
    <option value="1">Animals</option>
    <option value="1.1"> - Cats</option>
    <option value="1.2"> - Dogs</option>
    <option value="2">Cars</option>
    <option value="3">Hats</option>
</select>

<div id="gallery"></div>

The JavaScript array could resemble something like this:

[[[cat1, cat2], [dog1, dog2]], [car1, car2], [hat1, hat2]]

By selecting Cats, only cat pictures are displayed, while choosing Animals shows images of both cats and dogs.

Feel free to check out this interactive demo.

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

HTML email - image appears in email only on selected devices

I am experiencing an issue with my EDM. While the images look fine on my desktop and mobile devices, some of them are not showing up when I try to send the email to other phone devices (they display as "not found"). All the images are already hosted on my ...

The find function within $(this) is malfunctioning

I'm having issues with displaying/hiding content when clicking on a table row. Here is the simplified code snippet: HTML: <table> <tr onclick="showDetails()"> <td>Some text <br> <span class="hiddenC ...

Adjust the size of a component dynamically to match another

In this scenario, we are dealing with two columns labeled A and B. Typically, column A contains more content, resulting in a greater height of 126px, while column B has less content, leading to a shorter height of 94px. The challenge arises when the h ...

Transferring the values of JavaScript objects to HTML as strings

My goal is to generate HTML elements based on the values of specific JavaScript objects that are not global variables. However, when attempting to execute the code below, I encounter an error stating "params is not defined." What I actually aim to achieve ...

Why is the angular navigation bar not appearing on the screen?

Currently, I am in the process of learning Angular through a Udemy course instructed by Maximilian Schwarzmuller. One of the topics he covers is creating a navigation bar. I have tried to implement the same code for my navigation bar, but unfortunately, it ...

Using CSS to Showcase Text and Images

Setting up a database for Weapons for Sale and incorporating PHP code: <?php echo '<link rel="stylesheet" href="display.css" type="text/css">'; function FindPhoto($name) { $dir_path = "http://www.chemicalzero.com/FireArms_Bis/Guns ...

How can I activate the mobile zoom feature on kinetic js?

I am currently working on a website using kinetic js + html5 canvas. Everything looks great on the web, but I am facing some issues with the display on mobile devices. Is there a solution to enable the mobile pan and zoom function in kinetic js? Thank you ...

Alert: Angular 5 detects an invalid selector '';'

I am encountering an issue with my Angular 5 application. After running ng b --prod, I am seeing the following warnings: Warning in Invalid selector '; .space1x at 6219:39. Ignoring. The CSS style for space1x in style.css is as follows: .space1 ...

Using Python with Selenium to verify the attribute's value is correct

I need to verify the value of an attribute within an element. Below is my Python code snippet: validkey = False # Check if the key was valid. element = w.find_element_by_id('registerkey_form') # Check if the activation message is displayed, i ...

Exploring the varying flexbox behavior with (overflow-y) scroll on Safari, Firefox, and Edge compared to Chrome

When viewing this plunker page on Chrome for Windows and Android (including Canary), everything functions properly. I am able to scroll the two areas on the left and right, and the top and bottom divs of the page remain at the top and bottom of the device ...

What is the best way to make a div take up the entire screen until triggering a scrollTo function?

I noticed an interesting design feature on this website (). No matter how much you resize your window, the div containing the guy's name and background image fills up the entire screen until you scroll down or click the 'read more' link. It ...

What are the steps to prevent the information in a text box from disappearing after submitting and calculating?

When this code is executed, it retrieves information about the starting and ending addresses and calculates the distance between them. However, a problem arises when the user submits the form - the input fields for entering the addresses are cleared. < ...

Issue when rendering HTML using bootstrap-table.js

I am currently facing an issue with displaying all the links in my dynamic list with a bootstrap filter. For some reason, the HTML code is being displayed instead of the expected output. Any assistance in resolving this matter would be greatly appreciate ...

Express and Node.js working together

Recently, I've been encountering an issue with my POST function. Whenever I click on the log in button, a message pops up saying: Cannot POST /login I'm at a loss here and would greatly appreciate any help you can provide \(^-^\) B ...

Having difficulty aligning an image vertically within a table cell

I am facing an issue with aligning images in table cells. Specifically, I have four table cells and want to vertically align a smaller image at the top of its cell. Despite trying to use vertical-align:top for the image within the cell, it doesn't see ...

Creating a row in your HTML frontend with automated three-column cards

Hello everyone, I am currently new to Django and also learning HTML simultaneously. I am working on a small project in Django, but encountering a problem with the frontend part, specifically related to HTML elements. As you can see in the image attache ...

Creating a div element that maintains a consistent aspect ratio regardless of its width or height

I've been working on making my player div responsive in terms of height. Currently, when I resize the width, the div scales down accordingly. However, resizing the height does not have the same effect. The scrollbar doesn't seem to help either du ...

Activate hover effect on desktop screen (excluding tablets and phones) by utilizing media queries

Applying hover state styling to a div can be done like this: div { &:hover { color: red !important; border: 3px solid red !important; } } To exclude iPads and other tablets from this CSS style, you can util ...

Tips for providing a link to a label and passing a query string to a different page in ASP.NET using C#

I am working on an asp.net page with SQL Server 2008 as the database. I have created three stored procedures; one to count the total number of users in tbl_users, another for counting the total male users, and the last one for counting the total female use ...

HTML set hover & active states to remain active indefinitely

NOTE: My project utilizes Angular, so Angular may offer a solution to this issue as well I am in the process of creating a page where I can preview and test out various styles that I have designed. In order to achieve this, I need to somehow activate both ...