• Resolved tobiasmalikowski

    (@tobiasmalikowski)


    Hi Darren,

    sorry to open another ticket again. But I can’t figure out how to pass a variable to a repeater template. I’m using your Previous Post plugin. In my repeater template I want to check if it’s the first post being loaded.

    My first attempt was to save get_the_id() to a variable, pass that variable to my repeater template and then do something like this:

    if(get_the_id() == $passed_variable) {
        // do stuff
    }

    Hope you can help me with this too. Thanks mate!

    https://wordpress.org/plugins/ajax-load-more/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Darren Cooney

    (@dcooney)

    You can use the variables as discusibed in the docs.
    https://connekthq.com/plugins/ajax-load-more/docs/variables/

    Use $alm_item to retrieve the current item number.

    if($alm_item == 1){
    // do stuff
    }
    Thread Starter tobiasmalikowski

    (@tobiasmalikowski)

    Hi Darren,

    I’ve already read the docs and tried the available variables, but it won’t work in my situation, cause I’m using the previous post addon to load the posts one by one. So $alm_item is always 1.

    I need to check if the post id that ALM is loading is the same as the post the user clicked on.

    Thread Starter tobiasmalikowski

    (@tobiasmalikowski)

    Ok managed to solve it. So for everyone who needs to do the same. Use declare the variable you want to pass as global:

    single.php

    global $alm_original_post;
    $alm_original_post = true;

    repeater-template.php

    global $alm_original_post;
    if(!$alm_original_post) {
        // since the script is only called once the variable is only available
        // on the first call. So you can do stuff different for the first post.
        // I needed this to don't display the post image for the first post,
        // since my post-image is connected to the navigation.
    }

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘ALM Previous Post – Pass variable to repeater template’ is closed to new replies.