Reputation: 1
I'm in a very difficult situation and have to figure this out, without enough knowledge.
I have an image gallery page, and a home page, on a wordpress site.
The image gallery page filters categories when you click on a link, heres what it looks like:
<ul>
<li>
<a href="#" class="selected" onclick="cgm_filter_system(0,'*',this);return false">All</a>
</li>
<li>
<a href="#" onclick="cgm_filter_system(0,'categoryid31',this);return false">Category 1</a>
</li>
<li>
<a href="#" onclick="cgm_filter_system(0,'categoryid34',this);return false">Category 2</a>
</li>
</ul>
I now want to have links on the homepage, Category 1, and Category 2, to take you to the image gallery page, with the category already selected.
There is no url change when you change categories on the image gallery page.
So I am guessing if I can just pass the:
onclick="cgm_filter_system(0,'categoryid34',this);return false"
from the home page, to the image gallery page, it will work, because it will be just like if I clicked on the link on the image gallery page.
Now I just need some help figuring out what this is called. I do not even know what to search for. Am I looking for a listener event?
How do I pass the javascript from the home page from a link, into the image gallery page, as if it was clicked on the iamge gallery page?
Is there a way to just put the variables in a regular ?
I can use php, javascript, or jquery.
If anyone can even point me in the right direction it would really help, I tried searching but there are many things that sound similar, and I do not know what direction to go in.
Thank you so much.
Upvotes: 0
Views: 1488
Reputation: 656
One approach could be to trigger a click on the gallery page. I must say that there are better ways to do this but I am trying to infer what is best for your level and situation. You might do the following:
1) Give the gallery links on the gallery page an identifier according to thier category id(data-id attribute in this case), for example:
<a href="#" data-id="category31" onclick="cgm_filter_system(0,'categoryid31',this);return false">Category 1</a>
2) Create a link on the index page:
<a href="gallery_page.php?category_id=31">Gategory 31</a>
3) Make jquery trigger a click when the above link is clicked; this would be on the gallery page, placed on the page AFTER THE LINKS:
<?php if(isset($_GET['category_id'])):?>
(function(){
$("[data-id='category<?php echo $_GET['category_id']?>']").trigger('click');
})();
<?php endif; ?>
Try it.
Upvotes: 1