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!
Related
I am trying to create a module which has both frontend and backend functionality. Like I need to ask for the city in the home page when the store loads. And all the available cities are entered/managed in backend admin panel.
Before I used to write for only backend things, frontend seems little confusing.
There is a design folder which is completely for theme development.
All the example are little different(https://www.mageplaza.com/magento-2-module-development/,http://inchoo.net/magento-2/how-to-create-a-basic-module-in-magento-2/]2), they have routes.xml, where route_id, and all are defined, but here I don't need any extra route. Need some additional tweaks in frontend pages.
I created module V_name/M_name/adminhtml/block controllers etc view ...
Guide me how to create a module, which has both front end and backend connection, cities should be entered in admin, they should show on the frontend homepage.
For now, I only managed to edit home page content CMS page by adding some HTML which shows a popup with a dropdown for cities when the page loads.
Since you already have the back-end figured out I will focus on front-end. Also, since all you need to do is populate a list that you already have created this should be easy. I did something like this before and I found it easier to just use JSON to query a list of, in your case the cities, and populate the drop down. I don't believe this is the most 'MVP/proper' way to go, but it is less work then the other ways. (At least for me it is. I always prefer the JavaScript option since it allows for easy future page customization.)
To use the JSON method you need to create a Block with a method like the one below. You will see that you will also have to create a Resource Model (I'm not going to go over creating the Resource Model or the details of Blocks since there are much better resources than me already online that will go into every single detail you need.). Once this is complete you can access the data straight from the .phtml page in an easy to use JSON array.
First you need to make sure you are now structuring your Modules properly. The new Block below should be in a structure like this...
app/code/<VENDOR>/<MODULE>/Block/Wrapper.php (or whatever you name it)
The admin Blocks should be in the structure below, which it sounds like you are already know how to do.
app/code/<VENDOR>/<MODULE>/Block/Adminhtml
Create your Block and add a method to create a JOSN array like below...
public function getCityList()
{
$city_array = array();
/** #var \<VENDOR>\<MODULE>\Model\ResourceModel\City\Collection $collection */
$collection = $this->_cityCollectionFactory->create();
$collection->addFieldToFilter('active','1')->addFieldToSelect(['city_id', 'city']);
$collection->getSelect()->order(array('city ASC', 'city_id ASC'));
$count = 0;
foreach ($collection as $model)
{
$city_array["$count"] = $model->getData();
$count++;
}
return \Zend_Json::encode($city_array);
}
FYI... The foreach loop in the code above is weird and uses $count because I needed to do some tricky things to get something to work.
Then you can create the Block in your .phtml file to access the data via javascript.
<?php
$block_obj = $block->getLayout()->createBlock('<VENDOR>\<MODULE>\Block\Wrapper');
?>
<script type="text/javascript">
window.citylistJson = <?php echo $block_obj->getCityList() ?>;
</script>
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.
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.
Whats the easiest way to enable my page title to update per content div areas it's on?
I have a vertical scrolling website and would like the page title to change when the user navs to each content area (The content areas are within div & article)
Essentially, I'm trying to keep 'Orginal Site Title | + Home/About etc'
I'm thinking it's something I'd have to call with php to remember a set title attribute per div link? Any suggestions on setting this up (If possible)
I think you should take a look at the Viewport plugin. This way you have 4 selectors you can use:
$(":in-viewport")
$(":below-the-fold")
$(":above-the-top")
$(":left-of-screen")
$(":right-of-screen")
Now you could do something like this:
//Get the id of element(div) that is currently in view
var inview = $('div:in-viewport:first').attr('id');
//Define titles
if (inview == 'home'){
var newtitle = 'Home'
} else if (inview == 'about') {
var newtitle = 'About us'
}
//Lets rename the page title
document.title = 'Orginal Site Title |' + newtitle;
The above code should now always be called when you scroll ($(window).scroll(function () { ... });) to update page title according to the div that is currently in view.
This is just a generic example and it can be completely changed to your needs. I hope it helps in some way.
You might be able to do this by writing a plugin based on the scrollspy plugin that comes as part of twitter bootstrap: http://twitter.github.com/bootstrap/javascript.html#scrollspy
You could tweak it so rather than setting a class on the target it updates the title with whatever the content is in the current viewable panel
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