CMS List pages except the 404 page - magento

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));

Related

Joomla template - is on homepage

I want to create a joomla 3.x template which shows a different UI on the homepage than on all the oder pages.
This works fine with the following code:
$app = JFactory::getApplication();
$menu = $app->getMenu();
$lang = JFactory::getLanguage();
$isHomePage = $menu->getActive() == $menu->getDefault($lang->getTag());
When I click on a menu item $isHomePage is "false" and I can show a different layout.
But when I open an article from the featured articles-list on my home-page, the menu item is still the home page but the user does see the article.
How do I get the information, if the user is really on the home page?
As per my understanding, the home page condition getting true on inside page is due to the fact that if an article does not have any menu it gets it from the current menu. So clicking on home page article link carries home page menu id.
There are some alternative that I can suggest -
1) Checking for URL - Check if current URL is equal to site page URL.
$uri = JUri::getInstance();
$currentUrl = trim($uri->toString(),'/');
$homeUrl = trim(JUri::root(),'/');
$isHomePage = $currentUrl == $homeUrl;
2) Check for homepage parameter with inner pages parameters. For example, if your homepage is of the article and having id X, check from request params check option and id param to com_content and id == X.
I hope this might be helpful.

Magento condition for specific page

In Magento I'm using <?php if ($this->getIsHomePage()):?> to check if it's the main page or not but how would I check if the user is on a custompage? CMS Page Url Key game-store
To get the URL key / identifier of any CMS page in Magento, use the following bit of code.
<?php
$yourUrlKey = 'game-store';
$cmsPageUrlKey = Mage::getSingleton('cms/page')->getIdentifier();
if($yourUrlKey == $cmsPageUrlKey){
//do something here
}
?>
The above code will print your URL Key
Either
$model = Mage::getModel('cms/page')->load('game-store','identifier');
var_dump($model->getData());
var_dump($model->getPageId());
or
$model = Mage::getModel('cms/page')->getCollection()
->addFieldTofilter('identifier','game-store')
->getFirstItem();
var_dump($model->getData());
var_dump($model->getPageId());
should do it.

Magento How to remove categories from product URLS on the sitemap?

I generated a sitemap on Magento's backend. However, the URLS to the product pages contains categories that we don't want.
Example URLS that are being generated that I don't want:
Domain.com / cateogry 1 / category 2 / product
The URL format that I want:
Domain.com / product
I turned off category paths on the backend:
System --> Configuration --> Catalog -- >Use Categories Path for Product URLs
but the sitemap is still showing categories.
Is there an option on the backend to remove categories from the xml sitemap? I would rather not have to change each URL manually because there are a lot of products.
Thanks in advance.
Quick and simple
magento/module-sitemap/Model/ResourceModel/Catalog/Product.php
Change This
$connection = $this->getConnection();
$urlsConfigCondition = '';
if ($this->isCategoryProductURLsConfig($storeId)) {
$urlsConfigCondition = 'NOT ';
}
To Anything really like:
$connection = $this->getConnection();
$urlsConfigCondition = '';
if (2 > 1) {
$urlsConfigCondition = 'NOT ';
}
For some reason It's just not picking up configuration even if set in backend
Magento 2.3.1 btw

how to make codeigniter routing to work with paging

I have the following routes for the news that works like a charm:
$word5 = urlencode('mygreek-keyword-here');
$route[$word5] = "news/displayAllNews";
and this page display all news with the desired keyword in the address bar. But...there is always a but...I have paging on this page, so when i click on next page link...page works but with old non-friendly seo url, that is:
news/displayAllNews/10/10
while I would like to have is: mygreek-keyword-here/10/10
code that i have in my controller for the paging is as follow:
$config['base_url'] = site_url('/news/displayAllNews/'.$limit.'/');
what should i do in routes.php and in my controller to get the desired result?
Regards, John
You could get the string of URI by $this->uri->uri_string() method, and set the pagination config as follows:
$config['base_url'] = site_url($this->uri->uri_string() .'/'. $limit.'/');
Note that the URI library is loaded automatically, it doesn't need to load it manually.
Update:
Change the route rule to:
$route["$word5(.*)"] = "news/displayAllNews$1";
If it doesn't work yet, remove the .'/'. $limit.'/' phrase and let the pagination to add the limit itself by:
$config['per_page'] = 10; // or $limit, default items per page.
$config['use_page_numbers'] = FALSE;

How can I get the CMS page id of a particular page in 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.

Resources