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


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: 1 Guest(s)