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.
Related
I have a question regarding e-commerce websites. Lets assume there is an e-commerce website that sells products for women, men, kids. For each of these categories it sells clothes, shoes ---etc. When a user clicks on women or men or whatever category, the user should be directed to a page showing the list of products corresponding to that category. Lets assume that the website have the same layout. For example the navbars, the squares where products will be displayed are the same. the only difference is the content it self. My question does large e-commerce websites have a separate html file for each product or they have some a template html file where the design and layout is fixed and based on link clicked the content of html is changed. Having a separate html file would be very cumbersome. If having a template html file is the case, how does the name of the link in browser change when different products are clicked is it related to .htaccess.
Thanks.
Yes .htaccess is important in this case. Try to learn how to parse url, and make some simple MVC applications.
There are many methods to doing this. The main answer to your question is that you need to parse the url. I'll go over a couple here.
1) PHP looks like it would be the easiest solution if you're connecting to a mysql database with products. You can create a php file with the categories as parameters, so each link could look like products.php?category=shoes
Then you can parse that url with $_GET in your code.
$category = $_GET['category'];
Then, in your php file, you can display specific content based on the category like so:
if ($_GET['category'] = 'shoes'){
//then enter your logic here
}
elseif ($_GET['category'] = 'books'){
//then enter your logic here
}
Here's some more info on the PHP GET: http://w3schools.sinsixx.com/php/php_get.asp.htm
You can do this via javascript by parsing the href
function getParameterByName(name, url) {
if (!url) url = window.location.href;
name = name.replace(/[\[\]]/g, "\\$&");
var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, " "));
}
var dynamicContent = getParameterByName('dc');
and then writing the logic to correctly create elements that fit your requirements through javascript.
More details: http://jennamolby.com/how-to-display-dynamic-content-on-a-page-using-url-parameters/
This should help you move forward to understanding how to achieve your concept hopefully!
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.
I have a website with the following setup:
overview.php
hotel1.php
hotel2.php
hotel3.php
Where overview has a sidebar with links to hotels 1, 2 and 3 and each hotel page has a sidebar with links to the other two hotels (excluding itself) along with the overview page.
At the minute, I am hard coding the sidebar in each php page, as they are all slightly different.
I am wondering if there is a way I can code one sidebar in a separate file (sidebar.php) with links to each of the four pages and add the sidebar with a php include() function.
Then, depending on the page (which will have an identifier), show all the links, except the link to itself.
Problem is, I'm not sure how to do it, or if it can be done.
The site is php and html (with css and javascript).
And if it is relevant, I have about 100 folders containing an overview and then multiple hotels which I would like to implement this on.
The easiest way to do it is to wrap your sidebar code in a function.
sidebar.php
<?php
function print_all_sidebar_links_except_self($self = NULL){
$hotels_text = array(
"hotel1" => "Gryffindor Tower",
"hotel2" => "Ravenclaw Tower",
"hotel3" => "Slytherin Dungeons"
);
if (isset($self)){
unset($hotels_text[$self]);
}
foreach ($hotels_text as $page => $name){
echo "<a href='".$page.".php'>".$name."</a>";
}
}
?>
overview.php: print_all_sidebar_links_except_self();
hotel1.php: print_all_sidebar_links_except_self('hotel1');
hotel2.php: print_all_sidebar_links_except_self('hotel2');
hotel3.php: print_all_sidebar_links_except_self('hotel3');
I'm just starting out using the ProcessWire system and really enjoying it.
On my Home Page, I would like to display an image from a random page. The page can be ANY page as long as the it is the child of the parent page with ID '1010'.
Is it possible, and if so, how do I achieve this?
My current code for showing the home page image is this:
if($page->image) echo "<img src='{$page->image->url}'>"; however, I'd like to select a random image from any of the children pages of the above parent ID.
I found this, but wasn't sure whether it would be of any use.
Many thanks for any pointers :-)
You should try something like this in your template's code (assuming that your image field is called image):
/* Find all children of page with ID 1010 that include an image */
$allChildPages = $pages->find('parent=1010,image.count>0');
/* Select a page from all children in the PageArray randomly */
$randomChildPage = $allChildPages->getRandom();
if ($randomChildPage->image) {
echo "<img src='{$randomChildPage->image->url}'>";
}
Have a look at the relevant code:
$pages->find() returns a collection of Pages (matching the Selector) as a PageArray (that extends the WireArray class).
$anyWireArray->getRandom() returns a random element of itself.
Also have a look at this forum thread where several strategies to randomize images from different pages are discussed.
I have the following problem:
I use taxonomys (tx) as tags. They can be added when the node is created. So I don't know how many tx I have or what ID they have.
The path of the tx is like the following:
/foo/element1
/foo/element2
/foo/element3
...
The secound element is the tx.
Now I want to use a view (page) to handle the tx-path:
/foo/%
The problem is, when I open a path like the one on top I see the theme of the node-taxonomy.tpl.php but not the style I set in the view.
Whenever I open a path in the form (/foo/not-a-tx) I can see the output of the view.
Could someone give me a hint how to get out the view output but not the tx-output?
Thanks
Sebastian
I solved the problem with this way:
I use a view block (not a page)
I added a new output area in my ,info file
I use this way to show only the vocab
I show the block in the new area online bei foo/*
It works Okay for me.
Thx to every one.
Do you want to get rid of the taxonomy pages completely?
If so, you can use a hook_menu_alter() and unset the taxonomy page.
EX.
hook_menu_alter(&$items) {
unset($items['taxonomy/term/%taxonomy_term']);
}
You'd have to look at the $items array to pinpoint the name of the registered menu path, but I think this is it.
This will remove the taxonomy page for all vocabularies however.
Actually you need to make a view to override the internal drupal path of the taxonomy term page: taxonomy/term/% (where % is the taxonomy id) and not the aliased path, which in your case is foo/%
[Optional but saves work: There is already an example view that is bundled with Drupal that implements the taxonomy view. Go to Views > List and you will see the the view is greyed out and it is called
Default Node view: taxonomy_term (default)
All you need to do is enable it and modify it to your needs]
Don't worry about the aliases. You can define your URL pattern at /admin/build/path/pathauto (make sure pathauto module is enabled. You can download it at http://drupal.org/project/pathauto ). In your case the pattern would be foo/[cat] where [cat] is a token for category. Make sure you enter this pattern under Taxonomy Term paths in the pathauto automated alias settings.