php - Drupal6: Append query string to primary links -


I am trying to add a query string "? Device = mobile" to all the primary links programmatically .

In my topic page, the PPPPPP I have tried the following in the file,

  & lt ?? Php if (is_array ($ primary_links)):? & Gt; & Lt ;? Php foreach ($ $ link as the primary link):? & Gt; $ Link ['href'] = $ link ['href']. '? Device = mobile '; & Lt ;? Php endforeach; ? & Gt; & Lt ;? Php endif; ? & Gt;   

However this prints the code on the page only. Currently I'm trying to use hook_menu_link_alter, but I have not been successful so far to check my code on only one primary link item, I have tried the following code:

  myModule_menu_link_alter (and $ item, $ map) {$ items ['photo_gallery'] ['href'] = 'Photo_gallery? Device = mobile '; }   

Unfortunately there was no change in the link. I am going to check hook_menu_item_link () from my template.php file, but at this point I like it if someone can point me in the right direction, and tell me what I did wrong < P> Thank you.

The code you are putting in your page.tpl. The correct idea of ​​Php is, but you are missing two things:

  1. The foreign language body of the loop should be surrounded by the PH tag, so that the PHP code is explained And will execute. This is the reason that you think that Drupal only "prints the code": because you are excluding it from "generation", so it becomes part of the HTML of your template.
  2. Even if you execute the code correctly, you will not see any changes, because by default, in your foreach loop $ link The item in the array is a copy of the variable origin, doing so will not modify the $ link ['href'] = 'accessories' original. To modify the original, you can use the context syntax, such as: foreach ($ as primary_links & amp; $ link) . << Li>
  3. And finally, even though you fix the last two issues, it still will not work because the link of the link is going to be processed by theme ('link') later on, and your "?" And "=" is being encoded and it will break the link. Therefore, to fix those three issues, I would say that you see your page. To see the PLP code like:
       gt; 'mobile'); ? & Gt; & Lt ;? Php endforeach; ? & Gt; & Lt ;? Php endif; ? & Gt; Or, if you think that you have to open / close PHP on every line, then just use a normal block:  
        ; Php if (is_array ($ primary_links)) {foreach (and primary_link as $ link) {$ link ['query'] = array ('device' = & gt; 'mobile'); }}? & Gt;   

    Note 1. & amp; $ Link syntax (Use context instead of copy), and 2. Array key of query array, which in those "special" array keys Is the one that will search for Doppl, and if found, the last link is used to create the appropriate URL query (see the docs)

    In addition to this, the cache Remember to clean whenever you see "no change", especially when there are no topics Work.

Comments