1

We are currently evaluating different cookie consent solutions considering its price models and therefore we need to know the amount of "active" URLs in our Craft multisite installation.

Does Craft somewhere cache or save complete URLs which I could count?

(I'm not sure if it does but since Craft always makes sure that URLs are unique I have hope that it does.)

2
  • Without delving into the database, can't you just count how many URL-enabled elements you have, multiplied by the number of sites?
    – gioppe
    Aug 30 at 8:31
  • With Commerce and its product variants, not all entries available in all languages and so on, this might be inaccurate. Aug 31 at 6:02
1

You could have a look at Luke Peter's Sitemap solution. This is a script that generates your sitemap. You can modify it to fit your need and just output a list of URLs.

Generate an XML Sitemap in Craft CMS

{# Create an empty array for all published entries #}
{% set entry_list = [] %}

{# Create a URI exclusion list for entries you don't want in the sitemap #}
{% set exclusions = ["blog/unlisted-blog-post", "thank-you-page"] %}

{# Get all sections (singles, channels, and structures) #}
{% set sections = craft.app.sections.allSections %}

{# Loop through each section #}
{% for section in sections %}

  {# Get all entries of this section type, but only if they're published and have a URL #}
  {% set entries = craft.entries.sectionId(section.id).status("live").uri("not ''").all() %}

  {# Merge these entries into the main list #}
  {% set entry_list = entry_list|merge(entries) %}
  
{% endfor %}

{#
  Loop through all published entries to create the sitemap markup.
  Skip any entries with a URI that appears in the exclusions list.
#}
<ul>
{% for entry in entry_list if entry.uri not in exclusions %}
  <li><a href="{{ entry.url }}">{{ entry.url }}</a></li>
{% endfor %}
</ul>

Most SEO Plugins that generate a Sitemap might solve this problem as well.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.