News:

Support the VirtueMart project and become a member

Main Menu

Multiple Category Images in Category Page

Started by scotous, August 20, 2012, 22:05:23 PM

Previous topic - Next topic

scotous

What I wanted to achieve is to have more than 1 category image shown in the category page.

From what I can remember I had achieved it in a previous version of vm but from what I see now i can't get it right.

The string from other posts was
<?php if ($this->category->virtuemart_media_id) echo $this->category->images[0]->displayMediaFull("", false); ?>
but this only shows the first image of the category.

Any way this could work?


ivus

Hi scotous,

That's correct.

Quote

<?php

  if ($this->category->virtuemart_media_id) :
    foreach ($this->category->images as $catimg) :
      echo $catimg->displayMediaFull("", false);
    endforeach;
  endif;

?>


You need some sort of loop to display all the image. Simple PHP stuff.

Good luck, I hope this helps. :D

scotous

Dear Ivus,

Thank you very much for your assistanse.

I try the below code but it still only shows the 1st picture.

I tried the foreach for a lil bit but couldnt figure it out.
What I see is that the virtuemart_media_id is different for every image but the virtuemart_category_id is correct.

Did this code worked for you?

ivus

Hi scotous,

I don't use Category Images in my site.

What you'll need to do is find the items in your $this->category->virtuemart_media_id array and loop through each of those to output the images.

The code I wrote, was just an example based on the code you pasted.

scotous

Dear Ivus,

When you say find the items in the $this->category->virtuemart_media_id array what do you mean?

I am aware after diggint the sql that all the images i uploaded in a category have different virtuemart_media_id but same virtuemart_category_id and the first thing i did was to check if that could work.

But it didnt

:/

ivus

echo '<pre>'; print_r($this->category->virtuemart_media_id); echo '</pre>';

You won't get far if you don't know if the image information is in that array. The fact that VM is only showing the first image may mean that only ONE image is passed to that page?

scotous

What i get from this is

Array
(
   
  • => 1
        [1] => 4
        [2] => 5
    )

    I am not sure what this means though...

    Through the backend i have added 3 images.

    Is there any way to check how many images are passed in the page?

scotous

Ok i now now what 1-4-5 means.

These are the virtuemart media ids that are allocated in this category only.
So the correct ids are passed.

but still only the first is shown

ivus

Hi scotous,

that's right... they're the media ID's you need to work with... unfortunately, there's no frontend model/helper that uses mediaIDs so your task gets way more difficult from here on...

I don't use category images otherwise I'd be able to continue helping you, but if you know PHP, all you need to do is write an SQL query to grab the location of the files associated with the ID out of the database, then display it on your page.

Good luck.


scotous

The products page work exactly the same way but they do show more than one images
I ll go to sleep now and will recheck it again tomorrow

Thank you very much again!

scotous

I have 40% understood the way array's work but still coulnd get the solution.

The array shows me that the image is passed

Array
(
   
  • => 1 (this is the first image of the category)
        [1] => 2 (this is the second image of the same category)
    )

    But although i put the exactly same code with the products one (fyi in the products page the code works)

    So i presume that the products code have a model/ helper that provides the required connection which i miss...

    any help anyone?