Published on 12/27/2018
Published by Swapnil k
Creating Custom Sitemap For The App
Sometimes we don’t use CPT’s to show the content.
suppose I have an app that shows job listing and a single job page
in this case job is not a post, it’s a lead in the database.
so for the job single page, wpseo is not gonna create a sitemap.
to create our custom site-map follow these steps:
- Create settings in app config(if not available).
- Create meta field ‘enable_sitemap’ in settings module and set value to yes, this will create a sitemap of that app.
- Create a new module in config named custom-sitemap and write your custom code in this module.
Sample custom-sitemap module:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
//** get all the jobs which are not closed.**// [module.set_array job_xml_query] [pageno]1[/pageno] [pagesize]2000[/pagesize] [with] [sql] SELECT coll_id as data_id,object_id FROM job_postings where coll_type='job' and meta_key='status' and meta_value != 'closed' [/sql] [/with] [transform ref_id=data_id /] [meta new] [table]job_postings[/table] [meta_keys]job_slug,key_skills,location,created_datetime[/meta_keys] [coll_type]job[/coll_type] [id_field]coll_id[/id_field] [/meta] [/module.set_array] [db.meta_query query="{module.job_xml_query}" set='template.res' /] //**generate sitemap of jobs**// [loop.@job template.res.rows] <url> <loc>[php.site_url /]/current-openings/job/[aw2.get @job.item.job_slug /]</loc> <lastmod>[aw2.get @job.item.created_datetime /]</lastmod> </url> [/loop.@job] |