Post by djeeke » Sun Apr 17, 2011 5:39 am

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
Last edited by djeeke on Tue Apr 19, 2011 2:25 am, edited 1 time in total.

New member

Posts

Joined
Wed Mar 30, 2011 10:19 pm

Post by JAY6390 » Sun Apr 17, 2011 11:21 pm

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

Image


User avatar
Guru Member

Posts

Joined
Wed May 26, 2010 11:47 pm
Location - United Kingdom

Post by djeeke » Mon Apr 18, 2011 2:04 am

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

New member

Posts

Joined
Wed Mar 30, 2011 10:19 pm

Post by JAY6390 » Mon Apr 18, 2011 6:16 am

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

Image


User avatar
Guru Member

Posts

Joined
Wed May 26, 2010 11:47 pm
Location - United Kingdom

Post by djeeke » Mon Apr 18, 2011 10:25 pm

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...

???

New member

Posts

Joined
Wed Mar 30, 2011 10:19 pm

Post by JAY6390 » Mon Apr 18, 2011 10:29 pm

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.

Image


User avatar
Guru Member

Posts

Joined
Wed May 26, 2010 11:47 pm
Location - United Kingdom

Post by djeeke » Tue Apr 19, 2011 12:31 am

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 ;-)

;D

New member

Posts

Joined
Wed Mar 30, 2011 10:19 pm

Post by JAY6390 » Tue Apr 19, 2011 12:36 am

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

Image


User avatar
Guru Member

Posts

Joined
Wed May 26, 2010 11:47 pm
Location - United Kingdom

Post by djeeke » Tue Apr 19, 2011 1:54 am

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..

New member

Posts

Joined
Wed Mar 30, 2011 10:19 pm

Post by JAY6390 » Tue Apr 19, 2011 1:59 am

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

Image


User avatar
Guru Member

Posts

Joined
Wed May 26, 2010 11:47 pm
Location - United Kingdom

Post by djeeke » Tue Apr 19, 2011 2:24 am

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 !

:)

New member

Posts

Joined
Wed Mar 30, 2011 10:19 pm

Post by simpl3 » Thu Sep 08, 2011 6:19 pm

very useful, will try that for sure! :clown:

Newbie

Posts

Joined
Tue Sep 06, 2011 4:23 am

Post by alexhigh » Tue Jan 22, 2013 8:37 am

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))) {

Newbie

Posts

Joined
Sun Jun 17, 2012 8:59 pm
Who is online

Users browsing this forum: No registered users and 59 guests