Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    Regular Coder cineweekly.com's Avatar
    Join Date
    Aug 2010
    Posts
    485
    Thanks
    14
    Thanked 3 Times in 3 Posts

    How can I insert a snippet into a link?

    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:

    Code:
    <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.
    Last edited by cineweekly.com; 05-23-2011 at 03:11 AM.

  • #2
    Regular Coder djh101's Avatar
    Join Date
    May 2009
    Location
    California
    Posts
    626
    Thanks
    51
    Thanked 67 Times in 67 Posts
    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?
    "Yeah science!"

  • #3
    Regular Coder cineweekly.com's Avatar
    Join Date
    Aug 2010
    Posts
    485
    Thanks
    14
    Thanked 3 Times in 3 Posts
    Quote Originally Posted by djh101 View Post
    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 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?

  • #4
    Regular Coder djh101's Avatar
    Join Date
    May 2009
    Location
    California
    Posts
    626
    Thanks
    51
    Thanked 67 Times in 67 Posts
    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?
    "Yeah science!"

  • #5
    Regular Coder cineweekly.com's Avatar
    Join Date
    Aug 2010
    Posts
    485
    Thanks
    14
    Thanked 3 Times in 3 Posts
    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:
    Code:
    <a href="http://www.cineweekly.com/results.html?blahblahq={some coding language to insert id="queryA"}"><span id="queryA">pokemon cards</span></a>

  • #6
    Regular Coder djh101's Avatar
    Join Date
    May 2009
    Location
    California
    Posts
    626
    Thanks
    51
    Thanked 67 Times in 67 Posts
    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.
    "Yeah science!"

  • #7
    Regular Coder cineweekly.com's Avatar
    Join Date
    Aug 2010
    Posts
    485
    Thanks
    14
    Thanked 3 Times in 3 Posts
    Hmm, Javascript was my second guess. Could anyone help or a mod move this thread to Javascript?

  • #8
    Regular Coder djh101's Avatar
    Join Date
    May 2009
    Location
    California
    Posts
    626
    Thanks
    51
    Thanked 67 Times in 67 Posts
    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).
    "Yeah science!"

  • #9
    New Coder
    Join Date
    Dec 2007
    Posts
    68
    Thanks
    25
    Thanked 2 Times in 2 Posts
    I think it can be done in PHP...

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

    Code:
    // 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

    Code:
    // 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

  • #10
    Regular Coder cineweekly.com's Avatar
    Join Date
    Aug 2010
    Posts
    485
    Thanks
    14
    Thanked 3 Times in 3 Posts
    Quote Originally Posted by djh101 View Post
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •