WordPress.org

Ready to get started?Download WordPress

Forums

Post Content to show in Fancy Box (5 posts)

  1. cocoonfxmedia
    Member
    Posted 1 year ago #

    Hi

    I have an interactive map powered by Jquery and I want to be able to show a list of post types per region. When you click on the post type title I want a fancybox to open with the post content. For some reason I can't see away to add the fancybox to the permalinks.

    My code is as follows:
    header.php

    <script type="text/javascript">
    $(document).ready(function(){
    $('.fancybox).fancybox();
    });
    </script>

    content-page.php

    <li id="midlands">
    <?php page_query = new WP_Query('category_name=midlands&post_per_page>=1') while ($page_query->have_posts()): $page_query->the_post();?>
    <a class="fancybox" href="<?php the_permalink();?>"<?php the_title();?>?><?php the_title();?</a><br/>
    <?php endwhile: wp_reset_postdata();?></li>

    I have tried everything and I can not get it to work. I can get a link without a permalink to display the page content the links on but I not able to pull the content from a post.

  2. Thea G
    Member
    Posted 1 year ago #

    For one thing, try to echo your variables so they get written to the html like this

    <?php echo the_permalink();?>

  3. bcworkz
    Member
    Posted 1 year ago #

    @Thea G: That's a good tip in general, except for WP functions with names starting with "the_", which typically directly echo content to the client as part of the function and do not actually return anything. So the code you suggest will not do anything more than the OP's code. the_permalink() is a one liner function, essentially: echo get_the_permalink();

    @cocoonfz: The first snippet has a selector with a missing quote, but I suspect it's a typo and not the cause of your problem. I don't have a real solution for you, but where your script appears in the header can make a difference, which is sometimes not entirely controllable. You might try enqueuing the script and relevant css so WP knows about it and hopefully resolves dependencies. I don't know if this will help, but would be worth a try if you're still stuck.

  4. Thea G
    Member
    Posted 1 year ago #

    thanks bcworkz...I didn't know that (about the echo being built into the_ functions). It makes sense that is how it works ...the_content() et al

  5. ntlgnzalez
    Member
    Posted 1 year ago #

    Hi!
    I need just exactly what cocoonfx was talking about, but I'm not so good in program. Can anyone explain me how can I link my posts to this query page??
    I'm working with custom post types

    <?php page_query = new WP_Query('category_name=midlands&post_per_page>=1') while ($page_query->have_posts()): $page_query->the_post();?>

    thank you so much!!!

Topic Closed

This topic has been closed to new replies.

About this Topic