Echo Joomla K2 Item Title in Main Template Using PHP - joomla

I'm trying to simply echo the title of the current k2 item I'm viewing, but the echo will not occur within the K2 template, it should show in my MAIN site template.
I tried this:
<?php echo $this->title; ?>
But that displays the FULL site title including my company name because I have it set that way in the main Joomla configuration.
I don't want the full site title that is generated for the 'title' tag in the head of the website; I just want to generate the name of the specific item I am currently viewing. This is probably pretty easy, but my PHP knowledge is limited.

I realise this is pretty old. However if you are still looking for a solution. This is not very elegant but will do what you want.
Firstly, just in case you weren't aware, you can get the article id from anywhere in by doing a JRequest:getVar('id') which will use a GET request to get the id from the URL.
$id = JRequest::getVar('id');
$id = explode(':',$id);
echo $id[0];
The reason I am exploding it is because in my site I am using aliases which if you are and you echo $id without you will see its in the form id:alias.
Using this method, you could query the database to get the name associated with that id in the k2_items table. You could create a function to do that which is else where in the templates folder then just assign it to a variable which you echo in the template. That keeps your template clean but gives you what you want.
Like I say, not a quick elegant solution but will work.

Related

I duplicated products magento and my urls are product-1.html product-2.html

I have made my magento store (community)
I have used duplicate product on a lot of products and I didn't get that the URL key field had to be changed for every product i thought i would solve it self.
Now i have about 100 products and unfortunately they are now named example:
/HaircolorBlack.html , /haircolorblack-1.html, /haircolorblack-2.html and so on.
I wonder if there are any way to easy make magento re create the url after what the products meta title is?
This would be so helpful.
I saw this two year old post about approx the same thing but I didn't wanted to use that script since I don't know if it might break anything in my magento since its been so much updates. Here is link: Clearing URL keys in Magento
Also I need total moron instructions on where to put the script to. Sorry ;)
Thanks a lot.
S
You can create a one off script using magento itself.. add this script somewhere in your magento root folder (beside index.php):
<?php
require_once "app/Mage.php";
Mage::app('admin'); // must be admin to do changes
function convertToUrlKey($string) {
return $string; // I WILL LEAVE YOU TO SOLVE THIS PART
}
foreach(Mage::getModel('catalog/product')->getCollection() as $product):
$metaTitle = $product->getMetaTitle();
$urlKey = convertToUrlKey($metaTitle);
try {
$product->setUrlKey($urlKey);
$product->save();
echo "Assigned url key {$urlKey} to {$product->getName()}.\n";
} catch(Exception $ex) {
echo "ERROR: {$ex->getMessage()}";
}
endforeach;
Obviously this is not a complete solution as you will have to re-create the convertToUrlKey function for the correct behavior of converting 'Black Hair Color' to 'black-hair-color' and also ensure that there will be no duplicate url keys generated..
You can run the script by browsing to it or running through SSH:
$ cd magentoProject
$ php -f changeUrlkeys.php
Good luck!

Path to CKEditor in CakePHP app on Zeus server

I'm integrating CKEditor into a CakePHP app which is running on a Zeus server (and therefore can't use .htaccess - I have to use rewrite.script instead). Problem is, the paths that CKEditor puts into the head section of the page don't work, so the editor won't load.
For instance, one generated path is:
http://www.example.com/js/ckeditor/config.js?t=B8DJ5M3
If I go to
http://www.example.com/js/ckeditor/config.js
I can see the file, but as soon as I add the ?t=B8DJ5M3 on the end, Cake complains that it can't find the jsController.
I'm not sure what to do about this - whether to dig around in CakePHP, CKEditor or the rewrite.script files! What should I try next?
That query string on the end of your URL is used to make sure the file isn't cached. Seems like something in your GET request configuration/routing on the Zeus server is trying to locate that exact file including the query string. You're going to need to create a Rewrite that performs a goto on the URL minus the query string. I found a pretty solid article in the Drupal forums where someone put together a script that may help you: http://drupal.org/node/46508
RULE_0_START:
# get the document root
map path into SCRATCH:DOCROOT from /
# initialize our variables
set SCRATCH:ORIG_URL = %{URL}
set SCRATCH:REQUEST_URI = %{URL}
# see if theres any queries in our URL
match URL into $ with ^(.*)\?(.*)$
if matched then
set SCRATCH:REQUEST_URI = $1
set SCRATCH:QUERY_STRING = $2
endif
RULE_0_END:
And from there, handle your goto minus the query string. Hope that helps
You can do this
In the view where you want to display the editor, put the following script on the top of the page (or somewhere before textarea which you want to contain editor):
<?php echo $this->Html->script('ckeditor/ckeditor');?>
This scipt will include the "webroot/js/ckeditor.js" file to your view.
Create the textarea and give it a class named "ckeditor"
<?php echo $this->Form->textarea('content',array('class'=>'ckeditor'))?>
Voila! The editor is now displaying instead of raw textarea.

Auto fill information for movie products in Magento

I'm working with Magento CE 1.6 in a project where we need an easy way to fill the movie info in DVDs and Blu-Rays products for a reseller ecommerce. I'm set to use the Rotten Tomatoes API wich seems very adequate for our purposes, but here's the thing: We don't want to have to input every single detail of the movie in the New Product dialog, oppositely, we want to fetch the info automatically using the movie name as hint (the API perfectly supports this). I though that we could achieve this by two means:
Having the administrator to enter only the names of the movies and
create and run periodically a script that fetches the rest of the
info with the API and updates the data directly in the DB. I've been
watching the DB changes when a product is saved and would'nt like to
do that.
Editing the Magento code to make the new product form auto fillable,
maybe with ajax, once a movie name is entered. Zend framework isn't
my strong and seems kind of hard too.
Am I seeing this problem from the rigth angle? Is there maybe another API? Or a Magento extension? Or another ecommerce?!
I would suggest a little different approach. Enhancing the Admin interface is difficult, but possible. Here is an easier way.
Method #1 - Quick and Easy
Create yourself a script that would go through a list of products. You can select them by attribute type, category, or even just select them all! Then, loop through that collection, and for each product, grab the title, query the movie API, and set the product's attributes. Then, save the product, and move to the next one. Something like this:
Note: Be sure to create your custom attributes in the admin and assign them to the attribute set.
<?php
require_once 'app/Mage.php';
umask(0);
Mage::app('default');
function getVideoDataFromAPI($title)
{
// get your data from the API here...
return $data;
}
$collection = Mage::getResourceModel('catalog/product_collection')
->addAttributeToFilter('attribute_set_id', $yourAttributeSetId)
->addAttributeToFilter('year', ''); // <-- Set a field here that will be empty by default, and filled by the API. This is '' because it won't be null.
foreach ( $collection->getAllIds() as $id ) {
$product = Mage::getModel('catalog/product')->load($id);
$videoData = getVideoDataFromAPI($product->getName());
if ( empty($videoData) ) { continue; }
$product->setYear($videoData['year'])
->setRating($videoData['rating'])
->save();
}
?>
Method #2 - Do the above, but in a custom extension
I always like extensions over scripts. They are more secure and more powerful. With an extension you could have an admin list of the products, can filter them how ever you would like, and have a mass action to pull the video data manually. You could also set it up on a cron job to pull regularly.

Joomla plugin : how to get article title and article id

I have developed on simple plugin in Joomla 1.6
I stuck at : How to get article title and article url.
I am getting no output if tried to print below statement:
echo $article->title;
echo $article->id;
I have written this in php file, not used MVC architecture.
Is there any other settings need to do in Joomla admin side ?
Please suggest your pointers for extracting article title and article url.
Thanks in advance!
Pravin
In order to get the article ID you have to write the following:
echo JRequest::getVar('id');
For the title, you just take the id you got, load the article object
$blabla = $article->load(ID);
echo $blabla->get('title');
It seems JRequest is deprecated in 2.5 & 3.x as indicated in the Deprecated Elements list.
I would rather use the following:
$article_id = JFactory::getApplication()->input->get('id');
i tried :
public function onContentPrepare($context,&$article, &$params, $limitstart) {
echo JRequest::getVar('id');
}
Still I am not getting the id. Is this right?
The article is loaded in your second argument ($article). Being on this event (onContentPrepare), the only property you can access is $article->text.
For suiting your purpose (getting the article id and title) you will want to use another event, called "onContentBeforeDisplay".
public function onContentBeforeDisplay($context, &$article, &$params, $limitstart)
Here you have (again) the article passed through the second argument, but now you have access to properties like $article->id, $article->title and many others.
For future references on content events, take a look at the file "plugins\content\example\example.php"
You can use for getting active article title like this
$menu =& Jsite::getMenu(); echo $menu->getActive()->title;
may this help.
To get Joomla article id use this...
<?php echo JRequest::getVar('Itemid'); ?>
In the previous answer someone used id instead of Itemid. Hope this helps!

Page-specific logic in Joomla

I am trying to enable JavaScript in a Joomla template to behave differently depending on the page. In particular, I have set the Key Reference as that appears to be the most appropriate value I could find for this purpose. Unfortunately, I can't seem to access it in my code. I tried:
$this->params->get("keyref")
and a few other variations, but they simply returned a blank. How can I retrieve this value or is there a better way of writing page specific logic.
Related Articles
Joomla load script in a specific page: This would work, but seems like overkill for what I want to do here.
Each page can be given an alias. We can retrieve the alias using code from the forum:
function getCurrentAlias()
{
$menu = &JSite::getMenu();
$active = $menu->getActive();
return $active->alias;
}
We can then inject this into the Javascript:
var alias= '<?php echo getCurrentAlias(); ?>';
I'm not aware of keyref, but I would solve it by using the class suffix parameter you can set for each menu entry.see I would use a space in front of this suffix. With javascript you can then try to read this classname (suffix without the space) on each page.
getElementsByClassName("mysuffix");
for example
If this returns multiple objects, you know on which page you are. Will that help you?

Resources