Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Custom Field or New Component?
#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


Messages In This Thread
Custom Field or New Component? - by designthing - 2011-06-12, 22:21:14
Custom Field or New Component? - by Angryboy - 2011-06-12, 23:20:56
Custom Field or New Component? - by designthing - 2011-06-13, 04:54:30
Custom Field or New Component? - by designthing - 2011-06-15, 20:55:38
Custom Field or New Component? - by designthing - 2011-06-16, 00:11:26
Custom Field or New Component? - by Angryboy - 2011-06-16, 01:03:09
Custom Field or New Component? - by Angryboy - 2011-06-16, 05:06:39
Custom Field or New Component? - by Angryboy - 2011-06-16, 05:25:52
Custom Field or New Component? - by Zegnåt - 2011-06-16, 05:37:36
Custom Field or New Component? - by mvlcek - 2011-06-16, 05:40:28
Custom Field or New Component? - by Angryboy - 2011-06-16, 05:47:34
Custom Field or New Component? - by designthing - 2011-06-16, 23:48:41
Custom Field or New Component? - by mvlcek - 2011-06-16, 23:59:43
Custom Field or New Component? - by designthing - 2011-06-17, 20:19:02
Custom Field or New Component? - by mvlcek - 2011-06-17, 21:36:05



Users browsing this thread: 2 Guest(s)