samedi 31 janvier 2015

How To Get WordPress Categories Link List?


I am trying to make a custom sitemap for my WordPress blogs categories. For that I added the below code in my functions.php file and when I save it, my Blog goes white. Nothing is showing up. I removed this code by going through FTP and then all got again fine.


Now I want to make and use this code. Now can anyone help me out to fix this code?



/* ------------------------------------------------------------------------- *
* Custom Dynamic XML Sitemap Generator For Categories
/* ------------------------------------------------------------------------- */
add_action("publish_post", "cat_create_sitemap");
add_action("publish_page", "cat_create_sitemap");
function cat_create_sitemap() {
$categoriesForSitemap = get_categories(array(
'hide_empty' => 0,
depth => 0,
'hierarchical' => false
));

$sitemap = '<?xml version="1.0" encoding="UTF-8"?>';
$sitemap .= '<?xml-stylesheet type="text/xsl" href="sitemap-style.xsl"?>';
$sitemap .= '<urlset xmlns="http://ift.tt/xwbjRF">';

foreach($categoriesForSitemap as $category) {
setup_postdata($category);
$categorydate = explode(" ", $category->category_modified);
$sitemap .= '<url>'.
'<loc>'. get_permalink($category->ID) .'</loc>'.
'<priority>1</priority>'.
'<lastmod>'. $categorydate[0] .'</lastmod>'.
'<changefreq>daily</changefreq>'.
'</url>';
}
$sitemap .= '</urlset>';
$fp = fopen(ABSPATH . "custom-cat-sitemap.xml", 'w');
fwrite($fp, $sitemap);
fclose($fp);
}




Aucun commentaire:

Enregistrer un commentaire