Skip to:
Content
Pages
Categories
Search
Top
Bottom

Site Members Loop & Variables


  • TheEasyButton
    Participant

    @theeasybutton

    I’m working on a plugin that utilizes “The Site Members Loop

    The first line of the loop says

    <?php if ( bp_has_site_members( 'type=active&max=5' ) ) : ?>

    What I would like to do is put a variable where the max number is. I can put a variable where active is and it works fine. But if I put a variable where the max number is

    (i.e. &max=$come_on_you_dang_thing) it kicks out the following error:

    Warning: Division by zero in C:… buddypressbp-corebp-core-templatetags.php on line 819

    The area around line 819 (so you dont have to go look) says

    $this->pag_links = paginate_links( array(
    'base' => add_query_arg( 'upage', '%#%' ),
    'format' => '',
    'total' => ceil( (int) $this->total_member_count / (int) $this->pag_num ),
    'current' => (int) $this->pag_page,
    'prev_text' => '&laquo;',
    'next_text' => '&raquo;',
    'mid_size' => 1
    ));

    The longest line there is 819.

    So…??? Any clue why it’s kicking out that division error and how I can fix it??

    Thanks in advance for your help!!

Viewing 10 replies - 1 through 10 (of 10 total)

  • Burt Adsit
    Participant

    @burtadsit

    Just putting a $var in the template doesn’t mean that the $var is available in that scope. Unless you are generating the value of $var in the template itself it will resolve to 0 and be passed along to bp.


    John James Jacoby
    Keymaster

    @johnjamesjacoby

    If he’s trying to do…

    <?php if ( bp_has_site_members( 'type=' . $foo1 . '&max=' . $foo2 ) ) : ?>

    …then in theory it *should* work, at least from what I see.

    I’ll have time in the morning to check on this if you don’t by then Burt.


    Burt Adsit
    Participant

    @burtadsit

    I’ve run into this before. That code snippet above only works if the $foo’s are created in the template. The code underneath that contains $foo’s is a different scope.


    TheEasyButton
    Participant

    @theeasybutton

    Thanks JJJ & Burt for your responses.

    Burt, you said “Unless you are generating the value of $var in the template itself….” Basically, what I was doing, and sorry I didn’t include this in my code, was

    <?php
    $var = 5;
    if ( bp_has_site_members( 'type=active&max=$var' ) ) : ?>

    I was doing it the most simple way I could think of just to see if it would work first but that number as a variable was killing me.

    Should I look at $foo’s or is that not the right solution? Thanks again.


    Jeff Sayre
    Participant

    @jeffsayre

    How about this:

    <?php
    $var = 5;
    if ( bp_has_site_members( 'type=active&max=' . $var ) ) : ?>

    :)


    TheEasyButton
    Participant

    @theeasybutton

    Oh good grief!!! What the heck is wrong with me? Time to go hide in shame in the corner. LOL Thanks Jeff!!!

    *shakes her head at herself*

    Marking as resolved


    Jeff Sayre
    Participant

    @jeffsayre

    Don’t worry! Things like that happen to me daily.


    dunc
    Participant

    @dunc

    @burtadsit I have been able to achieve a positive result using @jeffsayre ‘s code, however I want to set the value of my $var outside the template. Do you know if this is possible? I fear not based on what you said above:

    “I’ve run into this before. That code snippet above only works if the $foo’s are created in the template. The code underneath that contains $foo’s is a different scope.”

    I’ve tried setting my $var in my functions.php file and in my custom page template by hooking in to bp_before_members_loop:

    <?php
    function my_function() {
    $var = ‘xxx’;
    }
    add_action(‘bp_before_members_loop’,’my_function’);
    ?>

    Many thanks!


    r-a-y
    Keymaster

    @r-a-y

    @dunc – If you want a global variable, then (surprise, surprise!) use a global variable or a define.

    In wp-config.php or /wp-content/plugins/bp-custom.php, you can either do this:

    global $my_var;
    $my_var = WHATEVER;

    or:

    define( 'MY_VAR', WHATEVER );

    Then in your page template or anywhere else, you do this:

    global $my_var;
    if ( bp_has_site_members( 'type=active&max=' . $my_var ) ) :

    or:

    if ( bp_has_site_members( 'type=active&max=' . MY_VAR ) ) :

    Hope that helps.


    dunc
    Participant

    @dunc

    @r-a-y – Thanks! That worked.

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Site Members Loop & Variables’ is closed to new replies.
Skip to toolbar