Problems, need help? Have a tip or advice? Post it here.
17 posts Page 1 of 2
Hi!

I have a blog page, and a profile page with a bunch of clonable pages inside.
In the profile page of a person, I need to check if that person is also a blog author, and if so, add a link in the profile page to the blog page, but showing only the articles from that author.

There's a "Author bio" field in all profiles, but only the persons who are author have content in this field.

So I was thinking of something like

Code: Select all
<cms:pages masterpage='article.php'>
  <cms:if "<cms:not_empty profile_bio />" >
    <a href="<cms:show k_page_link />">See all articles from this author</a>
  </cms:if>
</cms:pages >


But it shows 15 "See all articles from this author" links, since there's a total of 15 articles in the blog.
How can I make this link to a page where it would display a list of the author's articles only?

Thanks!
Hi,

Could you please post the definition of the 'profile_bio' field in article.php?
Currently how are you filling this field with the author's info?

Please let me know. Thanks.
Hi KK,

Here's the code for the profile_bio region :

Code: Select all
<cms:editable type='richtext' name='profile_bio' order="-4" label="Author bio


It's just a text area that I fill with the bio of the author that I fill manually in the admin section.
I have over 100 profiles in the Profile page, but only around 5 or 6 of them are actual articles authors.

Thanks!
Thanks.

If I am correct in assuming that article.php (in which this region is defined) is the template used to create the blog entries, right?

If so, suppose an author creates 100 blog articles, since the region appears in each blog entry, will you enter the bio text into every single of those 100 pages? What happens if you wish to modify the bio of a particular author? Will you search for those 100 pages and modify the info in each of them?

This is precisely the problem that is solved by 'relationship' - you define the bio in the profile template instead. Now since each author has only a single profile page, this bio text needs to be entered only once. On the article side, create a many-to-one relation between the articles and the author profile. So now while creating a blog entry you can select the name of the author from a dropdown.

This way we can easily find all articles related to a particular author, find the number of articles written by a particular author etc. fairly easily.

I suggest you please take the time to study the relationship feature (http://docs.couchcms.com/concepts/relationships.html) and let me know what you think about it for your use-case.
Hi KK,

Thanks for the info.
I've added the profiles list into the Article section in the admin using :

Code: Select all
   <cms:editable type='relation' name='article_author' masterpage='profile.php' has='one' />


And now, when I'm creating a new article for the blog, I can choose who's the author from all the persons in the profile page.
That's great.

But now, I need to show on the profile page of "John Doe" for example, a button saying "See John Doe articles from the blog", but this button should appear only if he actually has any articles in the blog section. And we can see if he has articles in the blog if an article got the "article_author" field with his name selected.

Once you click the button, it needs to send you to a page where all articles from John Doe would be displayed. But only his articles.

How can I do that? I'm kind of lost here.
Thanks!
Hi :)
There is such a thing in cms:pages tag as k_paginated_top. This is a variable which appears within cms:pages if and only if there are pages. And 'top' also means it appears ONCE.

So if you have <cms:pages custom_field="author='John Doe'" limit='1' paginate='1' > which will check if there are pages, then what happens?

If there are some, at list 1 article of John, then you can post that message with a link like this:
<cms:if k_paginated_top >
See all articles of John - link
</cms:if>

There are other variables inside cms:pages that help to show total number of articles by John. Place <cms:dump /> to see them.

Next, if you list articles of all authors and wish to place a link below each abstract, if there are related articles of current guy, then its a different story but principle is the same. Check cms:reverse_related_pages, cms:related_pages. You may also wish to check a count of pages differently with param count_only='1'.

Regards :D
Join COUCH:TALK channel here https://t.me/couchcms_chat
Ryazania — a framework to boost productivity with Add-ons viewtopic.php?f=2&t=13475
Support my efforts to help the community https://boosty.to/trendo/donate
Thanks trendoman,

I understand some parts of what you said, but I don't understand where or what should go "where" in the code.
I have a article.php page, that is the clonable page for blog posts, and profile.php page, that is the clonable page for all the users profiles.

Like I said earlier, I got
Code: Select all
 <cms:editable type='relation' name='article_author' masterpage='profile.php' has='one' />


In the Article page. So in the admin section, when editing or creating a new article for the blog, I can choose what profile is linked to this article.

My "author bio" field is using the following code :
Code: Select all
<cms:editable type='richtext' name='profile_bio' order="-4" label="Author bio"/>


I want it to detect if a user profile is selected somewhere in the article pages. If so, add a link to see all his blog posts.

Thanks a lot!
@larin555, I can see the stumbling blocks you seem to be facing.
Don't worry, though. With relations in place we can implement both the use-cases you mentioned without much trouble.

Could you please grant me a day? I'll try to explain in detail exactly what needs to be done.

Thanks.
Hi KK,

Thanks!
Can we talk about it tomorrow? (Sept 2nd)
Please tell me at what time, and I'll add you on Skype.

Thanks again
Hi larin555,

Here is the promised solution.
Let us tackle first the articles template listing only posts related to a particular user.

The list-view of your article.php template should already be listing all blog posts using some variation of the following code -
Code: Select all
<cms:pages masterpage='article.php' limit='10'>
    <h2><cms:show k_page_title /></h2>
</cms:pages>

In your setup, the article template is related to the profile.php template through a region named 'article_author'.
Let us now bring that region into the code above to make it list posts of only a user with profile named 'john-doe' -
Code: Select all
<cms:pages masterpage='article.php' limit='10' custom_field="article_author=john-doe">
   <h2><cms:show k_page_title /></h2>
</cms:pages>

I don't think it'd be difficult for you to understand the modified code above.

Of course, the code above will always show posts of user 'john-doe' as we have hard-coded that name in it.
Let us make it flexible by making the code dynamically take the user-name from the URL (i.e. we should be able to supply any user-name through the URL by adding it as a querystring parameter). Here is how we do it -
Code: Select all
<cms:set my_user="<cms:gpc 'user' method='get' />" />
<cms:if my_user >
    <cms:set my_filter="article_author=<cms:show my_user />" 'global' />
</cms:if>

<cms:pages masterpage='article.php' limit='10' custom_field=my_filter>
   <h2><cms:show k_page_title /></h2>
</cms:pages>

in the code above, we are checking the URL used to access the current template for a querystring parameter named 'user' and then using whatever value is specified in it to filter our listing.

To test it out, if the current URL happens to be
http://www.yoursite.com/article.php
make it
http://www.yoursite.com/article.php?user=jane
and now when you access the template listing it will show it filtered by 'jane'.

So that now gives us the ability to manipulate the URL dynamically.
Use a different user name as the parameter and the listing should show posts related only to that user e.g. the following will show a listing of only posts related to 'sherlock-holmes'
http://www.yoursite.com/article.php?use ... ock-holmes

OK, with that done we can switch our attention to the profile.php template.
I need to show on the profile page of "John Doe" for example, a button saying "See John Doe articles from the blog".. Once you click the button, it needs to send you to a page where all articles from John Doe would be displayed. But only his articles.
We can do that now simply by adding the user name to the link leading to the articles listing we saw above. Example -
Code: Select all
<cms:if k_is_page>
    <cms:set my_article_template_link="<cms:link 'article.php' />" />

    <a href="<cms:add_querystring my_article_template_link "user=<cms:show k_page_name />" />">See <cms:show k_page_title /> articles from the blog</a>
</cms:if>

but this button should appear only if he actually has any articles in the blog section.
One way of doing that would be to first find out the count of posts related to the user and then conditionally output the button as follows -
Code: Select all
<cms:if k_is_page>
    <cms:set my_count_of_posts="<cms:pages masterpage='article.php' custom_field="article_author=<cms:show k_page_name />" count_only='1' />" />

    <cms:if my_count_of_posts >
        <cms:set my_article_template_link="<cms:link 'article.php' />" />
       
        <a href="<cms:add_querystring my_article_template_link "user=<cms:show k_page_name />" />">See <cms:show k_page_title /> articles from the blog</a>
    </cms:if>
</cms:if>

I think that should cover both the use-cases you had.
Hope it helps.
17 posts Page 1 of 2