skip to Main Content

First off, forgive me if this sounds stupid, I’ll try to explain the best I can. From what I’ve gathered, I think this is like an RSS feed but I’m not 100% sure if what I’m asking is doable.

So say I have a website. Website.com and on my home page I have a div with ‘Pictures’ with an image as the banner. Then I have a different page, website.com/images and on /images I have a set of pictures I upload to daily. Is it possible to link these two pages together so that whatever new picture I put up on /images automatically sets the banner for the home page div?

I know I can hard code the image in but just seeing if this is doable.

<div class="medium-grid flex-column">
        <a class="ab-feat ab-fade height-fix" href="/url!!">
            <div class="title">
                <h3>Images</h3>
                <p>Some random text for now</p>
            </div>
            <div class="img-cover">
                <img src="url/for/banner.jpg" alt="images" />
            </div>
        </a>
    </div>    

2

Answers


  1. When you upload images on the website.com/images, you should save the images url in your database. so that you will be able to get the latest image url from the database and set it as banner on the website.com

    You can create a database table images

    images - id
           - url
           - created_at
    

    html

    <div class="banner">
    
    </div>
    

    javascript

    $.get('url/to/get/latest/image', function (response) {
      $('.banner').css('background-image', response.body.img.src);
    });
    

    or if you receive an array of all the images use this

    $.get('url/to/get/all/images', function (response) {
      $('.banner').css('background-image', response.body.images[images.length -1].src); // use (images.length -1) to have the index of the latest image
    });
    
    Login or Signup to reply.
  2. Yes it’s possible. If you are using WordPress, it has an easy way to create an RSS feed. You will need to create your “images” RSS feed and publish it. This will give you a unique URL that your main page can “subscribe” to. Then, on your main page, you will have to create some mechanism to refresh data from that URL. The easiest way would be to create a polling mechanism that polls that URL and updates your div

    If you are not using WordPress, most CMS’s have something similar built in. Just search their documentation for RSS feeds.

    If you are not using any CMS, this is still doable, but you will have to code everything yourself.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search