Different urls generated with JRoute::_() in different pages - Joomla! 3 - php

I developed a component in Joomla! 3, and I used JRoute::_() & router.php to make urls search-engine-friendly. something like this :
/component/products/WIFI-IP-Phone/list-3
So I decided to replace /component/products with a clean alias, And I created a menu with a clean alias to the component home page. now, all the link I have inside the component ( generated with JRoute::_() ) are like this : /escene/WIFI-IP-Phone/list-3 and its perfect, its exactly what I want, But ... I'm using JRoute::_() in three different modules, and I generate links with that, the problem is that generated links in these modules when I'm in the home page or any other page except the component pages, are different with the generated links in these module when I'm in the component pages.
When I'm in the home page or other : /component/products/WIFI-IP-Phone/list-3
When I'm in my component pages : /escene/WIFI-IP-Phone/list-3
Any body can explain the reason Or help me to make all urls like /escene/WIFI-IP-Phone/list-3 ??

This is because the functions you write in components router.php get executed for the links when the page displaying is of the same component. But there is a way to accomplish this task.
1. First create a new menu in the menu manager and create all links in this menu.
2. Publish this menu but do not assign any position.
3. In this way you would get a sef url for each link.
if(JFactory::getConfig()->get('sef')) {
echo 'My sef url';
} else {
echo 'Dynamic url';
}
In this way Joomla will do your url parsing by detecting your component through the alias stored.
Let me know if you have any further query.

Related

Moving a block (view) into a different region programmatically (Drupal 7)

I use the Commerce Kickstart Distribution of Drupal 7. I want to have the searchbar assigned to a different region on the frontpage than on all other sites in my theme. I used the approach shown here: http://saw.tl/drupal/programmatically-manage-drupal-blocks.html
function mytheme_hook_block_info_alter(&$blocks, $theme, $code_blocks)
{
if(drupal_is_front_page()) {
$blocks['views]['-exp-display_products-page']['region'] = "branding";
}
}
This is the function in my template.php. I know that the search bar is created using the views module and is not a "default block".
The name shown in the Block menu for the search bar is Exposed form: display_products-page, the module name and machine name I choosed following this tutorial http://drupalchamp.org/node/166
However, it does not work at all. I do not get any errors or warnings, the block just stays in is default region when I load the front page.
You can use Context module to add blocks to different regions depending on some criteria:
https://www.drupal.org/project/context
Very powerful and easy to use module so I'm advising it.
And if you prefer doing it form code you could grab block's content and print it from template directly, depending on detected page. Something like:
$block = module_invoke('views', 'block_view', 'block_machine_name');
print render($block);
Of course you would execute it conditionally...

wordpress link home page to different page

I have created html pages and trying to convert into wordpress theme,how to link html one page to other page in wordpress menu bar
sample code :
Features
this code is not working,it 's showing page not found.how to make this link in wordpress using php code.
Firstly Create Page "Features" from wp-admin.
Create template for this page.
http://codex.wordpress.org/Stepping_into_Templates
To set this page in menu Go in "Menu" section in WordPress.
http://codex.wordpress.org/Appearance_Menus_Screen
To view this menu in fronted use wp_nav_menu()
Take example template from your theme.
This is file in theme ending with -page.
Change template name in head of a file.
Then remember about the_loop all should be inside a loop to work correctly with many pages.
Put html there, also in header.php attach css to this html.
Page structure is like, header in the up, then page and then footer.
Remember to preserve good html structure - divs beginning and ending.
Then you create a page with content ( which is presented in the_loop ) , which has its own url address.
You can set url naming of pages in settings -> permalinks, you may need to write to .htaccess file.
Then you have direct url to page. You can use it in code like this:
echo bloginfo('url'). 'nameofpage';
All to do is create a template and assign it to page ( on page edit page template option ).
You can use pages or posts for this, i prefer pages.
Create new pages or posts and get their ID.
For linking its:
Get link with this:
get_permalink( $yourPostOrPageID ); // only get; not echo
Otherwise
Wordpress homepage link:
get_bloginfo('home');
Category or custom taxonomy term link:
get_term_link( $term, $taxonomy );

session variable that records an onclick element

Lets say i have 5 pages which has some hierarchy and all pages are in same folder. When i click on one page its going to another page in same folder.
Example
fruits.php is main page and banana.php, apple.php, orange.php & pineapple.php. All the later 4 has links in main page. I need to display navigation in all the pages like if its main page just main page. If its a banana i should display as Main_Page>>Fruits>>Banana ans so on how can i achieve if i have n number of hierarchies lets say flowers(lily.php, rose.php), Eatables(chocolates.php, biscuits.php) etc and all pages in same folder.
make folders foreach category and have them in the main folder:
main/flowers
main/fruits
...
include php files in respective folders:
main/flowers/lily.php
main/fruits/apple.php
...
now use javascript to read the url of the current page:
var url = window.location;
var cat = url.split("/");
cat[cat.length - 1] = cat[cat.length - 1].split(".")[0]; // to remove ".php" part from "lily.php" and get "lily" to display
now you have those names in cat array, so you can display them in html as you need:
alert(cat[1]+"/"+cat[2]); // should popup something like fruits/Apple
First, what you are trying to make is called "breadcrumb". If you google it in this words you'll have too many hits.
There are too many ways to achieve this according to your site scheme. If you have a collection of your pages in your DB you can find the hierarchy of pages to show in breadcrumb by querying the DB. If you don't have this, I can advise you to make a folder hierarchy as:
Main
|--fruits.php
|--flowers.php
|--Fruits
|--apples.php
|--bananas.php
|--Flowers
|--lily.php
|--rose.php
Then on each page you can show your folder hierarchy as breadcrumb. This may be an easy way to start.

Accessing $_SESSION from outside of Joomla

I used Joomla 1.5 for a site that I developed for a gaming company. Part of the site consists of a character generater for the game that they developed. The issue is that users want to be able to print the character sheets off, without having the Joomla template surrounding it.
As for the specifics, I have the directphp extension installed, and the entire generator is written in PHP (with a little JavaScript to handle things that PHP can't). As the generator spans several dozen page calls, it made sense to store everything in $_SESSION. All of this works correctly. In an attempt to make the final sheet printer friendly, I tried redirecting the user to a page outside of Joomla (though on the same server, and even within the same folder) but I cannot access the $_SESSION data from this new page.
I have seen several posts (a few on this site) that point to loading the Joomla Framework and accessing it that way, which I have tried, but the data that I was looking for does not appear to be contained there. Has anyone come across this problem before, or know how to get to that data?
You are making this WAY harder than it needs to be. You don't have to write any additional code to accomplish what you are trying to do. In order to print our the component output without all of the Joomla template, you just append ?tmpl=component to your URLs and Joomla will display only to component output without any of the template. If you want to give it a custom stylesheet or anything special, you can also add in a template override by adding a file named component.php in your template folder.
In order to control the CSS per page, you can add Page Class Suffixes in the menu items. Then add this code to index.php so you can use them.
Somewhere in the head add this:
$menu = &JSite::getMenu();
$active = $menu->getActive();
$pageclass = "";
if (is_object( $active )) :
$params = new JParameter( $active->params );
$pageclass = trim($params->get( 'pageclass_sfx' ));
endif;
Replace your body tag with this:
<body id="<?php echo $pageclass ? $pageclass : 'default'; ?>">
Any page that you do not specific a Page Class Suffix for will use default as the body ID, any that you do will use what ever you specify.

how to generate url friendly in Joomla?

I have a problem with joomla 1.5 friendly url (that not so friendly actually)
I am not using SEF at the moment (should i ?)
heres is my problem
I have some categories and sections. Each has alias.
so i can check all news category for example by visiting www.myxyz.com/news/
to check an article the url that generated would become:
www.myxyz.com/news/10-local-news-title-alias
I have no idea how joomla generate that url. In my templates i need to generate some links to specific articles.
so I create a helper in template:
// helper to get alias in mainMenu ... alias must be unique
function getMainMenu($menuAlias){
$items = &JSite::getMenu();
// Get Menu Items
$rows = $items->getItems('alias', $menuAlias);
if($rows){
//$result = JRoute::_(JURI::base().$rows[0]->link);
$result= JURI::base().substr(JRoute::_($rows[0]->link), strlen(JURI::base(true)) + 1);
return $result;
}else{
return JURI::base() ;// aka not found
}
}
but when I enter the page like www.myabc.com/news/7-local-news-alias
the url would become messed up and changed to wrong url.
should I use SEF for joomla url friendly ?
You should just work with normal url's in your code. when you turn on SEF joomla! will automaticly convert all links you create to SEF urls and when a request comes in it will revert them back to regular url's for you...
It's a little convoluted, but the proper way to link to SEF URLs is to use the original, non-SEF link. You will need:
The ID of the article
The Itemid of the menu item for your section (e.g. the menu item linking to Article Blog layout, etc)
Then you just link to:
index.php?option=com_content&view=article&id=42&Itemid=3
Where 42 is the article ID and 3 is the menu ID.Your link will then look something like:
/section-alias/42-the-article-alias
If you miss off the Itemid your link will look like this (I think):
/components/content/42-the-article-alias

Categories