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.

Including current entry in related entries

June 10, 2008 1:41pm

Subscribe [3]
  • #1 / Jun 10, 2008 1:41pm

    keystone

    21 posts

    Sometimes it is necessary to include the current entry when fetching related entries. For example, I am building a site where I use a categories as site sections. I have a section called Company which has the pages About, Careers, Contact and Partners. All of these pages get assigned to the same category, Company. When someone browses to a Company page, all Company pages should display in the sidebar with the current page highlighted.

    related_categories_mode=“on” almost gets me there, but it excludes the current entry. To workaround this I modified the mod.weblog.php file. For obvious reasons it isn’t desirable to edit modify EE files directly. If anyone knows how to accomplish this in a more elegant way please let me know. This is my first EE mod, use at your own risk. It works great for me, but your milage may vary.

    Starting at line 7173 (in EE 1.6.3), I modified mod.weblog.php as follows to allow for a new parameter, show_current.

    /** ----------------------------------
            /**  Manually set paramters
            /** ----------------------------------*/
            
            $TMPL->tagparams['category']        = $cats;        
            $TMPL->tagparams['dynamic']            = 'off';
            $TMPL->tagparams['rdf']                = 'off';
            
            
            // Set user submitted paramters
            
            $params = array('weblog', 'username', 'status', 'orderby', 'sort');
            
            foreach ($params as $val)
            {
                if ($TMPL->fetch_param($val) != FALSE)
                {
                    $TMPL->tagparams[$val] = $TMPL->fetch_param($val);
                }
            }
            
            if ($TMPL->fetch_param('limit') == FALSE)
            {
                $TMPL->tagparams['limit'] = 10;
            }
            
            // Added option to include current entry
            
            if ($TMPL->fetch_param('show_current') != "yes")
            {
                $TMPL->tagparams['not_entry_id']    = $qstring; // Exclude the current entry
            }

    By default show_current is set no. Set it to yes to show current entry. An example of how this would work in a typical site subnav. I’m using Page URIs, so you may have to adjust accordingly if you aren’t.

    <ul id="subnav">
            {exp:weblog:entries related_categories_mode="on" show_current="yes" dynamic="off" disable="categories|member_data|pagination|trackbacks|custom_fields"}
            <li  {if '<?php echo $_SERVER["REQUEST_URI"] ?>' == '{page_uri}'} class="current"{/if}><a href="http://{page_uri}">{title}</a></li>
            {/exp:weblog:entries}
        </ul>

    The code above shows all the related category entries and adds a “current” class to the current entry.

    Hope this is helpful to someone!

    Brian Morykon

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

ExpressionEngine News!

#eecms, #events, #releases