OXID Community Forum

> German forum > Entwickler > Google Sitemap Xml - Einfach zu Erstellen
Login
FAQ Members List Calendar Search Today's Posts Mark Forums Read

Thread: Google Sitemap Xml - Einfach zu Erstellen


Reply
 
Thread Tools Display Modes
#Top   #1  
Old 07-27-2009, 03:42 PM
DIATOM's Avatar
DIATOM DIATOM is offline
Senior Member
Join Date: Apr 2009
Location: Leipzig
Posts: 143
DIATOM is on a distinguished road
Send a message via ICQ to DIATOM Send a message via Skype™ to DIATOM
Cool Google Sitemap Xml - Einfach zu Erstellen

Hallo Jungs,

es gibt bestimmt viele unter euch die Ihren Shop bei Google anmelden wollen,
um diesen für Suchmaschinen zu optimieren.

Daher ist aber eine so genannt Google Sitemap Xml von nöten, die leider
bie Oxid nicht dabei ist und auch nur in überteuerten Modulen angeboten wird.

Da wir selber eine schnell Lösung brauchten,
habe ich ein kleines Script aufgesetzt was diese selbst erstellt.

In der Sitemap werden mit SEO URLs alle
Kategorien, Produkte und Kundencmsseiten gespeichert.

google_sitemap_xml.php
Code:
<?php

/*
Google Sitemap Xml v.0.1
--------------------------------
oxid ESales - SEO
--------------------------------
by DIATOM Internet & Medien GmbH
--------------------------------
c: 27.07.2009 | u: 27.07.2009
*/


/* BEGIN - Config ----------------------------------------------------------- */

    // Default
    $xmlList                        = array();
    $xmlInsert                      = array();

    // Config
    $mod_cnf                        = array();
    $mod_cnf['filepath']            = './';
    $mod_cnf['filename']            = 'sitemap.xml';
    $mod_cnf['siteurl']             = 'http://www.domain.de/';
    $mod_cnf['sql_server']          = "localhost";
    $mod_cnf['sql_dbname']          = "";
    $mod_cnf['sql_dbuser']          = "";
    $mod_cnf['sql_dbpw']            = "";
    
    // Error
    $error                          = array();
    $error['connect']               = "keine Mysql Verbindung gefunden!";
    $error['select']                = "kein Mysql Datensatz gefunden!";
    
/* END - Config ------------------------------------------------------------- */


/* BEGIN - Function --------------------------------------------------------- */

    // Function - Create Xml File
    function createXmlFile($xmlInsert) {
    
        global $mod_cnf;
    
        // File Create
        $fp = fopen($mod_cnf['filepath'].$mod_cnf['filename'], "w+");
        fwrite($fp, implode("\n", $xmlInsert));
        fclose($fp);  
    }
    
    // Function - get Categorys
    function getCategorys() {
    
        global $mod_cnf;
    
        // Default
        $list       = array();
    
        // Sql - Select
        $sql_sel   = "SELECT
                            oxid,
                            oxtitle,
                            oxdesc,
                            oxlongdesc
                        FROM oxcategories 
                        WHERE
                            oxactive = 1 AND
                            oxhidden = 0
                        ORDER by oxtitle ASC
                        ";
        $sql_query  = mysql_query($sql_sel);
        while( $sql_row = mysql_fetch_array($sql_query) ) {
        
            // Vars
            $loc                = $sql_row['oxid'];
        
            // List
            $list[] = array(
                'loc'           => getSeoUrl($loc),
                'priority'      => '1.0',
                'lastmod'       => date('Y').'-'.date('m').'-'.date('d').'T'.date('h').':'.date('i').':'.date('s').'+00:00',
                'changefreq'    => 'weekly',
            );
        }
        
        return $list;
    }
    
    // Function - get Products
    function getProducts() {
    
        global $mod_cnf;
    
        // Default
        $list       = array();
    
        // Sql - Select
        $sql_sel   = "SELECT
                            oxart.oxid as oxid,
                            oxart.oxartnum as oxartnum,
                            oxart.oxtitle as oxtitle,
                            oxart.oxshortdesc as oxshortdesc,
                            oxart.oxtimestamp as oxtimestamp
                        FROM oxarticles as oxart 
                        LEFT JOIN oxobject2category as oxobj2cat ON ( oxobj2cat.oxobjectid = oxart.oxid )
                        LEFT JOIN oxcategories as oxcat ON ( oxcat.oxid = oxobj2cat.oxcatnid )
                        WHERE
                            oxart.oxactive = 1 AND
                            oxcat.oxactive = 1 AND
                            oxcat.oxhidden = 0
                        ORDER by oxart.oxartnum ASC
                        ";
        $sql_query  = mysql_query($sql_sel);
        while( $sql_row = mysql_fetch_array($sql_query) ) {
        
            // Vars
            $loc                = getSeoUrl($sql_row['oxid']);
            $oxtimestamp        = explode(" ", $sql_row['oxtimestamp']);
        
            // List
            $list[] = array(
                'loc'           => $loc,
                'priority'      => '0.5',
                'lastmod'       => $oxtimestamp[0].'T'.$oxtimestamp[1].'+00:00',
                'changefreq'    => 'daily',
            );
        }
        
        return $list;
    }
    
    // Function - get CMS Sites
    function getCmsSite() {
    
        global $mod_cnf;
    
        // Default
        $list       = array();
    
        // Sql - Select
        $sql_sel   = "SELECT
                            oxid,
                            oxtitle
                        FROM oxcontents
                        WHERE
                            oxactive = 1 AND
                            oxfolder = 'CMSFOLDER_USERINFO'
                        ORDER by oxtitle ASC
                        ";
        $sql_query  = mysql_query($sql_sel);
        while( $sql_row = mysql_fetch_array($sql_query) ) {
        
            // Vars
            $loc                = getSeoUrl($sql_row['oxid']);
        
            // List
            $list[] = array(
                'loc'           => $loc,
                'priority'      => '1.0',
                'lastmod'       => date('Y').'-'.date('m').'-'.date('d').'T'.date('h').':'.date('i').':'.date('s').'+00:00',
                'changefreq'    => 'weekly',
            );
        }
        
        return $list;
    }
    
    // Function - Get SEO URL
    function getSeoUrl($oxid) {
    
        global $mod_cnf;
        
        // Default
        $url        = '';
    
        // Sql - Select
        $sql_sel   = "SELECT
                            oxstdurl,
                            oxseourl
                        FROM oxseo 
                        WHERE
                            oxobjectid = '". $oxid ."' AND
                            oxlang  = '0'
                        LIMIT 1
                        ";
        $sql_query  = mysql_query($sql_sel);
        if( $sql_row = mysql_fetch_array($sql_query) ) {
        
            // Var
            $url = $sql_row['oxseourl'];
            if( empty($url) ) $url = $sql_row['oxstdurl']; 
        
            return $url;
        }
        
        return $url;
    }

/* END - Function ----------------------------------------------------------- */


/* BEGIN - Action ----------------------------------------------------------- */

    // SQL Connect
    $sqlConnect = mysql_connect($mod_cnf['sql_server'], $mod_cnf['sql_dbuser'], $mod_cnf['sql_dbpw']) OR die($error['connect']);
    mysql_select_db($mod_cnf['sql_dbname'], $sqlConnect) OR die($error['select']);

    // Get - Categorys
    $xmlList_cat        = getCategorys();
    
    // Get - Products
    $xmlList_prod       = getProducts();
    
    // Get - Cms Site
    $xmlList_cms        = getCmsSite();
    
    // Output - Xml
    $xmlList            = array_merge($xmlList_cat, $xmlList_prod, $xmlList_cms);


/* END - Action ------------------------------------------------------------- */


/* BEGIN - Output ----------------------------------------------------------- */

    // Vars
    $xmlInsert[] = '<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.google.com/schemas/sitemap/0.84"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://www.google.com/schemas/sitemap/0.84
	http://www.google.com/schemas/sitemap/0.84/sitemap.xsd">';
    
    foreach($xmlList as $key => $val) {
    
        // Vars
        $xmlInsert[] = '<url>
    <loc>'. $mod_cnf['siteurl'].$val['loc'] .'</loc>
    <priority>'. $val['priority'] .'</priority>
    <lastmod>'. $val['lastmod'] .'</lastmod>
    <changefreq>'. $val['changefreq'] .'</changefreq>
</url>';
    }
    
    // Vars
    $xmlInsert[] = '</urlset>';
    
    
    // Create Xml File
    createXmlFile($xmlInsert);
    
    
    // Output - User Info
    echo '<a href="'. $mod_cnf['filepath'].$mod_cnf['filename'] .'" target="_blank">XML Datei betrachten</a>';

/* END - Output ------------------------------------------------------------- */

?>
Später soll sich das ganze noch automatisch aktualisieren und
auch mehrere Sprachen unterstützen.

mfg, Sebastian

P.s. more Modules 4 Free ;-)
Reply With Quote
#Top   #2  
Old 07-27-2009, 04:17 PM
QuickCom's Avatar
QuickCom QuickCom is offline
Senior Member
Join Date: May 2009
Posts: 130
QuickCom is on a distinguished road
Send a message via MSN to QuickCom Send a message via Skype™ to QuickCom
Default AW: Google Sitemap Xml - Einfach zu Erstellen

Hallo Sebastian,

erstmal Danke für Deine Arbeit. Wo allerdings lege ich diese Datei ab ?

Sonnige Grüße aus Dresden

Dirk
Reply With Quote
#Top   #3  
Old 07-27-2009, 04:28 PM
DIATOM's Avatar
DIATOM DIATOM is offline
Senior Member
Join Date: Apr 2009
Location: Leipzig
Posts: 143
DIATOM is on a distinguished road
Send a message via ICQ to DIATOM Send a message via Skype™ to DIATOM
Default AW: Google Sitemap Xml - Einfach zu Erstellen

Einfach im Hauptordner von Oxid, würde ich sagen.
Ist aber ehh egal, weil die Datei ohne Oxid arbeitet.

Also SQL Daten net vergessen ;-) ( siehe $mod_cnf )

grüße, Sebastian
Reply With Quote
#Top   #4  
Old 07-27-2009, 04:43 PM
QuickCom's Avatar
QuickCom QuickCom is offline
Senior Member
Join Date: May 2009
Posts: 130
QuickCom is on a distinguished road
Send a message via MSN to QuickCom Send a message via Skype™ to QuickCom
Default AW: Google Sitemap Xml - Einfach zu Erstellen

Danke Sebastian.

Dirk
Reply With Quote
#Top   #5  
Old 07-27-2009, 05:36 PM
tobi73de's Avatar
tobi73de tobi73de is offline
Senior Member
Join Date: Apr 2009
Location: Geringswalde
Posts: 320
tobi73de is on a distinguished road
Default Re: Google Sitemap Xml - Einfach zu Erstellen

super Sache !
Reply With Quote
#Top   #6  
Old 07-28-2009, 01:03 PM
MichaelZ MichaelZ is offline
Senior Member
Join Date: Dec 2008
Posts: 189
MichaelZ is on a distinguished road
Default Re: Google Sitemap Xml - Einfach zu Erstellen

Vielen Dank.

Aber ich habe da noch ein Problem:
Ich habe meine Artikel teilweise in 2 Kategorien stehen. Die URL bleibt dieselbe. Nun wird diese URL 2 mal eingetragen.
Habe nun für die Funktion get Products statt
Select
nun
select distinct
eingefügt. Scheint meiner Meinung nach zu funktionieren.
Da ich aber nun mal keine Ahnung habe, frage ich lieber:
Bekomme ich nun andere Probleme (URLs, die er mir nun zuwenig ausgibt oder ähnliches)?
Und wenn ja, wie kann ich es besser machen?

Danke
Michael
Reply With Quote
#Top   #7  
Old 07-29-2009, 10:34 AM
DIATOM's Avatar
DIATOM DIATOM is offline
Senior Member
Join Date: Apr 2009
Location: Leipzig
Posts: 143
DIATOM is on a distinguished road
Send a message via ICQ to DIATOM Send a message via Skype™ to DIATOM
Wink AW: Google Sitemap Xml - Einfach zu Erstellen

Ohh, daran hab ich gar nicht gedacht.

Folgende Lösung sollte das Problem lösen:

Function: (Änderung)
Code:
// Function - get Products
    function getProducts() {
    
        global $mod_cnf;
    
        // Default
        $list       = array();
    
        // Sql - Select
        $sql_sel   = "SELECT
                            oxart.oxid as oxid,
                            oxart.oxartnum as oxartnum,
                            oxart.oxtitle as oxtitle,
                            oxart.oxshortdesc as oxshortdesc,
                            oxart.oxtimestamp as oxtimestamp
                        FROM oxarticles as oxart 
                        LEFT JOIN oxobject2category as oxobj2cat ON ( oxobj2cat.oxobjectid = oxart.oxid )
                        LEFT JOIN oxcategories as oxcat ON ( oxcat.oxid = oxobj2cat.oxcatnid )
                        WHERE
                            oxart.oxactive = 1 AND
                            oxcat.oxactive = 1 AND
                            oxcat.oxhidden = 0
                        GROUP by oxart.oxid
                        ORDER by oxart.oxartnum ASC
                        ";
        $sql_query  = mysql_query($sql_sel);
        while( $sql_row = mysql_fetch_array($sql_query) ) {
        
            // Vars
            $loc                = getSeoUrl($sql_row['oxid']);
            $oxtimestamp        = explode(" ", $sql_row['oxtimestamp']);
        
            // List
            $list[] = array(
                'loc'           => $loc,
                'priority'      => '0.5',
                'lastmod'       => $oxtimestamp[0].'T'.$oxtimestamp[1].'+00:00',
                'changefreq'    => 'daily',
            );
        }
        
        return $list;
    }
- "GROUP by oxart.oxid"
- Jetzt sollte sich die SQL Abfrage nur auf die Tabelle "oxarticles" beziehen
und doppelte Einträge im "Left Join" ignorieren.

Sonst sollte alles normal funktionieren.

P.s. Getestet habe ich es noch nicht ^^

mfg, Sebastian
Reply With Quote
#Top   #8  
Old 07-29-2009, 11:02 AM
MichaelZ MichaelZ is offline
Senior Member
Join Date: Dec 2008
Posts: 189
MichaelZ is on a distinguished road
Default Re: AW: Google Sitemap Xml - Einfach zu Erstellen

Hallo Sebastian
Danke, sieht gut aus (ich habe zumindest nun keine Doppelten mehr).

Für die Produktsuche habe ich aber als Kriterium noch:
oxart.oxstock > 0
eingefügt.
Artikel, die ich nicht mehr auf Lager habe, werden bei mir nicht gelistet. Habe ich also für die Sitemap dann auch herrausgenommen.
Gruss
Michael
Reply With Quote
#Top   #9  
Old 09-19-2009, 09:47 AM
dreifachonline dreifachonline is offline
Member
Join Date: Jun 2009
Posts: 83
dreifachonline is on a distinguished road
Default AW: Google Sitemap Xml - Einfach zu Erstellen

grandios DIATOM, das läuft perfekt. Thx
Reply With Quote
#Top   #10  
Old 11-23-2009, 07:17 AM
oberleiner's Avatar
oberleiner oberleiner is offline
Senior Member
Join Date: Oct 2008
Location: QuickAudio, Leuna
Posts: 137
oberleiner is on a distinguished road
Default AW: Google Sitemap Xml - Einfach zu Erstellen

Hallo DIATOM,

bekommt ihr das auch für die 3er Version hin?

best wüsches
oberleiner
Reply With Quote
Reply

Bookmarks

Tags
erstellen, google, sitemap, xml

« Previous Thread | Next Thread »
Thread Tools
Display Modes

Nicht Sichtbar
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Google Sitemap Generator fertig !!! aggrosoft Module 2 03-18-2013 12:18 PM
Google Aktualisierung auch über Sitemap unvollständig / Mehrere Versuche schon gescheitert ... ZuvielPCPlatzhirn Allgemeines 6 07-11-2010 11:57 AM
Google Sitemap? monteiro Modules 3 03-01-2010 04:17 PM
Empfehlung Google Sitemap Generator tobi73de Administration 3 02-18-2010 03:36 PM
Google Sitemap Generator erfaßt nur Startseite SvenA Newbies 7 09-08-2009 05:34 PM

All times are GMT +2. The time now is 11:21 PM.