XML / Sitemap

Discussion in 'Programming' started by izlik, Dec 21, 2013.

  1. #1
    Hello

    I have a problem. I have a sitemap for a page with images on it and i want the imagelinks into the sitemap. the URL is like this "file/8639/1920x1440/stretch/another_one_1.jpg"

    The things that changes in the URL is
    1: "8639" wich is the ID of the image in the database,
    2: "1920x1440" wich is the resolution, users can choose different resolutions from the original this is also the foldername of that specific size. the folder name is like this /file/8639/1920x1440/ for this specific image, this size is not in the databse, only the original size is.
    3: "another_one_1.jpg" ofcourse changes for the image name, this is in the database under "name"
    4: "stretch" is in the database under a collumn called "display"

    The things that stay the same is "file".

    So, how can i make this into a sitemap for the images themselves? i have one for the "php links" wich is like this. i also would like this for every entry in the database like the one with the links bellow, hope someone can help with this?

    $sql_query = "SELECT * FROM `images`";
    $result = mysql_query($sql_query);

    if (mysql_num_rows($result) != 0)
    {
    while ($row = mysql_fetch_assoc($result))
    {
    $url = WallpaperUrl($row['id'], $row['seo_url'], $row['category']);
    $xmloutput = "
    <url>
    <loc>".$url."</loc>
    <lastmod>".$azi."</lastmod>
    <changefreq>weekly</changefreq>
    <priority>0.7</priority>
    </url>";
    echo $xmloutput;
    }
    }

    Hope someone can help me wich this.
     
    Last edited: Dec 21, 2013
    izlik, Dec 21, 2013 IP
  2. jk.deff

    jk.deff Active Member

    Messages:
    59
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    55
    #2
    I do not quite understand the question.
    Example of Google's Image Sitemaps You can see here:
    https://support.google.com/webmasters/answer/178636

    Final code will be about such:
    // !!!!!     Here you need to complete
    $list_of_resolutions = array('1920x1440','1280x1024','1024x768');
    $domain = 'http://example.com/';
    //
    
    
    $sql_query = "SELECT * FROM `images`";
    $result = mysql_query($sql_query);
    
    if (mysql_num_rows($result) != 0)
    {
        while ($row = mysql_fetch_assoc($result))
        {
            $url = WallpaperUrl($row['id'], $row['seo_url'], $row['category']);
            $xmloutput = "
            <url>
            <loc>".$url."</loc>
            <lastmod>".$azi."</lastmod>
            <changefreq>weekly</changefreq>
            <priority>0.7</priority>";
    
            foreach ($list_of_resolutions as $resolution)
            {
                // "file/8639/1920x1440/stretch/another_one_1.jpg"
                $img_loc = $domain . 'file/'.$row['id'].'/'.$resolution.'/'.$row['display'].'/'.$row['name'];
                $xmloutput .= '<image:image><image:loc>'.$img_loc.'</image:loc></image:image>';
            }
    
            $xmloutput .= "</url>";
            echo $xmloutput;
        }
    }
    Code (markup):
    You understand that I can not test it, so there may be small errors.

    Important is not to forbid access in robots.txt for folder with pictures.
     
    Last edited: Dec 21, 2013
    jk.deff, Dec 21, 2013 IP