Skip to:
Content
Pages
Categories
Search
Top
Bottom

Trying to Run a if group = "this name"


  • chrisknade
    Participant

    @chrisknade

    Im trying to match group names to a predefined list so that I may only output the groups which match the list.

    I’ve tried this

    <div id="localphone">
    <?php if ( bp_has_site_groups() ) : ?>

    <div class="pag-count" id="group-dir-count">
    <?php bp_site_groups_pagination_count() ?>
    </div>

    <div class="pagination-links" id="group-dir-pag">
    <?php bp_site_groups_pagination_links() ?>
    </div>
    <?php while ( bp_site_groups() ) : bp_the_site_group(); ?>
    <?php $localNetwork = bp_the_site_group_name() ?>;
    <?php if ($localPhone== Brighton || $localPhone==Test Group)

    <dl>
    <dt><a href="http://business-chamber.com/featured-<?php bp_the_site_group_name() ?>/" title=""><?php bp_the_site_group_avatar_thumb() ?></a></dt>
    <dd><?php bp_the_site_group_name() ?></dd>
    </dl>
    <?php }
    else {
    echo
    }
    ?>
    <?php endif; ?>
    <?php endwhile; ?>

    <?php else: ?>

    <div id="message" class="info">
    <p><?php _e( 'There were no groups found.', 'buddypress' ) ?></p>
    </div>

    <?php endif; ?>

    Can anyone shed any light on why that won’t work. Its basically I’ve got a list of 50 or so that I want shown and then to pull in the name of each and the gravatar. I’m trying to do this in the bphome theme by the way, in a custom page.

    Cheers in advance for any help!!!.

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

  • r-a-y
    Keymaster

    @r-a-y

    Put quotes around your conditional cases.

    eg.

    if ($localPhone== Brighton || $localPhone==Test Group)

    to:

    if ($localNetwork== "Brighton" || $localNetwork=="Test Group")

    See if that works.

    [EDIT]

    Also $localPhone isn’t defined… you want to use $localNetwork instead.


    chrisknade
    Participant

    @chrisknade

    Thanks for the reply Ray. Yeah i’ve went back too far on my undos. I had it the way you’ve suggested. Any other reason’s why it wouldn’t work, as in logically rather than in my example poor syntax?


    r-a-y
    Keymaster

    @r-a-y

    I haven’t had time to dive into the logic, but it looks quite sound.

    What happens when you echo $localNetwork?

    Try bp_get_the_site_group_name() instead of bp_the_site_group_name().

    When I have some more time, I might give it another shot.

    Hopefully someone else can help you out by then!

    I’d also recommend getting acquainted with the bp-groups/bp-groups-templatetags.php.

    It’s your bible to BP Groups! :)

    You must use:

    bp_get_the_site_group_name()

    as without the ‘get’ part, it will echo and not return the value.


    chrisknade
    Participant

    @chrisknade

    Otherwise Andy do you think that should work?


    r-a-y
    Keymaster

    @r-a-y

    Try it and report back!


    chrisknade
    Participant

    @chrisknade

    I have tried it, with this code

    <?php get_header(); ?>

    <div id="content" class="widecolumn">
    <h2 class="widgettitle"></h2>
    <div id="localphone">
    <?php if ( bp_has_site_groups() ) : ?>

    <div class="pag-count" id="group-dir-count">
    <?php bp_site_groups_pagination_count() ?>
    </div>

    <div class="pagination-links" id="group-dir-pag">
    <?php bp_site_groups_pagination_links() ?>
    </div>
    <?php while ( bp_site_groups() ) : bp_the_site_group(); ?>
    <?php $localPhone = bp_get_the_site_group_name() ?>;
    <?php if ($localPhone=="Manchester" || $localPhone=="Test Group") {
    echo '<dl>';
    echo '<dt><a href="http://business-chamber.com/featured-<?php bp_get_the_site_group_name() ?>/" title=""><?php bp_get_the_site_group_avatar_thumb() ?></a></dt>';
    echo '<dd><?php bp_get_the_site_group_name() ?></dd>';
    echo '</dl>';
    } else {
    echo 'hello';
    }
    ?>
    <?php endwhile; ?>

    <?php else: ?>

    <div id="message" class="info">
    <p><?php _e( 'There were no groups found.', 'buddypress' ) ?></p>
    </div>

    <?php endif; ?>

    </div>

    <?php get_footer(); ?>

    Im now getting

    ;

    ;

    hello;

    I definately have the 2 test groups there and it is doing something right, as in only returning the hello for the last one where I don’t have a || condition.


    r-a-y
    Keymaster

    @r-a-y

    <?php $localPhone = bp_get_the_site_group_name() ?>;

    Remove the semi-colon from the end and that will get rid of the echo problem.

    I assume you meant:

    <?php $localPhone = bp_get_the_site_group_name(); ?>

    The if statement should be:

    <?php if ( ($localPhone=="Manchester") || ($localPhone=="Test Group") ) {


    chrisknade
    Participant

    @chrisknade

    Hmmm, thats got rid of the semi colon as you said. Now im just getting the solitary echo as in none of my conditions are satisfied. They should be coz both groups are there. Have i made a mistake regarding the get.


    r-a-y
    Keymaster

    @r-a-y

    What happens when you try to echo $localPhone?


    Jeff Sayre
    Participant

    @jeffsayre

    Along with the corrections that r-a-y points out, I took a quick cursory look and saw this error:

    <?php $localNetwork = bp_get_the_site_group_name() ?>;

    Should be:

    <?php $localNetwork = bp_get_the_site_group_name(); ?>


    chrisknade
    Participant

    @chrisknade

    Thanks for your input Jeff. Ray i get all 3 groups outputting fine when i echo localPhone. Could it be that i need to assign test group to say $testgroup and try the comparison that way? Is there some syntax conflict that won’t let me compare them the way i currently am?

    Anyway off to bed now, its 1am uk time.


    r-a-y
    Keymaster

    @r-a-y

    This could be a little silly and not even note-worthy but try adding spaces between your equals signs:

    <?php if ( ($localPhone == "Manchester") || ($localPhone == "Test Group") ) {

    The other thing you could do is try just one condition:

    <?php if ( $localPhone == "Manchester") {

    and see what happens.


    chrisknade
    Participant

    @chrisknade

    I’ve tried with and without spaces, I’ll try the single condition, I’ll be in touch tomorrow no doubt! Thanks for your help so far ray. Night


    Jeff Sayre
    Participant

    @jeffsayre

    Ha!

    I had this thread up, walked away for twenty minutes, forgot to refresh, and just posted. Of course, in that time there were eight additional posts. Oops!


    chrisknade
    Participant

    @chrisknade

    Right I’ve tried the single quote on it now. still no luck, my face is currently like my avatar! glum!

    Any further ideas? I can’t see how something as simple as doing a check on existing data in the loop should be some troublesome.

Viewing 16 replies - 1 through 16 (of 16 total)
  • The topic ‘Trying to Run a if group = "this name"’ is closed to new replies.
Skip to toolbar