Chris
Chris

Reputation: 1929

point to article without having a menu link

I work with Joomla for some time but I have only little question. How can I point to an article without first make a link of it in a menu?

Upvotes: 0

Views: 2721

Answers (3)

bumerang
bumerang

Reputation: 1846

My solution is quite different:

  1. First create some menu with you will never use, unless you already need any category to be browsed. The point is: you need to have links to category with will be the same as category alias, and if any category is subcategory add parent category as parent menu position.

  2. Categories has path in database, this path is: parent-alias/other-parent-alias/more-parents/category-alias now, if you have done first step you should be able to get to category using it path data (function below).

  3. Use sql query to get that path, and other function to make article slug

this is code for 2 functions that should help you

/**
* $art si article object
*/
function articleLink(&$art){
    // create slug
    $link = $art->id.'-'.$art->alias;

    // get category link (path)
    $cat_link = categoryLinkFromArticle($art);
    $link = $cat_link.'/'.$link;
    return $link;
}


function categoryLinkFromArticle(&$art){
    $db = JFactory::getDbo();
    $db->setQuery("SELECT * FROM #__categories cat WHERE cat.id='$art->catid'");
    $cat = $db->loadObject();

    $link = $cat->path;
    return $link;
}

Typical usage

<?php foreach ($articles as $item) :  ?>
    <?php $link = articleLink($item); ?>
    <a href="<?php echo $link; ?>" ><?php echo $item->title; ?></a>
<?php endforeach; ?>

Upvotes: 0

jlleblanc
jlleblanc

Reputation: 3510

Also, the JCE Editor has a button where you can link to any article and sidestep the menu system: http://extensions.joomla.org/extensions/88/details

Upvotes: 2

Chris Thompson
Chris Thompson

Reputation: 35598

Do you mean link? The dirty way to do it is you can pull the id and the title out of the url when you are editing it and then get creative with your link to reconstruct a url (by using a link you already know about) that the user will need to get to the article.

Does that make sense?

Upvotes: 1

Related Questions