开发者

Loading content from Wordpress posts dynamically from clicked images

开发者 https://www.devze.com 2023-04-06 05:53 出处:网络
I\'m trying to insert content from separate Wordpress posts into an info box when an image is clicked. I\'m using a modified template for this section of the site, where the images are populated from

I'm trying to insert content from separate Wordpress posts into an info box when an image is clicked. I'm using a modified template for this section of the site, where the images are populated from an array.

I have successfully made this work using the .load() method with jQuery an开发者_运维知识库d a static URL.

        <script type="text/javascript">
        jQuery(document).ready(function() {
                jQuery('.dynagrid a').click(function(event){ 
                // stop normal link click
                event.preventDefault(); 
                }); 
            jQuery('.dynagrid a').click(function(){
                jQuery('div.project-info').fadeToggle(function(){
                    jQuery(".infotext").load('/cowshed/akg .infotext > *', function() {
                        jQuery('div.project-info').fadeToggle() 
                    }); 
                });
            });
        }); 

My problem lies in making the loaded URL dynamic for each image - with each image loading different information. My plan was to grab the <alt> information for each image as a variable and insert this e.g. jQuery(".infotext").load('/cowshed/+alt+ .infotext >*'); and match it to the permalink of the desired post but everything I've tried has failed.

I've looked for hours for a solution on this and I fear my inexperience in jQuery is making this much harder than it may actually be.

Here's the page so far: Cowshed Tools

Can anyone see a solution and shed some light?


 jQuery(".infotext").load('/cowshed/akg .infotext > *', function() {
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^

The indicated part should be the URL that'll provide the content you're loading into the .infotext element. You've got what looks like an unholy mishmash of url and CSS selectors, which is NOT a valid URL. Given you want to load things dynamically, it should be something:

.load('http://example.com/fetchcontent?contentID=' + this.alt, function () ....);

The url doesn't have to be absolute like that, but it should be a valid URL for your server.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号