Forum

Thread tagged as: Members

Members Dynamic Content

Sorry for all questions in advanced.

So I am trying to dynamically fill a members page with a blog tag and header image.

I know members each have their own tags but how do I show blogs with that tag on only their member page?

And how do I get a different image to show as header based on their tag?

b lewis

b lewis 0 points

  • 3 years ago
b lewis

b lewis 0 points

I have tried this with out much luck

<?php perch_blog_custom(array(
          'tag' => perch_member_get('first_name');
));
?>

I was hoping it worked like

<?php
perch_content_custom('Posts', [
  'count' => perch_get('count', 10);
]);
?>
Hussein Al Hammad

Hussein Al Hammad 105 points
Registered Developer

Hello beckhusen

You have a syntax error in your code. 'tag' => perch_member_get('first_name'); should not end with a semicolon ;, but a comma ,.


I know members each have their own tags but how do I show blogs with that tag on only their member page?

perch_blog_custom(array(
  'tag' => perch_member_get('first_name'),
));

The above code would retrieve blog posts tagged with the member's first name. Is this what you're trying to achieve?


And how do I get a different image to show as header based on their tag?

You'd need to check whether the member has the tag with perch_member_has_tag(). For example:

if (perch_member_has_tag('subscriber')) {
     // special header for subscribers
} else {
     // regular header for non-subscribers
}

Documentation for the Members app functions: https://docs.grabaperch.com/functions/members/

b lewis

b lewis 0 points

oh perfect! I got the tagging blog situation to work.

is there a way to make the 'subscriber' dynamic?

Hussein Al Hammad

Hussein Al Hammad 105 points
Registered Developer

is there a way to make the 'subscriber' dynamic?

It depends. What do you want to test against? Do you have a list of tags somewhere?

b lewis

b lewis 0 points

well i want each member to have their own, so there will be a list of client tags to select from

Hussein Al Hammad

Hussein Al Hammad 105 points
Registered Developer

I don't know enough about your project to suggest the best way to implement this.

From the code above it seems you have blog posts tagged with members first names. The members themselves don't have tags as far as I can tell, is this right?

So perhaps you want to check whether the member is logged in?

if (perch_member_logged_in()) {
     // special header for logged in members
} else {
     // regular header for non-members
}
b lewis

b lewis 0 points

They do currently have tags, and it is their first name

Each member will be clients and the introductory header will have an image specific to their business ie:

Name: Betty Tag: Betty Photo: /login/resources/bettysheader.jpg

Name: David Tag: David Photo: /login/resources/davidssheader.jpg

Name: Lacy Tag: Lacy Photo: /login/resources/lacysheader.jpg

b lewis

b lewis 0 points

Also, how do I add more fields to the Members detail admin area? ie: title, phone number, logo picture/

Hussein Al Hammad

Hussein Al Hammad 105 points
Registered Developer

They do currently have tags, and it is their first name

You don't need to add a tag to a member with their first name. You can get their first name with perch_member_get('first_name').

Though for what you're trying to achieve you may not even need their name. Add a field to the member edit form for the header and add regions for default headers:

if (perch_member_logged_in()) {
    $member_header = perch_member_get('header');

    if($member_header) {
        // special header for this member
        echo '<img src="' . $member_header . '">';
    } else {
        // default header for logged in members
        perch_content('Members Header');
    }


} else {
    // regular header for non-members
    perch_content('Non-Members Header');
}

Also, how do I add more fields to the Members detail admin area? ie: title, phone number, logo picture/

You can do so from perch/templates/members/member.html. This where you'd add the field for the member's header for example.

As far as I'm aware you can't upload images/files to the member's profile. So the header in the above solution will have to be a text field containing the path to the image.

b lewis

b lewis 0 points

You are so much help!

I have added the image field to upload the header but it won't stay and I get this as the output <!-- Undefined content: Members Header -->

Hussein Al Hammad

Hussein Al Hammad 105 points
Registered Developer

As far as I'm aware you can't upload images/files to the member's profile. So the header in the above solution will have to be a text field containing the path to the image.

So you'd have to add a text field and add the path there for e.g. /login/resources/lacysheader.jpg

<perch:members type="text" id="header" label="Header Image Path" />

<!-- Undefined content: Members Header -->

This is because you have not defined the content for the region perch_content('Members Header'). Go to the page in the control panel and you should see a new editable region.

b lewis

b lewis 0 points

This will most likely work for what I need, but I can not for the life of me get the code wrapped right. How do I incorporate your code into mine? The only thing that changes is between data-image-src=" "

<section class="">
  <div class="container">
    <div class="parallax-window" data-parallax="scroll" data-image-src="<?php perch_content('Members Header'); ?>" sizes="100vw"></div>
  </div>
</section>



if (perch_member_logged_in()) {
$member_header = perch_member_get('header');

if($member_header) {
// special header for this member
echo '<img src="' . $member_header . '">';
} else {
// default header for logged in members
perch_content('Members Header');
}


} else {
// regular header for non-members
perch_content('Non-Members Header');
}
Hussein Al Hammad

Hussein Al Hammad 105 points
Registered Developer

You can do something like this:

<section>
  <div class="container">
    <?php
    if (perch_member_logged_in()) {
      $member_header = perch_member_get('header');

    if($member_header) {
      // special header for this member
      echo '<div class="parallax-window" data-parallax="scroll" data-image-src="' . $member_header . '" sizes="100vw"></div>';

    } else {
    // default header for logged in members
      perch_content('Members Header');
    }


    } else {
      // regular header for non-members
      perch_content('Non-Members Header');
    }
    ?>
  </div>
</section>

And the template you use for the regions Members Header and Non-Members Header can include the .parallax-window markup in there:

<div class="parallax-window" data-parallax="scroll" data-image-src="<perch:content id="header" type="image" label="Header Image" />" sizes="100vw"></div>