Question

For a project I'm working on, I've run into the following problem

I have a module that loads articles based on category. I need these articles to be loaded in another article with {loadposition}, where an module will be loaded that loads the articles for that category.

For each said category I have an title and some text, and after that the module with the articles will be loaded. However, when there are no articles in the category, I'll get the title and text but no related articles.

What I'd want, is when there are no articles in a category and thus no articles will be shown, I also want to hide the title and text from that category.

I have tried to use the countModules function, but that won't work since the module for loading the articles will always be active, even if there are no articles in that category at all. Is there any way I could achieve this? Maybe some way to see if there actually are any articles in the category, and based on that show or hide the title and text?

Any help would be greatly appreciated

Was it helpful?

Solution

What you could do it, open the article in the backend and in the editor, click the small "html" button. You will see your article text and title will be wrapped around a <p> tag. So firstly, add a class to it like so:

<p class="my_module_article">Title of Article</p>
<p class="my_module_article">Text for article</p>

Then in your module default.php use an if and else statement and inside a little CSS like so:

$results = "the code you used to get the articles from the category";

if ($results) {
    //code to display the articles
}
else {
    $doc = JFactory::getDocument();
    $doc->addStyleDeclaration(".my_module_article { display: none; }");
    echo "There are no articles to be displayed";
}

I hope this helps

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top