• I just took over maintenance of a highly custom theme for a client.

    The site is news-themed site with all the pages having a three column layout, with each column being widget enabled. (You can see a demo of the site here: https://fishwrapped.com/). The client basically adds a bunch of widgets to each pages columns for display (mostly RSS widgets and a custom RSS feed widget plugin).

    The way the theme developer made the site is not manageable in my opinion and I want to clean it up. The original dev made 100 different page templates all named in sequence (e.g. RSSPage1 … RSSPage100). Each template is exactly the same inside except for the page number. The page number is then used to define the left, middle and right sidebar widgets for that page.

    As you can imagine this is quite unwieldy and a major duplication of code in my opinion. Also, as a serious side effect, when you try to load the Dashboard widgets page, 90% of the time your browser will stall because its trying to load up 100×3 dynamic widgets for placement.

    However, I have been unable to think up a better solution with fewer page templates, that will allow the user to define custom pages and still allow him to have different dynamic widgets on each page.

    Any thoughts or help would be appreciated.

Viewing 12 replies - 1 through 12 (of 12 total)
  • So if I understand this correctly, there are 100 pages, with all their own page-template, and the one differentiating factor is one number.

    Looks like a perfect application for custom fields to me.

    Peter

    Thread Starter cpjolicoeur

    (@cpjolicoeur)

    Peter,

    I agree about using custom fields, and that in fact was my first thought.

    However, that didnt work for this client because he needs to have the ability to use widgets. How can I allow him to setup widgets for each column via custom fields?

    Each template is exactly the same inside except for the page number. The page number is then used to define the left, middle and right sidebar widgets for that page.

    In that case you gotta tell us more about this page number you’re referring to.

    Maybe post one of those page templates on pastebin.

    Peter

    Thread Starter cpjolicoeur

    (@cpjolicoeur)

    Ok. I randomly chose the “Page10” template as an example

    https://pastie.org/639378

    The pastie includes the main template and the three “sidebar” templates as well

    If it’s only that number ’10’, that can easily be replaced by a variable (which could come from a custom field).

    <?php include(TEMPLATEPATH."/RSSPages/Page".$number."Left.php");?>

    How many different combinations of sidebars do you have?

    Peter

    Thread Starter cpjolicoeur

    (@cpjolicoeur)

    again, that was my original though as well, each page could (and will ) have different sidebars.

    one page might have 2 rss widgest on the left, 3 rss in the middle, 1 rss and 1 text on the right (for an example).

    the next page might have 1 rss left, 2 rss in middle with 1 text, and 2 rss on the right.

    The feed list and output of each pages rss widgets will be different. the same widget isnt duplicated in multiple places.

    And using a $number variable like in your example really doesnt do anything special for me. I still would be required to have the 100 pages and 100×3 associated sidebar pages with them already created in the filesystem.

    but wait…. backup.

    Widgets are assigned to sidebars, which are then inserted in templates.

    That means that you have a certain set of sidebars, and the widgets are assigned to these sidebars from the management console.

    From your page templates you insert these sidebars, depending on the page number, right?

    But I now see your problem: the content itself is also included.

    I still think this can be done via custom fields, but it’ll take a bit more work than I anticipated.

    Peter

    Thread Starter cpjolicoeur

    (@cpjolicoeur)

    the problem arises in that each page needs to have its own unique sidebar. I can’t just have one generic “left” “center” and “right” sidebar because then the same content would be displayed on each page.

    Each page needs to be able to have its own unique left, center, and right sidebar to get its own unique content.

    therein lies the problem

    We’re on a different wavelength, I guess:

    a. the sidebars already are predefined in functions.php, or otherwise you would not be able to add widgets to them.

    b. the sidebar (and number of sidebars) is dependent on the page you’re currently viewing, so that’s a variable factor.

    The last part is a perfect application for custom variables.

    How about the content (in page10center for instance): is that static content, or also a ‘sidebar with widgets’?

    Peter

    Thread Starter cpjolicoeur

    (@cpjolicoeur)

    all are sidebar with widgets. every page has no static content. all content for every page comes from the dynamic widgets in the left, center, and right sidebars that are defined in the functions.php file.

    Oke, now that we’ve established that: what exactly were your reasons not to use custom fields (as I come to think of it: since the page template and all of its surrounding functions – the sidebars) all have the same name (number), you could even use the pages postID to name and call these.

    You wouldn’t even have to include anything:

    <!-- begin the loop -->
    if sidebar(postID)-right exists, call that one
    if sidebar(postID)-left exists, call that one
    if sidebar(postID)-center exists, call that one
    <!-- end the loop -->

    I think a single page.php could do the trick.

    Peter

    Thread Starter cpjolicoeur

    (@cpjolicoeur)

    I have no problem using custom fields. I do it all the time in themes I write and I fully understand how to use them and how they could be used in this case.

    The big problem with this theme is the 300+ sidebars that are defined in the functions.php file for this theme. When the user actually tries to go to the widgets page in the WP Dashboard, all 300+ of these sidebars have to get loaded which causes serious slowdowns (and sometimes even crashes) in the dashboard.

    I guess the big question is is there a way to dynamically create new sidebars as you need them. For instance, I already have created and setup five unique sidebar configurations and now I determine that I need a new one. Is there a way to dynamically add a new one?

    I guess, I could store the current number in the database as a theme option, and then have a function in functions.php that loops through the count I need to create new ones??

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘Trying to Avoid duplication in theme file layout’ is closed to new replies.