Post Search Approach
- Pull out all of your posts and pages from the database
- Iterate through all pages / posts and do a string search on the content –
substr_count( 'http://www.yourdomain.com', $page->content );
- Sum up the counts from all the posts / pages
This will of course miss allot of links made by plugins, navigation etc – hence “half-ass”.
Site Scraping Approach
- Collect all the URLs you want to count links from
- Iterate through the URL list and use
file_get_contents( $the_url )
to get the page / post as a string - Perform the string search described above and sum them all up
This approach will double count the links persistent through many pages (navigation and sidebars).
There is, I’m sure a much better way to do this – but that’s all I could come up with off the top of my head. I’m sure you could tweak either approach to suit the degree of coverage you want.