*

Ajit Sahane

  • ****
  • 180 posts
  • https://bestclassifiedsusa.com
Want all images name & image sitemap generation
« on: February 10, 2025, 03:38:00 AM »
Osclass item we ad images, so around per ad item around 2-4 images we are adding.

And urls generated look like - https :// xyz. com/oc-content/uploads/0/148_thumbnail.webp  OR

https :// xyz. com/oc-content/uploads/1/569.webp
---------------------------------------------------------

So instead of this 569 numbering how we can set image name as per real image name. IF image name is [ bmw car for sale texas.jpg ]  then
URL should generate like - https :// xyz. com/oc-content/uploads/1/bmw-car-for-sale-texas.jpg or webp   etc

if img name is duplicate then auto change it like - https :// xyz. com/oc-content/uploads/1/bmw-car-for-sale-texas_1.jpg or webp


Also, want Image sitemap - with select option - Ad Img + Page Img + Website other Img etc

I hope this must required feature soon added in Osclass.

MB Team, Kindly Update on this.

*

MB Themes

Re: Want all images name & image sitemap generation
« Reply #1 on: February 10, 2025, 06:48:52 AM »
Osclass does not support named images yet.
  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots

*

Ajit Sahane

  • ****
  • 180 posts
  • https://bestclassifiedsusa.com
Re: Want all images name & image sitemap generation
« Reply #2 on: February 16, 2025, 09:40:20 AM »
anyway, if item img SEO optimized naming not possible, that's fine.

Next - How can we create sitemap_image.xml 

like -

<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
        xmlns:image="http://www.google.com/schemas/sitemap-image/1.1">

  <url>
    <loc>https ://xyz . com/for-sale/bike-for-sale-i123</loc>
    <image:image>
      <image:loc>https ://xyz . com/oc-content/uploads/0/image1.jpg</image:loc>
      <image:title>Item Title 1</image:title>
    </image:image>
    <image:image>
      <image:loc>https ://xyz . com/oc-content/uploads/0/image2.jpg</image:loc>
      <image:title>Item Title 1</image:title>
    </image:image>
  </url>

  <url>
    <loc>https ://xyz . com/oc-content/for-sale/car-for-i1234</loc>
    <image:image>
      <image:loc>https ://xyz . com/oc-content/uploads/1/image3.png</image:loc>
      <image:title>Item Title 2</image:title>
    </image:image>
  </url>

</urlset>



*

MB Themes

Re: Want all images name & image sitemap generation
« Reply #3 on: February 16, 2025, 12:40:42 PM »
I have not heard about sitemap for website images yet to be honest.
  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots

*

Ajit Sahane

  • ****
  • 180 posts
  • https://bestclassifiedsusa.com
Re: Want all images name & image sitemap generation
« Reply #4 on: February 16, 2025, 01:22:00 PM »
Yes, wordpress images auto added in post or page sitemap but osclass no option. So better image indexing its required. in GSC there are lot of error under Page indexing  Crawled - currently not indexed - like

huge img urls - https: //xyz. com/oc-content/uploads/1/257.webp   & YES this urls are no need to index in Google search but for max images indexing and shown in Google Image Search if we add this then its add value. after adding this image sitemap still GSC error not gone, but atleast max image index.

So, I played around code and make 1 php code file to generate this sitemap. Have a look and suggest any improvement if anything wrong in this.

After add this file to your Root directory - just hit this URL and your sitemap generated.

I hope our community will help a lot who want more advanced SEO approach. 

attached .txt file open and save as .php and upload to your root directory of osclass.

or see full code here -

Code: [Select]
<?php
// Prevent output buffering issues
if (ob_get_length()) ob_end_clean();
function 
decode_xml_entities($string) {
    return 
html_entity_decode($stringENT_QUOTES ENT_XML1'UTF-8');
}
// Load Osclass Core
require_once dirname(__FILE__) . '/oc-load.php';
require_once 
osc_base_path() . 'oc-includes/osclass/model/Item.php';
require_once 
osc_base_path() . 'oc-includes/osclass/model/ItemResource.php';

// Define the sitemap file path
$filename osc_base_path() . 'sitemap-images.xml';
$sitemap_url osc_base_url() . 'sitemap-images.xml';
@
unlink($filename);

// Start capturing XML output
ob_start();

// XML Declaration - Ensure it's the first output
echo '<?xml version="1.0" encoding="UTF-8"?>
' . "\n";
echo '<?xml-stylesheet type="text/xsl" href="' . osc_base_url() . 'oc-content/plugins/sitemap_pro/css/stylesheet.xsl"?>' . "\n";
echo '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" ';
echo 'xmlns:image="http://www.google.com/schemas/sitemap-image/1.1">' . "\n";

// Initialize counters
$total_items = 0;
$total_images = 0;

// Get all active items
$itemModel = new Item();
$items = $itemModel->listWhere("b_active = 1 AND b_enabled = 1", "pk_i_id DESC", 0, 5000);

foreach ($items as $item) {
    $item_id = $item['pk_i_id'];
    $item_url = osc_item_url_from_item($item);

    if (!empty($item_url)) {
        $total_items++;
        echo "  <url>\n";
        echo "    <loc>" . htmlspecialchars($item_url, ENT_XML1, 'UTF-8') . "</loc>\n";

        // Get correct images
        $resourceModel = new ItemResource();
        $resources = $resourceModel->getResources($item_id);
        $item_image_count = 0;

        foreach ($resources as $resource) {
            $image_filename = $resource['pk_i_id'] . ".webp";
            $image_dir = "0";  // Osclass default directory
            $image_path = osc_base_url() . "oc-content/uploads/{$image_dir}/{$image_filename}";

            if (!filter_var($image_path, FILTER_VALIDATE_URL)) {
                continue;
            }
           
    //$image_title = htmlspecialchars(html_entity_decode($item['s_title'], ENT_QUOTES | ENT_XML1, 'UTF-8'), ENT_XML1, 'UTF-8');

   
    $image_title = !empty($item['s_title']) ? html_entity_decode(htmlspecialchars($item['s_title'], ENT_XML1, 'UTF-8'), ENT_QUOTES | ENT_XML1, 'UTF-8') : "Spa Image";


            echo "    <image:image>\n";
            echo "      <image:loc>" . htmlspecialchars($image_path, ENT_XML1, 'UTF-8') . "</image:loc>\n";
            echo "      <image:title>" . $image_title . "</image:title>\n";
            echo "    </image:image>\n";

            $item_image_count++;
        }

        $total_images += $item_image_count;
        echo "  </url>\n";
    }
}

echo "</urlset>\n";

// Save the XML output to the sitemap file
$xml_output = ob_get_clean();
file_put_contents($filename, $xml_output);

// Redirect to success page with message (NO XML OUTPUT HERE)
header("Content-Type: text/html; charset=UTF-8");

echo "<h2 style='color: green;'>✅ Image Sitemap Successfully Generated!</h2>";
echo "<p><strong>📌 View Sitemap:</strong> <a href='{$sitemap_url}' target='_blank'>{$sitemap_url}</a></p>";
echo "<p><strong>🔢 Total Items:</strong> {$total_items} | <strong>Total Images:</strong> {$total_images}</p>";
exit;
?>


*

MB Themes

Re: Want all images name & image sitemap generation
« Reply #5 on: February 18, 2025, 05:12:11 PM »
Sorry I am missing point of that.
Google will get image urls if you provided item link.
  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots