Page 1 of 2

Contextual 'Recent Entries' plugin

Posted: Thu Jun 08, 2006 10:54 am
by Ianardo
Hi Guys

Is it possible to tweak the 'Recent Entries' plugin so that it only appears on certain pages?

Example: My client Balloonview Has categories called

Contract Publishing
Marketing Solutions
Original Copywriting
Charity Marketing

He also has an intro page to each category as a static page which is linked to in an html nugget in the sidebar.

What he has requested is that when you click the link and the category intro page appears, that a 'Recent Entries' list for that category should appear in the sidebar as a link to all the pages in that category. It should also stay whenever you visit a page within that category.

Do you understand what I mean?

Re: Contextual 'Recent Entries' plugin

Posted: Thu Jun 08, 2006 12:19 pm
by garvinhicking
Hi!

Yes,you can do that.

When a sidebar plugin returns "false" in the generate_content method, its output is not shown.

Thus you only need to create your own plugin by duplicating the recententries one and renaming it (both classname + php file) and then insert your code within the generate_content method:

Code: Select all

if ($serendipity['GET']['category'] == 2 || $serendipity['GET']['category'] == 3) {
    return false;
}
HTH,
Garvin

Posted: Thu Jun 08, 2006 12:32 pm
by Ianardo
Cool. Thanks Garvin, i'll try that.
:)

Posted: Fri Jun 09, 2006 10:38 am
by Ianardo
Great. That worked a treat, thanks.

Now, how can I hide ALL of the recent entries when i'm showing a static page?

Posted: Fri Jun 09, 2006 11:04 am
by garvinhicking
Hi!

If a staticpage is set, the "staticpage_pagetitle" variable will be set. Thus you could check that via:

Code: Select all

$pt = $serendipity['smarty']->get_template_vars('staticpage_pagetitle');
if (!empty($pt)) return false;
This will exit the plugin if a staticpage is displayed.

Regards,
Garvin

Posted: Fri Jun 09, 2006 12:23 pm
by Ianardo
Thanks Garvin.

Is there a way to make it not appear when ANY static page is showing, rather than having to name the page/s ?

Cheers

Posted: Fri Jun 09, 2006 12:30 pm
by garvinhicking
Hi!

Yes, there is a way. It's the code I already wrote. :-)

Best regards,
Garvin

Posted: Fri Jun 09, 2006 12:32 pm
by Ianardo
:oops:

:D

Posted: Fri Jun 09, 2006 1:33 pm
by Ianardo
That worked perfectly, thank you.

Now. Back to the previous question.
If you look at the site i'm working on: http://www.balloonview.com/lobby2 that the menu on the right links to static pages.
The static pages each have a link underneath saying "Click here to see examples of our work"
When you click this the category appears and the category menu appears at the right - all great so far and exactly what I want.

When you navigate to each story using the category menu the story appears, but also all the other category menus!

Could you tell me how to get around this please.
Hopefully this will be my last query.

Cheers
Ian

p.s. if you're ever in Hastings I owe you several beers! :-)

Posted: Fri Jun 09, 2006 1:58 pm
by garvinhicking
Hi!

Yes, that's right, because in individual entry view, an entry could be contained in multiple categories and thus the Category ID is not set.

You will then need to modify the plugin to check if $serendipity['GET']['id'] is set, and if it is, use serendipity_fetchEntry() to fetch that entry [this will cost performance!!] and inspect what category it is assigned to using the same check as before.

If you want so save performance, you'd need to create a custom PHP event plugin that listens on the entry_display hook, where it can evaluate the category data of a single entry.

Or you could use the $serendipity['smarty']->get_template_vars('entries') function and introspect that array to get the category id.

Sadly this is a bit beyond the scope of my time schedule, so I can't code that for you...maybe you'd like to look into the "serendipity_event_sidebarhider" plugin. I think I remember that the functionality of hiding sidebars in specific categories was built into that.

(checking)

Ah, yes it is. It also points me to the way using $GLOBALS['entry'][0]['categories'][0] for checking the first category id of a single entry :-D


Best regards,
Garvin

Posted: Fri Jun 09, 2006 2:30 pm
by Ianardo
Thanks Garvin - i'll give the plugin a go.
The rest sound horrendously complicated!

Posted: Fri Jun 09, 2006 2:38 pm
by Ianardo
Hey!!! That was fabulous!
Really quick and useful.

Thank you so much - I now declare the Balloonview project Finished!


http://www.balloonview.com/lobby2

Posted: Fri Jun 09, 2006 7:39 pm
by carl_galloway
Ian thats a very nice looking site and I love what you've come up with by changing the plugin, I might take that on board myself. You know when you look at this site you would never know it was powered by serendipity

Posted: Fri Jun 09, 2006 8:04 pm
by Ianardo
Thanks Carl
I must say, Serendipity has been a fabulous bonus for me. I'm no programmer but I love putting together sites in it.
I can give clients far more sophisticated sites than I could when I was working in html.
How do you guys make a living?
I know how long this stuff takes!

Posted: Fri Jun 09, 2006 8:35 pm
by carl_galloway
Ian, I don't make a living from Serendipity... I'm a life coach, but I only take on entrepreneurial clients these days, career management just doesn't let me build the relationship with the client that I want, and coaching/counselling is a two way street despite rumors to the contrary. I'm not even a trained designer, just an enthusiastic amateur. Ceejay (my other half) could probably take on clients if anyone liked her work and of course I'd happily help with coding.

Most of the professional designers who use Serendipity as the engine for their clients actually never admit it, and in fact many remove all reference to serendipity in the credits and style names. Unfortunate, but that's open source for you, and I think if they were exposed they would be terribly embarassed, but what gets me the most is I donate my time and I find it off-putting that many of the pro designers are making money from this without giving anything back to the community. If every pro designer gave just one professionally crafted template back to the community they would get the backlinks, we would probably have another 20 or so templates available, and the general excitement surrounding serendipity would be...

So if you plan to make money from Serendipity you'll find that anyone on these forums who is honest about making money by using it will be in the same boat, also not making much money - what you need to do is hunt down the pro's who keep silent, and then try to emulate them. Some of them sell 'complete' websites using Serendipity for many thousands of pounds or dollars.