Coded something up in Couch in an interesting way? Have a snippet or shortcode to share? Post it here for the community to benefit.
3 posts Page 1 of 1
Hello All,

Thought I'd share this little snippet / approach, now someone might have a more elegant solutions but for me this works fines and will be the standard approach I take.

Firstly, let me say the docs gave a great insight into globals.php usage, and KK's help let me clarify an approach.

Secondly, I do completely appreciated the clean admin panel that Couch offers, it lets you paint your own picture on it's blank canvas, and make things super easy for clients. Now, when I started tinkering with this I thought: Hey this would be a plugin in WP or other CMS', however reliance on plugins is a pain sometimes and I have utilised this approach, albeit more convoluted with EE before.

Down to the nitty gritty: I want to be able to give clients the ability to edit META information* for a page they publish (or that is already setup by me). Using the same "global" META (including titles) value in a site is not a great approach for the SEO conscious, however, and some may argue otherwise, I do believe there should be a default value. So, we achieve the default value in the globals by defining default Site title, Keywords and Description.

However, to simply allow more focussed SEO on a page we only need to use a little conditional magic in the header of the site.

The full code with some ropey annotations is below, basically we define the fallback / default META stuff in globals.php then use a simple conditional in there to check if the page.php has values in a defined editable regions, if so they get output instead of the defaults.

The premise is very simple, I don't claim to be a genius, and based on WordPress plugins like All In One SEO - except this is not a plugin and doesn't need to be, its far simpler and takes to seconds to setup if you copy my code snippets.

I hope it's of use to fellow users, any questions PM me and I will get back as soon as possible.

I'd like to add another layer to the conditional for things like News and Events so it does the following conditional logic:

1. Has META been defined in the page editable? - YES then Output, NO? Then move to 2
2. Well, we got some title of the page and probably a page content / body so lets just excerpt that, keywords will be a little harder unless we used a possible future feature like
Code: Select all
<cms:show page_tags />
which could output as default keywords, or just leave blank cos google doesn't care that much.


Anyway the whole code:

Code: Select all

//GLOBALS for the fall back SEO META values
// globals.php where we define core SEO stuff

<cms:editable name='base_seo' label='Base SEO' desc='Set the default SEO Meta Data' type='group' order='99' />
   <cms:editable name='meta_title' label='Meta Title' type='text' group='base_seo' />
   <cms:editable name='company_name' label='Company Name' type='text' group='base_seo' />

   <cms:editable name='meta_keywords' label='Meta Keywords - 7-8 max comma separated' type='text' group='base_seo' />
   <cms:editable name='meta_description' label='Meta Description - 180 words max' type='textarea' group='base_seo' />

//PAGE TEMPLATE DECLARATION for the primary SEO override
// Assumes your template is pages.php for menu maker
// Also use in any clonable or nested pages

<cms:template clonable='1' nested_pages='1' title='Pages'>

<cms:editable name='page' label='Page SEO' desc='Override the default SEO Meta Data' type='group' order='99' />
   <cms:editable name='meta_title' label='Meta Title' type='text' group='base_seo' />
   <cms:editable name='meta_keywords' label='Meta Keywords - 7-8 max comma separated' type='text' group='base_seo' />
   <cms:editable name='meta_description' label='Meta Description - 180 words max' type='textarea' group='base_seo' />


</cms:template>


//HEADER META used in the header.ext
// Assumes you are embedding your header in templates and it is called header.inc - i.e. domainroot/couch/snippets/header.inc
// change the filename.extension to suit your needs
// If your globals.php is named differently please change reference to it below

//WHITE SPACE VERSION

   <title>
   <cms:get_custom_field 'company_name' masterpage='globals.php' />
   <cms:if meta_title !=''> | <cms:show meta_title /><cms:else />
    | <cms:get_custom_field 'meta_title' masterpage='globals.php' /></cms:if>
    </title>
   
   <meta name="keywords" content="
   <cms:if meta_keywords !=''><cms:show meta_keywords />
   <cms:else />
   <cms:get_custom_field 'meta_keywords' masterpage='globals.php' />   
   </cms:if>
   ">
   
   <meta name="description" content="
   <cms:if meta_description !=''><cms:show meta_description />
   <cms:else />
   <cms:get_custom_field 'meta_description' masterpage='globals.php' />
   </cms:if>">   

//MINIFIED VERSION

   <title><cms:get_custom_field 'company_name' masterpage='globals.php' /><cms:if meta_title !=''> | <cms:show meta_title /><cms:else /> | <cms:get_custom_field 'meta_title' masterpage='globals.php' /></cms:if></title>
   <meta name="keywords" content="<cms:if meta_keywords !=''><cms:show meta_keywords /><cms:else /><cms:get_custom_field 'meta_keywords' masterpage='globals.php' />   </cms:if>">
   <meta name="description" content="<cms:if meta_description !=''><cms:show meta_description /><cms:else /><cms:get_custom_field 'meta_description' masterpage='globals.php' /></cms:if>">   








*Some clients, without any SEO education, may hinder themselves by altering these values so when we see user access lock down on fields / editable regions these MEAT fields I would keep away from the client and give to a higher site admin access group.
Thank you Patrick. Great explanation. I'm sure the technique will come in handy to many.

Because the topic is SEO, thought I'd add a little tip of my own (apologies but I don't mean to hijack your thread) -
I'm no SEO expert but I find myself using the following for TITLE:
Code: Select all
<title><cms:get_custom_field 'company_name' masterpage='globals.php' /> | <cms:show k_template_title /><cms:if k_is_page> >> <cms:show k_page_title /></cms:if></title>

Output (e.g. with news.php):
List-view: Company name | News
Page-view: Company name | News >> News item's title

Of course, this can easily be combined with your technique to make it more complete.
KK - no problem :) and your addition would make for a nice "default" title in an kind of listing be it news or events.

I will no doubt revise my initial code as I continue to use Couch, I'm still in my infancy with it but getting quicker by the day to utilise it my my own approach, still loving the flexibility (especially conditionals and logic that speak for them selves in code and don't need explaining - CMS dump is certainly fun to play around with).

There's never a right or wrong way, just an easy and easier, and sometimes better (more efficient) which I am sure I will stumble upon in the next few weeks - on tat note, my first Couch built site should be going live this week hopefully, I'll be sire to submit it to the showcase.
3 posts Page 1 of 1