-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrandom.php
28 lines (20 loc) · 814 Bytes
/
random.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<?php
/* Affichage d'un article aléatoire d'un blog qui tourne avec Joomla 3.X */
/* Cette version utilise l'API de Joomla */
/* version 0.3.1 */
define('_JEXEC', 1);
define('JPATH_BASE', __DIR__ . '/');
require_once JPATH_BASE . '/includes/defines.php';
require_once JPATH_BASE . '/includes/framework.php';
// Création d'une connexion avec la Base de données
$db = JFactory::getDbo();
// La requête est un objet
$query = $db->getQuery(true);
// The requête pour avoir tout les articles
$db->setQuery("select * from #__content where state='1'");
$data = $db->loadObjectList();
// On prends un article au hasard parmi tous ceux de la liste
$idArticle = array_rand($data, 1);
// Ici, ça affiche l'article
header("Refresh: 0;URL=index.php?option=com_content&view=article&id=".$data[$idArticle]->id);
?>