Como crear un Sitemap.xml sin plugin?
-
Hola tengo un problema agregue este codigo al archivo .xml pero no pasa nada no genera nada, aqui dejo el codigo si ven algun problema
// header(‘Content-Disposition: attachment; filename=»sitemap.xml»‘); // SI SE HABILITA, NOS DEVUELVE UN FICHERO SITEMAP.XML
function poetxmlsitemapgenerator_init(){
// OBTENER LISTA DE LOS POST
$posts = get_posts(array(
‘numberposts’ => -1,
‘orderby’ => ‘modified’,
‘post_type’ => array ( ‘product’,’page’,’post’), // URL QUE SE MOSTRARÁN EN EL SITEMAP.
‘order’ => ‘DESC’ // ORDEN: EL MÁS RECIENTE CREADO O ACTUALIZADO SE SITUARÁ EN PRIMER LUGAR.
));// GENERAR CADENAS XML SITEMAP
$xmlsitemap = ‘<?xml version=»1.0″ encoding=»UTF-8″?>’;
$xmlsitemap .= ‘<?xml-stylesheet type=»text/xsl» href=»sitemap-style.xsl»?>’; // HOJA DE ESTILO PARA LA PRESENTACIÓN EN HTML
$xmlsitemap .='<urlset xmlns=»http://www.sitemaps.org/schemas/sitemap/0.9″>’;// URL´S DE LOS POSTS, PÁGINAS Y PRODUCTOS Y CATEGORÍAS DE PRODUCTO.
foreach($posts as $post) {
setup_postdata($post);
$postdate = explode(» «, $post->post_modified);
$xmlsitemap .= ‘<url>’.
‘<loc>’. get_permalink($post->ID) .'</loc>’. // URL DE LAS PÁGINAS, POST, CATEGORIAS, PRODUCTOS
‘<lastmod>’. $postdate[0] .'</lastmod>’. // DEJA CONSTANCIA EN EL SITEMAP DE LA ÚLTIMA ACTUALIZACIÓN.
‘<changefreq>weekly</changefreq>’. // FRECUENCIA CON LA QUE PUEDE CAMBIAR ESTA PÁGINA: ALWAYS, HOURLY, DAILY, WEEKLY, MONTHLY, YEARLY, NEVER
‘<priority>0.9</priority>’. // FIJA LA RELEVANCIA/IMPORTANCIA DE LAS PÁGINAS/PRODUCTOS ETC, AHORA ESTÁ AL 90%
‘</url>’;
}// PÁGINA PRINCIPAL
$xmlsitemap .= ‘<url>’.
‘<loc>’. get_site_url() .'</loc>’.
‘<lastmod>’. date(‘l dS of F Y h:i:s A’) .'</lastmod>’.
‘<changefreq>monthly</changefreq>’.
‘<priority>1</priority>’.
‘</url>’;// TODAS LAS CATEGORIAS DEL BLOG
$categories= get_categories();
foreach ($categories as $category) {
$xmlsitemap .= ‘<url>’.
‘<loc>’. get_category_link($category->term_id) .'</loc>’.
‘<lastmod>’. date(‘Y-m-d’) .'</lastmod>’.
‘<changefreq>weekly</changefreq>’.
‘<priority>0.5</priority>’.
‘</url>’;
}// LISTAR TODAS LAS TAGS
$tags = get_tags();
foreach ( $tags as $tag ) {
$xmlsitemap .= ‘<url>’.
‘<loc>’. get_tag_link($tag->term_id) .'</loc>’.
‘<lastmod>’. date(‘Y-m-d’) .'</lastmod>’.
‘<changefreq>weekly</changefreq>’.
‘<priority>0.7</priority>’.
‘</url>’;
}$xmlsitemap .= ‘</urlset>’;
$file = ABSPATH . «sitemap.xml»;// ESCRIBIR LA CADENA DE SITEMAP XML
$fp = fopen(ABSPATH . «sitemap.xml», ‘w’);
fwrite($fp, $xmlsitemap);
fclose($fp);
}// XML SITEMAP GENERADO
add_action(‘publish_page’, ‘poetxmlsitemapgenerator_init’);
add_action(‘publish_post’, ‘poetxmlsitemapgenerator_init’);
add_action(‘trashed_post’, ‘poetxmlsitemapgenerator_init’);
add_action(‘save_post’, ‘poetxmlsitemapgenerator_init’);
// add_action(‘before_delete_post’,’poetxmlsitemapgenerator_init’);espero que me ayuden ya que no quiero instalar plugins :(
El blog con el que necesito ayuda es (visible solo para usuarios conectados).
-
El blog especificado en flowloud.com no se encuentra alojado en WordPress.com.
Este foro de soporte es para blogs hospedados en WordPress.com. Si tu pregunta es acerca de un blog de WordPress que tú hospedas, encontrarás ayuda en el foro de WordPress.org.
Si no entiendes la diferencia entre WordPress.com y WordPress.org, puedes encontrar esta información muy útil.
Este es un mensaje automatizado.
- El debate ‘Como crear un Sitemap.xml sin plugin?’ está cerrado y no admite más respuestas.