1

I have the following problem. The {loadposition} is specified in the contribution text and appears in the article as it should. Unfortunately, I have now also in the blog view of 6 articles each other also. How can I make the {loadposition} display only once in the blog view?

Sorry for my bad english

Edit:

I would like to load a Module on a definied position. In Single article thats ok. But in the Blogview the module appears on every blogentry. I would like to show the module only at the first blog entry

Mitcha

2 Answers 2

2

You might need to give a more specific example of what the module area is doing for the ideal suggestion. However, a few ideas that might point you in the right direction:

Plugin

Create a plugin that runs before the "Content - Load Modules" plugin. You will need this to detect the page's view and, if it detects the blog category layout, strip any {loadposition} that you do not want to display so that when "Content - Load Modules" runs, the unwanted modules no longer exist in the code it is parsing.

Use Read More

Set the category view to only show the content before the Read More break, and the article view to only show the content after the Read More break. Manually place the modules where they should appear on the category view, ie on one page it will appear both above and below the Read More. This could end up being quite fiddly for the admin who may have to duplicate a lot of content, depending on how your site works.

CSS

Hide the unwanted modules using CSS in the template. Not best practise, but should be a quick-and-easy approach.

Module

Update (if your own), or override (if core or third party) the template of the module so that it counts how many times it has been loaded on a page, and output content or output nothing accordingly.

Design

Does it need to appear in the article, or could you place the module elsewhere on the page without harming usability? If the admin is having to place the same module every time an article is created, it sounds like it may be a design problem.

Update

Is there any reason why you can't create a module area in your template - above or below the component area - and assign the module via the module manager? From the information you have given - this sounds like the best approach.

6
  • Hi Richard,thank u very much for your answer. I would like to load a Module on a definied position. In Single article thats ok. But in the Blogview the module appears on every blogentry. I would like to show the module only at the first blog entry.
    – Mitcha
    Apr 17, 2017 at 19:41
  • What is the module actually doing, and why does it need to be in the middle of an article?
    – RichardB
    Apr 17, 2017 at 19:49
  • its a weather map. this map should be placed in the actual article
    – Mitcha
    Apr 18, 2017 at 6:10
  • Or "the Picture of the Day"
    – Mitcha
    Apr 18, 2017 at 6:20
  • 1
    Changing the design for it to appear alongside the article rather than within the article would seem the most sensible. If that can't be done, I reckon the plugin approach would be your tidiest one. If you just want to hack at the blog layout's html, then you could also just create an override of com_content's category view within your template.
    – RichardB
    Apr 18, 2017 at 8:30
0

If you want loadposition to load only once in the Blog view then you need to do an if statement in

components/com_content/views/category/tmpl/blog.php

Here's the line where it counts the articles

https://github.com/joomla/joomla-cms/blob/staging/components/com_content/views/category/tmpl/blog.php#L72

<?php $leadingcount = 0; ?>

0 is the first one. So you could do a line before this line: https://github.com/joomla/joomla-cms/blob/staging/components/com_content/views/category/tmpl/blog.php#L83

<?php $leadingcount++; ?>

Saying

<?php 
 if ($leadingcount == 0) {
 // do stuff e.g.
 {loadposition myModulePosition}
}
?>

Because you tell it to only do it if leading count == 0 it will only do it the first time. However, if you also need this on your single article, you may be better off to check the article view first.

You can do so by doing this:

<?php 
if ($view == 'article') {
 // do stuff e.g.
 {loadposition myModulePosition}
} ?>

You might even decide you prefer a different module position for each case.

I don't know if that will work out of the box, you might need to do content prepare but since the other {loadposition xxxx} are working I doubt it. If you do need to you can find out how to do so on my other answer Is it possible to add a new module position within a module?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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