1

I'm trying to add posts I have in the category to open via Slide Panel without going into a single post how can I do this?

The Demo Slide In Panel can be viewed below:

DEMO SLIDE IN PANEL

I tested it on my website but only the first post appears in every post that clicks.

My code:

<?php
$args = array(
    'meta_key'=> 'ecpt_toparticle',
    'showposts' => 5,
    'category__in' => $cat
);
$sticky_query = new WP_Query( $args );
while ( $sticky_query->have_posts() ) : $sticky_query->the_post();
?>
            <div class="border"> 
            <a href="<?php the_permalink();?>" class="myimages js-cd-panel-trigger" data-panel="main">
            <?php the_post_thumbnail('300x300');?>
            </a>

            <div class="col-10">
            <div class="title"><?php the_title() ?></div>
        </div>
    </div>

    <?php  endwhile; wp_reset_postdata(); ?>

    <div class="cd-panel cd-panel--from-right js-cd-panel-main">
        <header class="cd-panel__header">
        <h1><?php the_title() ?></h1>
        <a href="" class="cd-panel__close js-cd-close">Close</a>
        </header>
        <div class="cd-panel__container">
        <div class="cd-panel__content">
        <div class="myimages">
        <?php the_post_thumbnail('600x350');?>
        </div>
        <p><?php the_content(); ?></p>

        </div> <!-- cd-panel__content -->
    </div> <!-- cd-panel__container -->
</div> <!-- cd-panel -->

You will easily understand it through screenshots:

enter image description here enter image description here

1
  • Not sure but a quick look at the code shows the right side info outside the loop from <div class="cd-panel cd-panel--from-right js-cd-panel-main">. From a quick look if the post this is run on is the first then it will pull only this data as its getting the current post info. Try running on another post to see if it obtains that posts data.
    – Sam
    Commented Nov 19, 2019 at 22:46

1 Answer 1

2

The reason why your query fails is the following. You are finishing the loop before your cd-panel with

<?php  endwhile; wp_reset_postdata(); ?>

which is correct. However, after that you are simply using

<?php the_title(); ?>, <?php the_content(); ?>

which is just a single template tag, and in your case, outputs the title of the first post of the last category you've queried.

The solution:

  • You have to load the post content's via a wp ajax call (on click on that accordeon tab), or

  • open up another loop before the cd-panel, get all posts and hide/show them with css

The second is more load heavy, but not that complicated.

1
  • Hi thanks for your answer do you have any example of how this is done?
    – Karelli
    Commented Nov 20, 2019 at 6:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.