Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic Page Titles for Articles and Categories in Blog Pages #417

Open
mostafaafrouzi opened this issue Dec 6, 2024 · 0 comments
Open

Comments

@mostafaafrouzi
Copy link

Is your feature request related to a problem? Please describe.

Currently, the Page Title feature in Helix Ultimate Framework inherits the title of the parent menu item. While this works for static pages or when separate menu items are created for each sub-page, it falls short in dynamic scenarios like blogs or articles.

For example:

  • A parent menu item titled "Blog" will display "Blog" as the Page Title for all articles and categories under it, even when navigating through individual articles.
  • This is problematic because users expect the Page Title to dynamically reflect the actual content (e.g., article or category name).

Additionally, the current behavior can cause semantic issues with HTML heading structure:

  • The Page Title is rendered with either <h1> or <h2> tags. However, if the parent menu title is static, it does not align with the actual page content, leading to accessibility and SEO issues.

Describe the solution you'd like

I propose the following enhancements:

  1. Dynamic Page Titles:

    • Update the title.php feature to detect the current page type.
    • If the page is an article, fetch and display the article title as the Page Title.
    • If the page is a category, fetch and display the category title as the Page Title.
  2. Improved Heading Structure:

    • Ensure the <h1> tag dynamically reflects the article or category title.
    • Adjust secondary heading tags (e.g., <h2> or <h3>) to maintain proper semantic HTML structure.

Additional context

Here is an example of how this could be implemented in title.php:

$input = $app->input;
$option = $input->getCmd('option');
$view = $input->getCmd('view');
$id = $input->getInt('id');

if ($option == 'com_content' && $view == 'article' && $id) {
    $db = Factory::getDbo();
    $query = $db->getQuery(true)
        ->select($db->quoteName('title'))
        ->from($db->quoteName('#__content'))
        ->where($db->quoteName('id') . ' = ' . (int) $id);
    $db->setQuery($query);
    $article_title = $db->loadResult();

    if ($article_title) {
        $page_title = $article_title;
    }
} elseif ($option == 'com_categories' && $view == 'category' && $id) {
    $db = Factory::getDbo();
    $query = $db->getQuery(true)
        ->select($db->quoteName('title'))
        ->from($db->quoteName('#__categories'))
        ->where($db->quoteName('id') . ' = ' . (int) $id);
    $db->setQuery($query);
    $category_title = $db->loadResult();

    if ($category_title) {
        $page_title = $category_title;
    }
}




These changes will improve:

User Experience: Page Titles dynamically adapt to the displayed content, making navigation more intuitive.
SEO: Dynamic <h1> tags improve search engine optimization by aligning with the content of each page.
Semantic HTML Compliance: Proper heading structures ensure accessibility and align with HTML best practices.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant