ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Making a site more efficient {58512}

December 12, 2011 4:27pm

Subscribe [2]
  • #1 / Dec 12, 2011 4:27pm

    Paul Hansen

    2 posts

    About a year and a half ago I coded a site (http://www.flyshop.nw) into EE 1.6.7.  I created a template for each page of the site.  I also created 2 weblogs (not embedded weblogs for nav, footer, css, etc.) for each template. One weblog for the content and one for the sidebar. Each page has several weblog entries.

    Since then I have been told there is a much more efficient way to code the site that would involve one or two templates and one or two weblogs (besides embedded weblogs) for the whole site.

    I bought Leon Murphy’s and Michael Boyink’s books and have read about url segments, conditional statements, weblog attributes, etc., but some how I am not quite getting how to code a single template to create several pages from one or two weblogs.

    I hope this makes sense and any help would be much appreciated.

  • #2 / Dec 13, 2011 5:01pm

    Dan Decker

    7338 posts

    Hi Paul Hansen,

    Sure thing!
    You could use the {segment_3} variable to set which weblog to call up.

    Say you have this URL:

    <a href="http://your.site.com/site/content/news">http://your.site.com/site/content/news</a>

    You would set up a template group named “site” and then crete a template in that group named “weblogs”.
    Your “weblogs” template could look like this:

    {exp:weblog:entries channel="{segment_3}" limit="10"}
    <h2>{title}</h2>
    <p>{body}<br />
    {/exp:channel:entries}

    This would pull 10 entries from the “news” weblog because “news” is the value of {segment_3}. If you wanted a different weblog, say “sports”, then the template would pull 10 entries from the “sports” weblog.
    If you wanted to display any single entry from a weblog, your URL would look similar to this:

    <a href="http://your.site.com/site/weblog/sports_headline">http://your.site.com/site/weblog/sports_headline</a>

    Then you would have a template to display a single entry:

    {exp:weblog:entries limit="1"}
    <h2>{title}</h2>
    <p>{body}<br />
    {/exp:channel:entries}

    This template will display only the “sports_headline” entry because ExpressionEngine detects the url_title variable in {segment_3}

    Does that help answer you question?

  • #3 / Dec 13, 2011 5:58pm

    Paul Hansen

    2 posts

    First thanks so much for answering.  I was beginning to wonder if I was making any sense.

    I think what you have said starts to answer my problem. Let me see if I can give more detail.

    For the website I have a template for each page, such as “index” for the homepage, “about” for the about page, “classes” for the classes clinics page, etc.

    For the index template, I use two weblogs to feed it data. They are “Home Content” and “Home Rightbar”. For the about template, I have weblogs called “Classes Content” and Classes Rightbar” and so forth for every page.

    Many of the “Content” weblogs have the same entry fields. All but one of the “Rightbar” weblogs have exactly the same entry fields.  Isn’t this redundant?  Could I feed all the templates from one or two weblogs? If so, what code would allow me to do it?

    Here is the code from “classes” template

    {embed="embeded/html_header"}
    
    <body  id="body_classes">
     
    <div id="wrapper">
     
     {embed="embeded/header_nav"}
     {embed="embeded/sidebar_nav"}
     
     <div id="content">
      
      <div id="column522">
      
             {embed="embeded/classes_intro"}
              <hr >
       
    {exp:weblog:entries weblog="class_content" limit="" disable="categories|members_data|pagination|trackbacks" sort="asc"}
    
    {class_photo}
    <h5 class="headBack">{class_heading}</h5>
    {class_description}
    <table class="classes">{class_table}</table>
    <hr >
    
    {/exp:weblog:entries}
    
       
     <div>/div>
      
     </div><!-- end #column522 -->
     
     <div id="column220">
      
      
    
    <div class="boxFirst">
    
    {embed="embeded/classes_clinicIntro"}
    
    {exp:weblog:entries weblog="class_rightbar" limit="" disable="categories|members_data|pagination|trackbacks"  sort="asc"}
    
    <br>
    {if referenceHead !=""}
    <h6>{referenceHead}</h6>
    <p>{/if}</p><h5>{title}</h5>
    <p>{teaserContent}<br />
    {if second_photo !=""}<br />
    {second_photo}<br />
    {/if}<br />
    {/exp:weblog:entries}</p>
    
    <p></div><!-- end .box --><br />
       <br />
     </div><!-- end #column220 --><br />
     <br />
      <div class="clear"></div></p>
    
    <p>{embed="embeded/footer"}<br />
       <br />
     </div><!-- end #content --><br />
     <br />
        </div><!-- end #wrapper --><br />
    </body></p>
    
    <p></html>

    If I replace “{exp:weblog:entries weblog="class_content". . ." with the coding below, then put classes in the title entry (which create a url) of a weblog or channel, will the template coding create a page?

    {exp:weblog:entries weblog="{segment_3}" limit="10"}
    <h2>{title}</h2>
    <p>{body}<br />
    {/exp:weblog:entries}

    It seems like more is needed, like if this says “homepage” then create a homepage.

    Several of my templates are the same. Can I make two or three pages from one template, feeding from the one or two weblogs?  I am wondering if I can make the site work with just three main templates. Is this confusing? If so, let me know what information I can supply.

    Thanks much again.

    Paul

  • #4 / Dec 19, 2011 3:26pm

    Dan Decker

    7338 posts

    Hi Paul,

    There is nothing wrong with the way you are doing things as long as you are getting the results you are looking for. That’s the beauty of ExpressionEngine!

    If you have your 6 weblogs, and most of the content structure is identical, you can whittle it down to 2 weblogs. 1 for content and 1 for right-bars, then delegate the different sections using categories. So you would create A category for your homepage, your classes, etc. In the respective parts of your template, you would retract your weblog tags to those categories.

    Your example here:

    {exp:weblog:entries weblog="{segment_3}" limit="10"}
    <h2>{title}</h2>
    <p>{body}<br />
    {/exp:weblog:entries}

    Would work, indeed! But you are correct in that you would have to make sure to include a third segment throughout your site.

    Just to make sure I’m not leaving you in a technical lurch, is everything working as you expect?

  • #5 / Dec 19, 2011 6:24pm

    Paul Hansen

    2 posts

    Thanks. I think I understand and am going to try it.

    I will get back to you and let you know if it has sunk in.

    After it works out, my next question will be how to cut down on the number of main templates. Many of them are the same as well and I think I could get by using two or three rather the 5 or 6.

    Really appreciate your help.

  • #6 / Dec 21, 2011 1:12am

    Kevin Smith

    4784 posts

    Sounds good, Phil. As a boost, you might look at moving those bits of your templates that are all the same into Snippets and Embeds, as the needs allows.

    Let us know how you get along!

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases