Jump to content

Variable links?


SpyJoe

Recommended Posts

Hello, could anyone please help me with the code on how to make a link to another page based on a specific name?

 

I have a page for every name. That name is an attribute and also stored in a database. I want my visitors to be directed to that specific page of a name that is shown on the page that they came from. Because I have so many pages it will take ages to do manually, so I'm using a template and therefore can't link every page manually.

 

I hope I explained clearly. Please ask if you are not sure what I mean. I will be very grateful if someone could help me.

 

Thank you in advance.

Link to comment
Share on other sites

can you post your code please? (an example of this:)

I want my visitors to be directed to that specific page of a name that is shown on the page that they came from

 

How is that name shown? is it a href link? (is the name in the url?)

 

 

Link to comment
Share on other sites

That's the thing. I don't have a code. I don't know much about PHP, but I'm trying.

 

I will try to be more specific, sorry.

 

The name is a brand name that is a href LINK to a page that contains all products for that brand. Which is also an attribute and saved in database, as everything is linked together.

 

Below that link is another link. And I want visitors to be redirected to a specific page for that brand name that is  shown above, when they click it.

 

Hope this helps.

Link to comment
Share on other sites

simple solution would be something like: (create dynamic links from database with the page names or ids)

 

<a href="redirector.php?pageName=page1">page1</a>

 

and use a little redirector file to check if the page exists before redirecting that will send them back if the page does not exist.

 

 

But there are loads of security issues with something like this, because it will allow virtually anyone to write pagenames in the url to open up stuff they shouldn't have access to. either you put all the pages in a specific folder, and only allow them to see pages contained within that folder, or you need to set up a permissions system based on each user (I'm assuming they have to login, might not be the case).

Link to comment
Share on other sites

:wtf: Im not sure at all what you are trying to do. And if you don't have a single line of code where to start from. Maybe you start learning from the basics? Or post to freelanceer forums, if you want someone to do something for you.

 

Link to comment
Share on other sites

I thought this was a simple question. I have done PHP before, but this was years ago, so can't remember much.

 

Thank you, WebStyles, but I don't think that's what I wanted. All I want is for href link to fetch the brandname of the page and direct the visitor to a page for that specific brand that it fetched. I'm sorry if I'm not explaining properly, I don't know how to make it more clear.

 

Visitors can browse pages when they are logged in and out. Security shouldn't be affected by this I think.

Link to comment
Share on other sites

I really don't know how to explain it more clear. I wouldn't even know where to start with the code. I searched everywhere for something similar, but so far can't find anything. Maybe someone can understand what I mean and post an example. Thank you all for your time.

Link to comment
Share on other sites

Yes, that is correct. I know that they all are stored in a database, but not sure how they are retrieved. Everything is done automatically by Magento, but I'm trying to customise it a bit.

 

I'm not sure if I'm allowed to post links to other websites here, but couldn't find it in the rules. Here is a page of the website:

 

http://www.legendfootwear.co.uk/hunter-original-black-womens-boots-69786.html

 

Do you see where it says: Brand: Hunter ? (Below the price)

And then a bit below it says "Size Guide"

 

Well I want visitors to be directed to a size chart for Hunter from that page. At the moment they are directed to a page which contains all brands' size charts.

 

Because that is a template, I need it all to be done automatically. I hope it is clear what I want to do now.

Link to comment
Share on other sites

that's pretty easy. All you need to do is grab the brandname then... but if you don't know where it is stored, how are we supposed to know? you need to look at your database, find the name of the table and the field you need (or look at your code in that page, chances are it's already being retrieved) and just add it to the link in the form ?brandname=whteverBrandNameIs,

 

then on your sizes page, just grab the variable, and display only relevant content.

 

 

Link to comment
Share on other sites

I've just tried for the last 20 minutes, but can't figure out what code to put.

 

Here is what I have so far:

 

The following code grabs the brand name.

 

$brand = $_product->getResource()->getAttribute('brandname')->getFrontend()->getValue($_product);

 

And here is the link. I don't know what to put here. At the moment the text of the link grabs the brand name and displays it. But the link is to a page where all brands are, no just that one brand.

 

<a href="<?php echo sizeguide.php ?>"><?php echo $brand; ?> Size Guide</a>

 

But how do I direct visitors to a page for that specific brand? Please help me out with the code. How do I grab the variable and display only relevant content?

Link to comment
Share on other sites

change this:

<a href="<?php echo sizeguide.php ?>"><?php echo $brand; ?> Size Guide</a>

 

for this:

<a href="sizeguide.php?brand=<?php echo $brand; ?>">Size Guide</a>

 

then in sizeguide.php grab $_GET['brand'] and create a simple switch() or if() to show only relevant content.

Link to comment
Share on other sites

I'm sorry to be a pain, but how will the if statement work? If brand matches the brand, then display it, if not, don't? That means I have to create if statement for every brand? We have about 40, is that correct?

Link to comment
Share on other sites

You need access to your mysql table as WebStyles said. If you have it, you can do something along the lines of:

 

if(isset($_GET['brand']))
  {
    $brand = mysql_real_escape_string(htmlentities($_GET['brand']));
    $brand_query = mysql_query("SELECT what_you_need FROM which_table WHERE brand = '$brand'")
    //then print the data relevant to that specific query which will be specific to the brand the is in the GET
  }

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.