• Hello,

    Hello,
    I try to display an Ajax Load more sidebar post list on single.php and Iwould like to add a specific class to the item currently queried on single.php. So I get the ID of the ajax loaded item into $thisPostID and compare it with $thePostID that should retrieve the queried page ID.

    I tried with :
    global $wp_query;
    $thePostID = $wp_query->post->ID;
    And
    $thePostID = get_queried_object_id();

    Both work fine in my template files but not in the Repeater template.

    Any idea how to work this around? Thanks by advance for your help.

    Below is a snippet of my repeater, with the If/ELse statement to set the css classes

    <?php
      $thisPostID = get_the_ID(); // Ajax loaded item ID, works fine
    global $wp_query;
    $thePostID = $wp_query->get_queried_object_id();
    ?>
    <article id="post-<?php the_ID(); ?>" <?php if ($thePostID == $thisPostID ) { post_class("c-news-list_item current_c-news-list_item"); } else { post_class("c-news-list_item"); } ?>>
    // content
    </article>
Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Darren Cooney

    (@dcooney)

    Hi @fishtik,
    Its actually really difficult to pass a variable to a repeater template. It’s something i’ve been trying to sort out but haven’t came up with a good solution yet.

    Can I ask why you you would even want to query the single post in your post listing?
    Seems to me like you would almost always want to exclude that post from displaying…. So for my ignorance in advance ??

    Thread Starter fishtik

    (@fishtik)

    Well ideally I would like to ajaxify my wordpress template and have an Ajax load more side bar with the latest posts. Here’s a reference I found very interesting : https://kekselias.com/articles/2016/06/03/may-payrolls-policy-normalization-interrupted/?c=1&t=0

    Also I’m not even sure Ajax load more will work with “Ajaxify WordPress Site”. Have you ever tried?

    And so the reason why I’m looking for the single post ID is to mute the design down with some custom css.

    Plugin Author Darren Cooney

    (@dcooney)

    I haven’t tried that, but it’s possible as long as you make sure to load the Ajax Load More JS.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Variable : Get_queried_object_id in the repeater’ is closed to new replies.