Cotonti / Cotonti

Fast, reliable and flexible PHP CMF/CMS
https://www.cotonti.com
BSD 3-Clause "New" or "Revised" License
92 stars 51 forks source link

The URL and Title of the last post in forums.functions.php #1773

Open webitproff opened 3 months ago

webitproff commented 3 months ago

SEO optimization is important to many of us. Those who understand the importance of this factor are clearly using the "URL Editor" plugin, including for the "Forums" module. To avoid unwanted indexing and duplicates, we are forced to "robots.txt" use rules, for example:

Disallow: /index.php?e=users&*
Disallow: /users?*
Disallow: /login
Disallow: /search?*
Disallow: /*?*
Disallow: /*&*
Disallow: /*&tag=*
Disallow: /rc.php?rc=*

But such rules also close indexing of pages that we would like to see in the search, for example:

https://project.com/forums/section/subsection/cat/topic777

but in the topics section, in the list, this link looks like this

https://project.com/forums/section/subsection/cat/topic777?n=last#bottom

that is, it will not be indexed by search engines here...

I suggest in forums.functions.php , add to the array of tags for the last post like this:


$tag_prefix . 'LASTPOST_ONLY_TITLE' =>  $stat['fs_lt_title'],
$tag_prefix . 'LASTPOST_ONLY_URL' => cot_url('forums', 'm=posts&q=' . $stat['fs_lt_id']),

Thus, we get values that we can customize to suit our needs already on the template side, for example:

<h3>
  <a href="{FORUMS_SECTIONS_ROW_LASTPOST_ONLY_URL}">
    <span class="my-class">{FORUMS_SECTIONS_ROW_LASTPOST_ONLY_TITLE|cot_cutstring($this, '75')} </span>
  </a>
</h3>

This will also allow you to show flexibility in which URL to give to guests (including search engines), and which to give to an authorized user.

For example:

<!-- IF {PHP.usr.id} > 0 -->
<h3>
  <a href="{FORUMS_SECTIONS_ROW_LASTPOST_URL}">
    <span class="my-class">{FORUMS_SECTIONS_ROW_LASTPOST_ONLY_TITLE|cot_cutstring($this, '36')} </span>
  </a>
</h3>
<!-- ELSE -->
<h3>
  <a href="{FORUMS_SECTIONS_ROW_LASTPOST_ONLY_URL}">
    <span class="my-class">{FORUMS_SECTIONS_ROW_LASTPOST_ONLY_TITLE|cot_cutstring($this, '75')} </span>
  </a>
</h3>
<!-- ENDIF -->

Just two lines for two new tags allow you to flexibly adjust these values on the frontend side, especially if SEO optimization is important to you and you use custom section templates, for example:

forums.sections.name-firstsection.tpl forums.sections.name-secondsection.tpl forums.sections.name-privatesection.tpl