Category: Code Snippets

A library of code samples for use in Joomla development.

Check User Group By Group ID

July 17, 2024
Check User Group By Group ID

There are many scenarios where you may need to check what group(s) a user is in. For example, I use this code to check if users are in my “Sponsors” group. If they are, I don’t display any advertisements for them and I show them a shiny purple star. Snippet Function Example This is how […]

Get Article Field Values From Anywhere

July 17, 2024
Get Article Field Values From Anywhere

The following code snippets use Joomla’s Database Classes to retrieve information about any article in the __content table of your Joomla database. Note that every function requires you to use Factory. So be sure to include the use statement at the top of the file you’re using any of these functions in. Remember, querying the […]

Accessing Custom Article Fields From Template Layouts

July 17, 2024
Accessing Custom Article Fields From Template Layouts

Suppose you want to create a custom article option in Joomla 4/5. In this example, I’m creating two fields -> “showspecialtext” and “specialtext”.  The “showspecialtext” field will be a boolean with a value of 0 or 1. If it it zero, nothing will happen on the single article page. If it’s 1, it will print […]

Adding Custom Fields On Extension Install

July 17, 2024
Adding Custom Fields On Extension Install

Custom Fields may be useful in many Joomla extensions. They can be added by calling a custom script file upon an extension install or uninstall. The script will use Joomla’s database driver to manually insert new custom field records. I created this code to go along with my guide on loading custom article fields within layout […]

Accessing Custom User Field Values With PHP

July 17, 2024
Accessing Custom User Field Values With PHP

In my guide on custom user fields in Joomla, I show how to add custom fields to a user’s profile. By default, Joomla only allows you to use these fields to show or save information about users. If you’re a developer, you can use this to programmatically add user-specific functionality to your website.  Scenario Suppose you want […]

Jump to category: