Skip to:
Content
Pages
Categories
Search
Top
Bottom

Need help with Custom Code


  • shanetheclassic
    Participant

    @shanetheclassic

    Hi Everyone,

    I have a unique issue. I’m using Buddypress with some modifications, and one of the features of the site is a sidestream bar that lists that latest 20 posts. In order to help with styliing and other issues, I created a code that explodes the activity content into parts so i could style accordingly. I made this code for the single activity page, so now my problem is that it only displays the latest activity in all 20 spots.

    I need it to be able to get all 20 and explode them all. I tried everything I know and got nowhere. PLEASE HELP!

    Heres the custom code I created. The part with $activityDescription = (activityDescription[0]); is where it calls the description for the latest post, if I change the value to 1 it shows the next one and so on..I tried an array with all 20 but still didnt work

    `

    <?php
    global $activities_template;
    $activities = $activities_template->activities;
    $activity = $activities[0];

    $activityContent = $activity->content;

    if(stripos($activityContent, “[bpfb_images]”))
    {
    $activityDescription = explode(“[bpfb_images]”, $activityContent);
    $activityDescription = ($activityDescription[0]);

    //var_dump($activityContent);
    $images = explode(” “, $activityContent);
    for($i=0; $i<sizeof($images);$i++)
    {
    if(!(stripos($images[$i], “.jpg”) === false) || !(stripos($images[$i], “.png”) === false) || !(stripos($images[$i], “.gif”) === false))
    {
    $brokenImages =preg_split(‘/s+/’, $images[$i]);
    for($k=1;$k<(sizeof($brokenImages)-1);$k++)
    {
    if(trim($brokenImages[$k]) == “” || !(stripos($brokenImages[$k], “bpfb_”) === false))
    continue;

    $finalURL = $brokenImages[$k];
    $finalFULL = $brokenImages[$k];

    if(!stripos($finalURL, “ttp://”))
    {
    $finalURL = str_replace(“.j”, “-bpfbt.j”, $brokenImages[$k]);
    $finalURL = “(SITE REMOVED)”.$finalURL;
    $finalFULL = “(SITE REMOVED)”.$finalFULL;
    }
    echo “

    “;
    echo “

    “;
    echo “

    “.bp_get_activity_action().”

    “;
    echo “

    “.$activityDescription.”

    “;
    }
    }
    }
    }
    else
    {
    echo “

    “;
    echo “

    “.bp_get_activity_action().”

    “;
    echo “

    “.$activityContent.”

    “;
    }
    ?>
    `

    I removed the webiste address in (SITE REMOVED) so search engines cant find it right now while its in dev.

    THANKS!

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

  • shanebp
    Moderator

    @shanebp

    imo, It’s not clear what you’re trying to do.
    On a ‘single activity page’ – you mean the profile activity page for a specific member ?

    And on that page you want to display, in a sidebar, the 20 most recent updates from all users ?

    In your code, you’re only looking for updates that include an image [bpfb_images]

    So you only want the 20 most recent updates from all members that include an image ?
    If so, you’d be better off writing a custom query. Then you won’t have to do all that string parsing.


    shanetheclassic
    Participant

    @shanetheclassic

    Sorry I’ll elaborate more, fellow shane ;)

    I need to display the most recent 20 posts. If you notice in the code I have it set to display if it has an image a certain way, and if it doesnt, another way (check the echo statements at the bottom)

    If I specifiy the post in $activityDescription = (activityDescription[0]); replacing 0 with 1,2,3 etc, it dispalys that post, regardless of if it has a picture or not..the code doesn’t only display ones with pictures, it just explodes them a certain way if it has one or not…

    So in a nutshell, I need it the code to do what it is doing now, but instead of just with the 1 post, I need it to work for the last 20….


    shanetheclassic
    Participant

    @shanetheclassic

    Sorry, by ‘way’ and ‘other way’ i mean the order of which it renders out the activity post..if the post has an image, it renders the image first, then avatar, then header, then description. If it doesnt have a picture, it renders the description, then avatar then header…


    shanebp
    Moderator

    @shanebp

    > I need it the code to do what it is doing now, but instead of just with the 1 post, I need it to work for the last 20….

    Did you try a for loop
    `
    for($i=0, i<20; ++i) {
    $activity = $activities[$i];
    etc
    `


    shanetheclassic
    Participant

    @shanetheclassic

    I just tried that, no luck

    I should also add that the avatar and header that get rendered out are unique to the post, just the description is the same for each post…


    shanebp
    Moderator

    @shanebp

    Why are you using this: $activityDescription = (activityDescription[0]);
    instead of this: $activityDescription = activityDescription[0];

    I would go with the latter version and echo it and comment out everything below it, to ensure it is as you expect. Or just var_dump($activityDescription) after you do the explode and before you reassign it.


    shanetheclassic
    Participant

    @shanetheclassic

    Force of habit using (), removed it though, no changes

    Did a var dump before and after, before lists the description content for the latest one ([0]) and after returns NULL

    Basically, the issue is getting the [0] in $activityDescription = activityDescription[0]; to be the first 20 posts [0,1,2,3 etc..] so it knows to do taht for all of them..i tried makign an array but got errors..i might of been doing ti wrong..but if you can focus on that part..

    If you need any more info, or would like to view the site yourself let me know

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Need help with Custom Code’ is closed to new replies.
Skip to toolbar