select first item from mod_articles_category

For Joomla! 3.x Coding related discussions, you could also use: http://groups.google.com/group/joomla-dev-general

Moderators: ooffick, General Support Moderators

Forum rules
Locked
pieter-jan
Joomla! Apprentice
Joomla! Apprentice
Posts: 19
Joined: Wed Mar 09, 2016 12:00 pm

select first item from mod_articles_category

Post by pieter-jan » Tue Jun 14, 2016 9:03 am

For a layout override on mod_articles_category, i would like to show the first item in a different way of the rest. Default layout outputs all items the same (foreach.... etc). How do i target the first item specificly and let the rest follow?

itoctopus
Joomla! Virtuoso
Joomla! Virtuoso
Posts: 4025
Joined: Mon Nov 25, 2013 4:35 pm
Location: Montreal, Canada
Contact:

Re: select first item from mod_articles_category

Post by itoctopus » Tue Jun 14, 2016 10:54 am

You can style the first item differently using CSS. You can do this with the first-child selector. For example, if you want the font color of the first time to be red, you can do this the following way:

Code: Select all

.modulecss ul li:first-child {
    color: red;
}
Where modulecss is the CSS of the module (that you can set at the module level).
http://www.itoctopus.com - Joomla consulting at its finest
https://twitter.com/itoctopus - Follow us on Twitter

pieter-jan
Joomla! Apprentice
Joomla! Apprentice
Posts: 19
Joined: Wed Mar 09, 2016 12:00 pm

Re: select first item from mod_articles_category

Post by pieter-jan » Wed Jun 15, 2016 9:15 am

thnx, but i get that method. Point is i want some different classes on the first item (making the first item 6 colums and the rest 3, for example), so i'm looking for a way to target the first item within the module itself, not trough css

User avatar
toivo
Joomla! Master
Joomla! Master
Posts: 17443
Joined: Thu Feb 15, 2007 5:48 am
Location: Sydney, Australia

Re: select first item from mod_articles_category

Post by toivo » Wed Jun 15, 2016 10:07 am

If you need to modify the PHP code and change the current CSS classes of the first article, you can create an override of the file default.php in the html folder of your template:
https://docs.joomla.org/J3.x:How_to_use ... _Overrides
https://docs.joomla.org/Layout_Overrides_in_Joomla
Toivo Talikka, Global Moderator

pieter-jan
Joomla! Apprentice
Joomla! Apprentice
Posts: 19
Joined: Wed Mar 09, 2016 12:00 pm

Re: select first item from mod_articles_category

Post by pieter-jan » Mon Jun 20, 2016 3:56 pm

toivo wrote:If you need to modify the PHP code and change the current CSS classes of the first article, you can create an override of the file default.php in the html folder of your template:
https://docs.joomla.org/J3.x:How_to_use ... _Overrides
https://docs.joomla.org/Layout_Overrides_in_Joomla
Thnx for your answer, but it isn't the answer that i was looking for. I know how to do overrides, i'm looking for a php method to target the first item in an itemloop on mod_articles_category, as discribed in my OP.

User avatar
toivo
Joomla! Master
Joomla! Master
Posts: 17443
Joined: Thu Feb 15, 2007 5:48 am
Location: Sydney, Australia

Re: select first item from mod_articles_category

Post by toivo » Tue Jun 28, 2016 7:04 pm

If you would like someone to do the PHP coding for you, you could perhaps post a request to the Professional Development Services forum at http://forum.joomla.org/viewforum.php?f=177
Toivo Talikka, Global Moderator

sovainfo
Joomla! Exemplar
Joomla! Exemplar
Posts: 8808
Joined: Sat Oct 01, 2011 7:06 pm

Re: select first item from mod_articles_category

Post by sovainfo » Tue Jun 28, 2016 8:42 pm

The standard trick for that is to introduce a boolean initialized to true. Inside the loop you test for true and do whatever you need to do once and set the boolean to false.
Issue with migrating? Include logs/joomla_update.php in your report!
Blank screen? Verify pagesource for HTML code (javascript error)
Installation failing on populating database? Install with set_time_limit(0)
Document your customizations!


Locked

Return to “Joomla! 3.x Coding”