Skip to main content

Create and adding a new article in Joomla.

Meta Description

Create a new article with Joomla in a few easy steps. Learn how to do it here!

Introduction

Adding a new article in Joomla is an easy and straightforward task! This article covers the required steps to create a new article in Joomla. To get started, the user must first acquire a Joomla account and login to the administration console. From there, the user will be presented with several options for creating and modifying articles. 🤓

Once the user is logged in, the next step is to select the 'New' button at the top of the page. This will open up a new page in the Joomla administration console. Here, the user will be able to customize the new article page with a title, content, categories, images and other elements. 📝

In order to publish the new article, the user should click the ‘Save’ button at the top of the page. Finally, the user can view the published article in the Joomla website by navigating to the article's URL.🖥️

Code

<?php
// Get the form values
$title = $_POST['title'];
$content = $_POST['content'];
$catid = $_POST['catid'];

// Create an article record in the Joomla database
$db = JFactory::getDbo();
$query = $db->getQuery(true);

$columns = array('title', 'introtext', 'catid', 'state', 'access');

$values = array($db->quote($title), $db->quote($content), $db->quote($catid), 1, 1);

$query
->insert($db->quoteName('#__content'))
->columns($db->quoteName($columns))
->values(implode(',', $values));

$db->setQuery($query);
$db->execute();
?>

Output

No output.

Explanation

The above code snippet is used to create an article record in the Joomla database. It takes the title, content and category ID from the form and inserts a new row in the #__content database table. The state and access columns are set to default values 1 and 1 respectively. 🎓

Get Help