Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Custom Field or New Component?
#1
As a newbie and learning GS, please can someone explain the difference between these two options: When should i use a Custon Field via the i18N Plugin and when would it be better to create a new component?
Can anybody give me a few examples of such scenarios. I would like to create a bit of variety on my pages with maybe 3 call to action boxes on homepage and sidebar with a twitter feed and/or latest news on another page. I am not sure how to do this and what is best practice. I am reading WIKI but still unsure.
Thanks in advance :-)
Reply
#2
CustomFields are for when you have page specific fields that could apply for a multitude of pages. For example, you don't want to have a new component for every subtitle of every page you make or every excerpt of a news article (if you use i18n Search as a news plugin), so a CustomField is most suitable in that instance. These let you define relatively small pieces of information, but aren't really advised for direct HTML output or scripting.

Components are for when you need certain pieces of coding to be part of the template you're currently using (or in some cases, with mvlcek's DynPages plugin, outputting them on specific pages). So if you have HTML coding from an external site that you want to implement cleanly into your layout, or external Javascript etc..., components are the way to go. Scripting is friendliest via components, however these need PHP 'if' statements (or a separate template page) to make them page specific, so in contrast to CustomFields, these are more universal for pages. You only need to define them once for them to show up the same on all pages, whereas a CustomField needs to be defined for each individual page - that is the core difference.

Your situation sounds like you just want a few components running, some of which will be just for the homepage and another for the 'Latest News' page. Have a read of this topic for advice on page specific components in your template, and stick to simply using components if you have about 3 pages in particular that need special treatment. In essence, you'll be producing a PHP IF string that tells the browser "when the slug is index, the sidebar should output X component(s); when the slug is updates (just an example), the sidebar should output Y component(s); else the sidebar should output Z component(s) on any other page".

If it were a case of you needing a different component on every page and you had a large number of pages (for example having a multitude of available languages for your site), this method would prove messy with how many if statements you produce. Towards bottom of that topic in the link above there is an explanation by mvlcek of integrating both the CustomFields and components features to get a workable and practical solution.

Hope this helps you!
Reply
#3
Thankyou Angryboy.
I really appreciate your time in explaining that. I have looked at the article link about Guru Zegnats Function solution and trying to Get IT! Still goes over my head.
As a designer, i need to know whats possible. I think the WIKI could really do with more clarification for those with little or no php knowledge. Diagrams and examples are also a big help when words become too techy.
As its named GetSimple Cms its gotta be...simple!
Thanks again
PS I am buying Dummies Guide to PHP :-P
Reply
#4
Well, i am still stumped by this Custom Field Plugin i18N. I guess i need to be held by the hand while mummy shows me big diagrams of how to get this working. I'd like to have a section of text showing on sidebar and having variations from page to page. So i assume this plugin is the answer. But how do i write out this custom field? And which php code snippet do i add to the template?
Will i ever understand this. Teeth grindingly yours.

Designthing :-(
Reply
#5
designthing,

designthing Wrote:I'd like to have a section of text showing on sidebar and having variations from page to page.
Here's what we at get-simple.de do to achieve what you're asking for. We ourselves didn't want GS's features list on every page, but only the homepage. This approach can be used to show one piece of text on several pages, too. Please read on.

We use simple PHP in the template, in this case sidebar.php in the Innovation theme. We placed the following code where we wanted GS's features block to appear in the sidebar. Notice that the component sidebar which has the feature list, is available out-of-the-box with the Innovation theme.

Code:
<?php

    /* If it's the homepage ... */
    if (return_page_slug()=='index') {

        /* ... display the HTML for the sidebar section and pull in the component named 'sidebar' */
        echo '<div id="features" class="section">';
        get_component('sidebar');
        echo '</div>';

    /* If it's NOT the homepage but any other page ... */
    } else {

        /* ... don't display anything in this place at all */
        echo '';        

    }

?>

Adapt this to suit your own page slugs. This should get you going. If you want a component to appear on, say, the homepage and the blog page, write

Code:
if (return_page_slug()=='index' || return_page_slug()=='blog')

instead of only

Code:
if (return_page_slug()=='index')

This approach could certainly be improved upon, but it does what we want for now.

Hope this helps!
Reply
#6
Thanks Polyfragmented.
I am beginning to see the light here. I am experimenting with the cardinal theme. So, the php would call in that particular component only if the condition is true - like index.php...thats a great help.
If only i knew php. Still gotta buy that book!
Reply
#7
The php would call that component with regards to whether the page slug matches the conditions. So if the page slug is index, it calls the sidebar component, if the slug is anything else (with polyfragmented's framework), a blank space is output.

A book isn't entirely necessary to understand just some basics to get you going - Google some online tutorials to help you.
Reply
#8
Angryboy,

I'm open for improvements on the approach. I'm just crudely hacking my way around PHP anyway.
Reply
#9
Your way is one of the more straightforward approaches to doing this, I believe. There are other, more concise methods (Zegnåt knows of), but they require more understanding to implement properly.
------
Here is how I would go about it, designthing (a bit more verbose perhaps than polyfragmented's).

On your template.php file, find the section for your sidebar. Implement this coding.

Code:
<!--[sidebar]-->
<div id="sidebar">
<?php
/* Credit to ccagle8 for this code, which was modified */

if ( return_page_slug() == 'index' ) {
    get_component('sidebar-index');
    /* IF the page slug is 'index', the 'sidebar-index' component will be output */ }

elseif ( return_page_slug() == 'updates' ) {
    get_component('sidebar-updates');
    /* IF the page slug is 'updates', the 'sidebar-updates' component will be output */ }

    /* You can add on more page-specific sidebars here by adding more elseif statements! */

else {
    get_component('sidebar');
    /* IF the page slug is anything else, the generic 'sidebar' component will be output */ }
}
?>
</div>
<!--[/sidebar]-->

Then ensure that you have three separate components created: one called 'sidebar-index' (containing only the coding needed for the index page's sidebar), another called 'sidebar-updates' (this time only for the Update page's sidebar) and 'sidebar' (which will be shown for any other page that hasn't been specified by the (ELSE)IF statements).

If you wish to add more page-specific components, just copy-paste this piece of coding:

Code:
elseif ( return_page_slug() == 'SLUG' ) {
    get_component('sidebar-SLUG'); }

Before the final 'else' statement (which is where I put the note in the code stating that you can add more sidebars), replacing the word SLUG with your page slug and create a corresponding component for the appropriate sidebar.

Also, there isn't a need for having an 'echo' command to output a blank space, because you can simply have your appropriate 'sidebar' component (be it slug-specific or generic) not have any text in it, and it shall behave in the same way.

Hope this helped. There is another way of doing this so that you have the components working as widgets, and its a case of the if statement pulling the correct combination of components - this would be in situations where not all pages have the same sidebar, but certain elements from the sidebar will be shared. If that is what you are wanting, have a shot at manipulating the coding we've shown to you, and if you need assistance, we are happy to provide it.
Reply
#10
Angryboy,

your approach fits designthing's requirements more closely and is more modular, so way to go. I'm going to shamelessly rip it off. ^^
Reply
#11
Thank you Smile

One huge flaw I've noticed in this approach however is when it comes to child pages. If someone wants to have child pages all with a specific sidebar then you'd need to use return_parent() instead of return_page_slug(). But does that template tag exist in GetSimple?
Reply
#12
Angryboy Wrote:One huge flaw I’ve noticed in this approach however is when it comes to child pages. If someone wants to have child pages all with a specific sidebar then you’d need to use return_parent() instead of return_page_slug(). But does that template tag exist in GetSimple?

The wiki does not really make this clear but when you pass FALSE to the get_parent() function it will return the value instead of write it out.

Something like the following should probably work, although I didn’t test it:
Code:
$parentOrSlug = ($p=get_parent(false))?$p:get_page_slug(false);
This will make $parentOrSlug contain the parent page’s slug but default back to the page’s own slug if no parent slug is found.
“Don’t forget the important ˚ (not °) on the a,” says the Unicode lover.
Help us test a key change for the core! ¶ Problems with GetSimple? Be sure to enable debug mode!
Reply
#13
designthing Wrote:Well, i am still stumped by this Custom Field Plugin i18N. I guess i need to be held by the hand while mummy shows me big diagrams of how to get this working. I'd like to have a section of text showing on sidebar and having variations from page to page. So i assume this plugin is the answer. But how do i write out this custom field? And which php code snippet do i add to the template?

1. If you really want different contents per page in your sidebar, you can do the following:
  • install I18N Custom Fields
  • go to Plugins/Configure Custom Fields in the admin and add a WYSIWYG field named sidebar, title e.g. "Sidebar content"
  • edit each page that should have a special sidebar content, open options and enter the content into the new custom field "Sidebar content"
  • add the following code to your template - instead of <?php get_component('sidebar'); ?>, if you want to replace the sidebar with this content - or before or after it, if you want to display additional content - or into the sidebar component, if you want to add some content inside the sidebar
Code:
<?php get_custom_field('sidebar'); ?>

1a. Alternatively, if you want to replace the sidebar, but pages without any content in this field should use the standard sidebar, use the following in your template (instead of <?php get_component('sidebar'); ?>:
Code:
<?php
if (return_custom_field('sidebar')) get_custom_field('sidebar'); else get_component('sidebar');
?>

2. Another possibility, if you have lots of pages, but only some sidebar variants:
  • install I18N Custom Fields
  • create additional sidebar components for each variant, e.g. "sidebar-products", "sidebar-services", etc.
  • go to Plugins/Configure Custom Fields in the admin and add a dropdown field named sidebarcomp, title e.g. "Sidebar component". Add each possible sidebar component's name in the field below the "dropdown" type, one per line, e.g.
Code:
sidebar
sidebar-products
sidebar-services
  • Edit each page and select one of the possible sidebar contents in the dropdown field "Sidebar component"
  • replace <?php get_component('sidebar'); ?> in your template with (will show the standard sidebar, if nothing was selected in the page)
Code:
<?php
if (return_custom_field('sidebar')) get_component(return_custom_field('sidebar')); else get_component('sidebar');
?>

3. Or use polyfragmented's approach of course ;-)

The best approach depends on the number of different sidebars and number of pages and if the editor who edits the page should be able to change the sidebar or not.
I18N, I18N Search, I18N Gallery, I18N Special Pages - essential plugins for multi-language sites.
Reply
#14
@Zegnåt: Thanks for clarifying that Smile

@mvlcek: So that's how you use the CustomFields with the components. I was never entirely clear on that, but this makes it pretty evident now. Do you think that a tutorial/article should be written on the various possibilities on creating a functioning sidebar?
Reply
#15
designthing,

hope you're not getting way more info than you can chew, hehe. You should have enough options now though.
Reply
#16
Thankyou ALL for your replies and helpful code hints. I am working on this now. It seems there are a few paths that lead to a solution. I think this knowedge should be available in the WIKI for other users who might never find answers. The Plugins by Mvlcek are amazing but my only criticism is that the documentation is not clear enough to PHP newbies. For example, the Custom Field Plugin 118N i found very vague - what to add in the field boxes, why the default fields were blank, where to put the code and from where to edit. All obvious to you experts and intermediates, but not to me. I did find the News Manager very well documented. Again, the Pagify Plugin stumped me.

Example excerpt from http://mvlcek.bplaced.net/get-simple/pagify:
--------------------------------------------------------------------------------------------------------------------------
specify a tag/keyword _pagify x for your page, where x is the approximate size in bytes, or
call the function pagify_set_size(x) in your template.

To see the full content, add a parameter complete to your page's URL.
--------------------------------------------------------------------------------------------------------------------------

Where do i place _pagify x, what size in bytes- what is that and how do i know? and call function pagify_set_size(X).
Sorry to be a nuisance, but i want to use these great plugins but i cannot because i don't have the ducumentation for newbs like me!
I love Getsimple CMS but its not that simple :-P
Reply
#17
designthing Wrote:Again, the Pagify Plugin stumped me.
...
Where do i place _pagify x, what size in bytes- what is that and how do i know? and call function pagify_set_size(X).

Edit the page (with long content that you want to split into multiple pages), open the page options and enter e.g. "_pagify 1000" (without quotes) in the field Tags & Keywords.

You have to try which number (size in bytes = approximately number of characters) is best for you.
I18N, I18N Search, I18N Gallery, I18N Special Pages - essential plugins for multi-language sites.
Reply
#18
Thanks Mvicek. Works fine now. It splits into pages where i set paragraphs. But the _pagify x value doesn't seem to change anything. Example: I have a page split into 4 paragraphs giving me 4 pages paginated. But the x value whether its 20 or 100 doesn't do anything. Am i missing something?
Reply
#19
designthing,

please address different topics in different threads in the future, okay? Pagify is only marginally related here, at best.

Glad you're making progress, keep going!
Reply
#20
designthing Wrote:Thanks Mvicek. Works fine now. It splits into pages where i set paragraphs. But the _pagify x value doesn't seem to change anything. Example: I have a page split into 4 paragraphs giving me 4 pages paginated. But the x value whether its 20 or 100 doesn't do anything. Am i missing something?

It only splits between toplevel paragraphs/divs
I18N, I18N Search, I18N Gallery, I18N Special Pages - essential plugins for multi-language sites.
Reply




Users browsing this thread: 2 Guest(s)