...

View Full Version : How can I insert a snippet into a link?



cineweekly.com
05-23-2011, 03:08 AM
I'm not sure how this would be done but I'm guessing PHP. I have a Google Custom Search bar on my site. I want to create links that automatically fill in the search query into the URL. For example:


<a href="www.example.com/results.html?blahblah=pokemon+cards">pokemon cards</a>

Blue is a consistent string of characters created by the Google Search.

Red is the search query that I want to automatically insert based on what's in pink.

djh101
05-23-2011, 03:22 AM
If you are searching Google (I know that Google also offers a site search feature separate from the typically seen Google search), the URLs displayed via a search are taken from Google's databases, so the only way to change the URL displayed for results would be to altar the returned results with Javascript after they are returned. Also, if you are using Google search, what, exactly, is the point in adding your own parameters to the URL?

cineweekly.com
05-23-2011, 03:28 AM
If you are searching Google (I know that Google also offers a site search feature separate from the typically seen Google search), the URLs displayed via a search are taken from Google's databases, so the only way to change the URL displayed for results would be to altar the returned results with Javascript after they are returned. Also, if you are using Google search, what, exactly, is the point in adding your own parameters to the URL?

I'm making a tag cloud / tag index HERE (http://www.cineweekly.com/friday/06-layer-cake-movie-review.html) towards the bottom in dark blue. Basically, I'm trying to find the best way to have these keywords link to the results page for their respective term. Is it really best to just do it one by one?

djh101
05-23-2011, 03:54 AM
Ah, well that's fairly simple. The URL comes up pretty long in a Google search, but what you should worry about is the 'q' parameter, which Google uses for your query. So, for each link, all you would have to do is make the URL that of your results page and set q to the pre-defined search query.

<a href="http://www.cineweekly.com/results.html?cx=partner-pub-3121530874756583%3Aytmhbk-rhu1&cof=FORID%3A11&ie=ISO-8859-1&q=search+test&sa=Search&siteurl=www.cineweekly.com%252Ffriday%252F06-layer-cake-movie-review.html">Search Test</a>

Is this what you're trying to do?

cineweekly.com
05-23-2011, 06:54 PM
Yes but what I'm wanting is some kind of code to insert it dynamically base on what's inside the anchor tag so I don't have to change the href parameter every time, just the content in the anchor tag.

Something like:

<a href="http://www.cineweekly.com/results.html?blahblahq={some coding language to insert id="queryA"}"><span id="queryA">pokemon cards</span></a>

djh101
05-23-2011, 08:46 PM
Ah. Well if you are changing the tag content directly (i.e. in the raw HTML), you would have to do this with Javascript, as HTML is client-side. If are setting the content, say, with a form and PHP, then the correct content can easily be inserted into both spots with PHP.

cineweekly.com
05-24-2011, 04:51 AM
Hmm, Javascript was my second guess. Could anyone help or a mod move this thread to Javascript?

djh101
05-24-2011, 06:57 AM
Javascript isn't really very reliable. If you're going to be writing the tag names directly into your code, you might as well do the URLs as well (it's not even really a whole lot more work).

kairog
05-24-2011, 10:41 AM
I think it can be done in PHP...

You can create a loop maybe through an array or getting data from a database.



// Option 1:
$keywords = array('word1','word2','word3');
foreach ($keywords as $key){
print '<a href="www.example.com/results.html?blahblah='.$key.'">'.$key.'</a>';
}


or if the keywords comes from database, you can do this in a while loop



// option 2:
while ($row = @mysql_fetch_object($queryresource)){
print '<a href="www.example.com/results.html?blahblah='.$row->keyword.'">'.$row->keyword.'</a>';
}


I hope this helps

cineweekly.com
05-24-2011, 11:47 PM
Javascript isn't really very reliable. If you're going to be writing the tag names directly into your code, you might as well do the URLs as well (it's not even really a whole lot more work).

Haha, you're the one that told me to use Javascript. I wanted the code because it would be easier to use the same anchor tags over and over because sometimes I'll have 100 new tags a week or less.

Thanks kairog I'll mess around with it.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum