How can I get the CMS page id of a particular page in Magento - magento

In magento by using this code:
$currentPageId =$this->getRequest()->getParam('page_id');
we can get the current page id.
But how can I get the page id of a particular page?
For example, I have a page with URL key about-fruit-store.
I want to get its page id. How can I get it?

Either
$model = Mage::getModel('cms/page')->load('about-fruit-store','identifier');
var_dump($model->getData());
var_dump($model->getPageId());
or
$model = Mage::getModel('cms/page')->getCollection()
->addFieldTofilter('identifier','about-fruit-store')
->getFirstItem();
var_dump($model->getData());
var_dump($model->getPageId());
should do it.

Related

Codeigniter custom URL structure

I want Url in my codeigniter app like this,
in Home www.domain.com/ -> i route the $config defaut_controller to category
in page 2, www.domain.com/category/[category_name]/ -> in here (page 2) i create pagination.
in page 3, www.domain.com/category/[categori_name]/[sub_category1_name] ->in here i create pagination too.
and then, in page 4 i want www.domain.com/category/[categori_name]/[sub_category1_name]/[sub_category2_name].
In my database, I have table category, sub_category1, sub_category2. and string url in every table.
I was try using _remap($method, $params = array()) function, but i can't do it.
Can anybody give me approch to do this? or reference similar web structure.
You can use routes for this.
In application/config/config.php:
For page 1:
$route['default_controller'] = 'category';
For page 2:
$route["category/(:any)"] = "category/index/$1";
For page 3:
$route["category/(:any)/(:any)"] = "category/index/$1/$2";
For page 4:
$route["category/(:any)/(:any)/(:any)"] = "category/index/$1/$2/$3";
Side note:
If you still facing the issue than create seperate function in category controller for sub_category and change index to function name in controller.

CMS List pages except the 404 page

On my magento website, I can display a list of all my CMS Pages with this method :
Mage::getModel('cms/page')->getCollection()
But now I'd like to hide the 404 page in my list for example. How to do that ?
Thanks
By default the 404 cms page has the identifier no-route. You can get the collection like this:
$pages = Mage::getModel('cms/page')->getCollection()
->addFieldToFilter('identifier', array('neq'=>'no-route'));
But Magento offers the possibility to make any page the 404 page. So the cleaner approach would be to get the real 404 page identifier first.
$_errPage = Mage::getStoreConfig('web/default/cms_no_route');
$parts = explode('|', $_errPage);
$identifier = $parts[0];
$pages = Mage::getModel('cms/page')->getCollection()
->addFieldToFilter('identifier', array('neq'=>$identifier));
I also recommend adding a store filter so you get only the pages enabled on the current store:
$pages = Mage::getModel('cms/page')->getCollection()
->addStoreFilter(Mage::app()->getStore()->getId())
->addFieldToFilter('identifier', array('neq'=>$identifier));

How To Get Current Page Parameters And Properties of Joomla 3.1

I want to create a module for joomla 3.1 for my own site. I need to know how to get current category id, parent category id, current page id. Please some one tell me how to do that. Thanks for your advance
going from memory here, please bear with some inaccuracies but it should be enough to get you going.
$input = JFactory::getApplication()->input;
// should be article, categories, featured, blog...
$view = $input->get('view');
// if it's a category view, this will be the category id, else the article id
$id = $input->getInt('id');
// in an article view, this will be the cat id.
$catid = $input->getInt('catid');
// this is the menu item id i.e. what you call page id I guess.
$Itemid = $input->getInt('Itemid');

How can I get current category id of Virtue Mart

I want to change the default Featured Products module of Virtue Mart. I would like to this module show just the current category's featured product. So I need to get the current category id.
How can I get it?
Thanks!
JRequest::getInt(category_id);
$input = JFactory::getApplication()->input;
// should be article, categories, featured, blog...
$view = $input->get('view');
// if it's a category view, this will be the category id, else the article id
$id = $input->getInt('id');
// in an article view, this will be the cat id.
$catid = $input->getInt('catid');
// this is the menu item id i.e. what you call page id I guess.
$Itemid = $input->getInt('Itemid');
I hope this will help you.. :)

Magento CMS pages — getting title from URL key/identifier?

Is there any way to get the title of a cms page, if you only know it's url key/identifier? For example, the about page (in the sample data) has a url key/identifier of 'about-magento-demo-store'. If that's the only information I had, how would I go about getting the page title from that? As in the faux code below:
$pageTitle = Mage::getModel('cms/page')->loadByAttribute('identifier', 'about-magento-demo-store')->getTitle();
I'd like to get a list of all CMS page titles, using just the url keys/identifiers.
I know you can get the current CMS page title using the following:
$pageTitle = Mage::getSingleton('cms/page')->getTitle();
Anyone any ideas?
OK, figured it out myself using trial and error:
$pageTitle = Mage::getModel('cms/page')->load('about-magento-demo-store', 'identifier')->getTitle();
I made this solution to get URL-Key (Identifier) of a page:
<?php $pageTitle = Mage::getSingleton('cms/page')->getIdentifier(); ?>
<?php if ($pageTitle=='home'):?>

Resources