Page 1 of 1
[solved] Create link to specific (single) information page
Posted: Sun Apr 17, 2011 5:39 am
by djeeke
Hi all,
I have succesfully moved the links to the information pages to my footer...
I need some help in understanding PHP arrays... I guess the answer is easy for someone with PHP knowledge...
My footer now has this
Code: Select all
<?php foreach ($informations as $information) { ?>
<a href="<?php echo str_replace('&', '&', $information['href']); ?>"><?php echo $information['title']; ?></a>
<?php } ?>
Obviously with the PHP foreach this shows the links to all my information pages...
But I just want Privacy, Policy & Terms in my footer...
And I would like to create separate links in my header.tpl to some other information pages...
I need the links to be built with the php code as my site is multilingual...
How do I proceed to select specific items out of the array (so not foreach...) ?
Tia !
Djeeke
Re: Create link to specific (or single) information page
Posted: Sun Apr 17, 2011 11:21 pm
by JAY6390
Just add them manually
Code: Select all
<a href="<?php echo HTTP_SERVER . 'index.php?route=information/information&information_id=3'; ?>">URL TITLE HERE</a>
Be sure to replace the information_id with the correct number, instead of 3
Re: Create link to specific (or single) information page
Posted: Mon Apr 18, 2011 2:04 am
by djeeke
Thanks Jay,
That's how I would have done it if my site was in a single language
But can you tell me how I can get the 'URL TITLE' in the language the page is displaying
Tia,
Djeeke
Re: Create link to specific (or single) information page
Posted: Mon Apr 18, 2011 6:16 am
by JAY6390
Code: Select all
<?php foreach ($informations as $information) {
if(in_array($information['information_id'], array(1,2,3,4)) {
?>
<a href="<?php echo str_replace('&', '&', $information['href']); ?>"><?php echo $information['title']; ?></a>
<?php
}
} ?>
Something like that should work, just replace 1,2,3,4 with a comma separated list of information id's you want to show
Re: Create link to specific (or single) information page
Posted: Mon Apr 18, 2011 10:25 pm
by djeeke
Thanks Jay, I tried this but I get
Undefined index: information_id
This is where I got stuck in the first place...
Since the code works with the foreach statement I guess there is an index defined...
I now just have to try and figure out what it is...

Re: Create link to specific (or single) information page
Posted: Mon Apr 18, 2011 10:29 pm
by JAY6390
The numbers you put in the array are the actual information id's
If you click edit next to the page(s) you want linked to, and then look in the address bar you will see a long url and near the end you will see "&information_id=XXX" where XXX is a number. This is the ID of that information article and is unique.
Re: Create link to specific (or single) information page
Posted: Tue Apr 19, 2011 12:31 am
by djeeke
Yes Jay, I know that, but how do I code them ?
I'm working on something, will post later on...
Problem with the about page is that this one has an seo link...
Will keep this thread updated ... I'm not a programmer so it takes time ;-)
And I suppose there will be a better solution but I'm already happy if I can get it working ;-)

Re: Create link to specific (or single) information page
Posted: Tue Apr 19, 2011 12:36 am
by JAY6390
I'm confused now. I posted the code above you would need (with the filtering by id) and all you need to do is replace 1,2,3,4 with the id's you want instead
Re: Create link to specific (or single) information page
Posted: Tue Apr 19, 2011 1:54 am
by djeeke
Sorry I confused you Jay...
When I tried your code, I got an error message...
This is why I posted I get 'Undefined index: information_id' as message...
Since it seems I can not use this 'information_id' I am now trying to extract the id from the 'information['href']' variable as it is included in that string and see if I can use this in the 'if' statement... (I got to the point of extracting the value with some string statements, now looking at the if statement)
Thanks for the help, I will update as soon as I get some working code..
Re: Create link to specific (or single) information page
Posted: Tue Apr 19, 2011 1:59 am
by JAY6390
I see. Sorry I assumed that the code had the info id in it too. If you open your controller file for the footer where you added the information code, I'm guessing you have something similar to this
Code: Select all
$this->data['informations'][] = array(
'title' => $result['title'],
'href' => $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=information/information&information_id=' . $result['information_id'])
);
below the title line add in
Code: Select all
'information_id' => $result['information_id'],
so it looks like this
Code: Select all
$this->data['informations'][] = array(
'title' => $result['title'],
'information_id' => $result['information_id'],
'href' => $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=information/information&information_id=' . $result['information_id'])
);
That will actually add in the information_id into the array to give you better control
Re: Create link to specific (or single) information page
Posted: Tue Apr 19, 2011 2:24 am
by djeeke
Thanks Jay !!!!
(Honestly I assumed the info_id was there as well, I just did not know how to access it...)
So now I now I need to add it into the controller file, once done your code works as a charm !
Thanks for the time spent to help me out !
Much appreciated !

Re: [solved] Create link to specific (single) information pa
Posted: Thu Sep 08, 2011 6:19 pm
by simpl3
very useful, will try that for sure!

Re: [solved] Create link to specific (single) information pa
Posted: Tue Jan 22, 2013 8:37 am
by alexhigh
This worked brilliantly, thanks Jay.
One thing I noticed was a missing close bracket:
if(in_array($information['information_id'], array(1,2,3,4)) {
pretty sure this should be:
if(in_array($information['information_id'], array(1,2,3,4))) {