0

I would like to prevent some specific articles from being shown on com_content blog view and featured articles view.

For example, if the article has a specific ID that I seted on code like "27" he will not show up on menu id 101 or count on the listing.

Yes, I am aware that creating a template overhaul for com_content on my template and just making a simple "if" statement on the right place would be enough. BUT, they want the development of a new plugin to handle this part and I would just make this post longer to explain why.

So I was asking myself if a code on a custom Joomla Plugin could affect and change the com_content article query and if yes I would like a example. Thanks.

Something like:

<?php
$menu =&JSite::getMenu();
$idm = $menu->getActive()->id;
$delist = array(27, 28);


if($idm == 101 && in_array($idofthearticle, $delist)){
// code to delist article from current page view
} 

?>
1
  • If by any chance you want a similar solution and is asking yourself how you could do it in a simpler way. First, do a template overhaul: docs.joomla.org/… Then on your file (like, blog.php) Find the foreach function code <?php foreach ($this->intro_items as $key => &$item) : Inside put: code $this->item = &$item; if(!in_array($item->id, $extarticles)){ ?> Remember to close if below right before the end of the foreach. On this example $extarticle is a array with ids. Apr 5, 2017 at 5:17

3 Answers 3

1

AFAIK, and you can look in the code, there is no plugin triggerer in getListQuery statement. So basically you can not.

But there is 2 workarounds (not pretty really):

  • strip not needed block in onBeforeRender at system plugins;

  • and the really weird one: after system is initialized replace (override, load instead of) content model with your own one that will modify the query before pulling items from DB. There is lots of techniques all-over the web on how to do such override.


Some links:


But if you good with your PHP knowledge basically what you want to do as the best solution:

  • read file with Joomla Class
  • change class name for example from JoomlaClass to JoomlaClassOverrided
  • create your own class with class JoomlaClass extends JoomlaClassOverrided
  • and implement override and load both classes.

This way you will only override needed parts.

And I went ahead and done simple plugin that will allow to do this kind of things. Hardcoded for now, but I'll work on improving it went there would be few minutes for it.

For now check the link https://github.com/alex7r/overrideany

p.s. As said before: you can use it to override only parts you needed and not copy whole code.

3
  • Maybe the second option that you listed could be what I am looking for, but I could not find anything searching on the web. Could you provide some links? Apr 5, 2017 at 8:14
  • I've added some links
    – Alexandr
    Apr 5, 2017 at 8:35
  • Hey, you can look at my github repository to solve your issue now. I left the link above, stars would be appreciated )
    – Alexandr
    Apr 5, 2017 at 20:53
0

Create your custom model/view

Maybe you would be better if you would create your own model/view with its menu item and use it for that page. This would be somewhat easy - simply duplicate the core model/view you want, do any renaming where necessary and then you can write your own queries to fit your needs.


Before going that far though, make sure that you have covered all other possibilities and workarounds that may be more than adequate for your needs. So, although you have not gone into details about what your final goal is and all the why's, here are some suggestions that maybe you have not realized they do exist.


Use different/more categories.

For example, I want to point out that an article will not appear in the blog layout of a category if it belongs to another category. So, working around this you may have a real simple solution: Just change the articles category. In case you still need a good categorization organization, you could go a step further and create that with subcategories and separate the articles of that parent category to those that are to be displayed in the blog layout than those that aren't. Then in your menu item simply select the proper category and adjust any of the other settings like showing child categories articles etc.


Use Featured Articles

Also, from your question above I see you mention menu item with id = 101. Usually the 101 is the default id of the home menu item and by default this is the featured items menu item. So here maybe it worths pointing that you can have FEATURED ARTICLES blog layout per category that will display only those articles marked as featured.


Use articles status

Finally there are even more options - depending on your needs. You can set an article to UNPUBLISHED status - this will make the article totally unavailable from both the blog layout and as a whole. But there is also the ARCHIVE status available, which will remove the article from the blog layout, but it will remain available and accessible - either from a menu item or directly. Something that seems very close to cover exactly what you have described above - while keeping those articles under the same category.

0

I realize that I'm not really answering your question, but I would like to share our experience on the subject, since some of our clients requested the same thing, but they left the details of the implementation to us.

Generally, we like to minimize the plugins as much as possible. So, the way we do it, we add a small HTML comment at the beginning of the article:

<!-- hide in categories -->

And then, in the category blog layout, we check the introtext for the above string, and if it is there, we skip the article. The only downside is that the number of articles displayed may not be accurate - for example, if you set each page to display 20 articles, and 2 of these articles are hidden, then the page will only display 18.

The upside of this method is that displaying/hiding an article from the blog is done at the article level, and not somewhere else (which makes it easier for editors).

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.