WordPress.org

Ready to get started?Download WordPress

Forums

Trying to Avoid duplication in theme file layout (13 posts)

  1. cpjolicoeur
    Member
    Posted 5 years ago #

    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: http://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 100x3 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.

  2. Peter Boosten
    Member
    Posted 5 years ago #

    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

  3. cpjolicoeur
    Member
    Posted 5 years ago #

    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?

  4. Peter Boosten
    Member
    Posted 5 years ago #

    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

  5. cpjolicoeur
    Member
    Posted 5 years ago #

    Ok. I randomly chose the "Page10" template as an example

    http://pastie.org/639378

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

  6. Peter Boosten
    Member
    Posted 5 years ago #

    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

  7. cpjolicoeur
    Member
    Posted 5 years ago #

    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 100x3 associated sidebar pages with them already created in the filesystem.

  8. Peter Boosten
    Member
    Posted 5 years ago #

    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

  9. cpjolicoeur
    Member
    Posted 5 years ago #

    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

  10. Peter Boosten
    Member
    Posted 5 years ago #

    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

  11. cpjolicoeur
    Member
    Posted 5 years ago #

    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.

  12. Peter Boosten
    Member
    Posted 5 years ago #

    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

  13. cpjolicoeur
    Member
    Posted 5 years ago #

    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??

Topic Closed

This topic has been closed to new replies.

About this Topic