简体   繁体   中英

Create article as menu item

I am fairly new to using Joomla (3.3) and I followed the instructions on a post here to create an article programmatically using this code:

<?php
define('_JEXEC', 1);
define('DS', DIRECTORY_SEPARATOR);

if (file_exists(dirname(__FILE__) . '/defines.php')) {
   include_once dirname(__FILE__) . '/defines.php';
}
if (!defined('_JDEFINES')) {
   define('JPATH_BASE', dirname(__FILE__));
   require_once JPATH_BASE.'/includes/defines.php';
}

define('JPATH_COMPONENT_ADMINISTRATOR', JPATH_BASE . DS . 'administrator' . DS . 'components' . DS . 'com_content');
require_once JPATH_BASE.'/includes/framework.php';


require_once JPATH_BASE. "/administrator/components/com_content/models/article.php";


$app = JFactory::getApplication('site', array('session' => false));

$new_article = new ContentModelArticle();

$data = array(
    'catid' => '17',
    'title' => 'Title',
    'introtext' => '<h4><strong>Intro Text Here</strong></h4>',
    'fulltext' => '<p>This is the full text paragraph </p>'
    'state' => 1,
);
$new_article->save($data);

I'd like to be able to create the article as a menu item but I'm not even sure where to even start. Any help appreciated.

Regards

Jim

I think you're making it a bit more complicated than it needs to be. In fact it's pretty simple. In your administrator panel, go to you menu.

Menus > Main Menu (or which menu you want) > Click on 'Add new' > Menu Item Type (click) > Click 'Articles' to expand the section > Single Article

When you do that you will have an option open up where you can select the article you want to be on that menu item.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM