简体   繁体   中英

PHP Code to display article title in Joomla Featured Blog View Menu Item

I am currently developing a Joomla 1.7 website, And I am using J2Store shopping Cart so I have to make make an article for every Product.

Then to display I create a Joomla Featured Articles Menu Item for the appropriate Category, my problem is this, The default Article Title isn't really appropriate for the page layout and because there will be many products / articles so as a time saver I would like to include some PHP code to retrieve the Article Title I have tried the following used in conjunction with the Sourcerer plugin.

<?php echo JFactory::getDocument()->getTitle(); ?>

But unfortunately it displays the Menu Title not the individual Article Titles, I also found the following code but I cant get it to work with Joomla 1.7

<?php   
    $option = JRequest::getCmd('option');
$view = JRequest::getCmd('view');
if ($option=="com_content" && $view=="article") {
    $ids = explode(':',JRequest::getString('id'));
    $article_id = $ids[0];
    $article =& JTable::getInstance("content");
    $article->load($article_id);
    echo $article->get("title");
} ?>

Try this:

$product =& JTable::getInstance("content");
$product->load($product_id);
echo $product->get("title");

And replace $product_id with whatever ID needed.

Look at this file:

components/com_content/views/featured/tmpl/default.php

That's the original template for the Featured Articles view, you can override it as explained in this link:

http://docs.joomla.org/How_to_override_the_output_from_the_Joomla!_core

to include a piece of code like this (in the file you created on your template folder):

<?php 
foreach($this->items as $fItem): 
    echo $fItem->title.'<br/>';
endforeach;
?>

Voilà, you will see all the titles from the displayed featured articles.

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