ankh2054 Posted June 20, 2014 Share Posted June 20, 2014 Hi All, Wonder if someone could assist me with the below. I have created a foreach loop to show all the children pages of current page. This works. I am then trying to show different text for each child based on whether the current logged in user is the owner or not. This works, apart from at each loop iteration the previous results are added prior to the current. <?php $results = $page->children; foreach($results as $reply) { //Bottom post buttin display options - Reply if ($reply->createdUser->name == $user->name){ $bottom_options_reply .= "<p> This is the current owner</p>"; } else { $bottom_options_reply .= "<p> This is not the owner </p>"; } //Theme each topic echo " <div class='panel panel-default'> <div class='panel-body'> <div class='col-md-3'> {$avatar_profile_logo} {$reply->createdUser->name} </div> <div class='col-md-6'> {$reply->body} </div> </div> <div class='panel-footer'> {$bottom_options_reply} </div> </div> "; Below is the screenshot of the results, showing the $bottom_options_reply being added multiple times. Link to comment Share on other sites More sharing options...
ankh2054 Posted June 20, 2014 Author Share Posted June 20, 2014 I added this to the above and it worked. $bottom_options_reply = ''; //Footer button display options - Reply $bottom_options_reply = ''; if ($reply->createdUser->name == $user->name){ $bottom_options_reply .= "<p> This is the current owner</p>"; } Link to comment Share on other sites More sharing options...
Joss Posted June 20, 2014 Share Posted June 20, 2014 Yes, you have to set up the variable before the loop, otherwise all you have a pile of addons to the variable without the original variable, if you see what I mean! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now