We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 40386
    • 8 Posts
    Hi

    I am using Ditto to create'Blog Categories' for creating a Blog Categories list similar to wordpress.

    I create a list of Categories, display them in the nav bar and when I click on a Category the page displays only those resources that match the category. I use a TV to store the Categories.

    It's working more or less ok: http://tennisfanweb.com

    It looks like crap but that's it's just a dev site so I can figure-out how things work etc.

    I have three questions for you guys:

    1. The TV Input Option Values have to be stored like this:
    cat1==cat1||cat2==cat2||cat3==cat3
    Why do they need to be paired like this?
    I tried this format cat1||cat2||cat3 but it didn't work.

    2. One of the categories is R & D The Category returns zero documents for a search on that. There are definitely docs with that TV value.
    I swapped the ascii code for the '&' but that doesn't work either. Is there a way of handling the '&' character?

    3. In my Ditto I used: &config=`categoryfilter` to grab the clicked-on Category. I pieced it together from various stuff I read but I have no idea why this works. I can't find a definitive description of the values etc My &config file 'categoryfilter' is:

    <?php
    $category = preg_replace('/[^A-Za-z0-9 ]/', '', $_GET['cat']);
    $filter='BlogCategory,' . $category . ',7';
    ?>
    


    I understand the php but I don't understand the format of the values for $filter. Is there documentation for that?
    Also, how come this works when I am not returning anything!

    Thanks to anyone who can help !

    Tony [ed. note: bristol last edited this post 11 years, 9 months ago.]
    • Evolution I presume?

      If this is your first MODX site, maybe you will want to use Revolution. The Articles package will create your blog.

      Just checking, and thought I'd let you know... unless there's a specific reason you're choosing Evolution.
        Frogabog- MODX Websites in Portland Oregon
        "Do yourself a favor and get a copy of "MODX - The Official Guide" by Bob Ray. Read it.
        Having server issues? These guys have MODX Hosting perfected - SkyToaster
        • 40386
        • 8 Posts
        Quote from: frogabog at Jul 04, 2012, 06:36 PM
        Evolution I presume?

        If this is your first MODX site, maybe you will want to use Revolution. The Articles package will create your blog.

        Just checking, and thought I'd let you know... unless there's a specific reason you're choosing Evolution.

        Thanks for the reply. Yeah it's Evolution and the client doesn't want to upgrade to Revo, so we're trying to help them with their Evo instal.

          • 19369
          • 1,098 Posts
          Quote from: bristol at Jul 04, 2012, 05:52 PM
          1. The TV Input Option Values have to be stored like this:
          cat1==cat1||cat2==cat2||cat3==cat3
          Why do they need to be paired like this?
          I tried this format cat1||cat2||cat3 but it didn't work.

          The reason why you need a pair, is that the first value is the one that you are going to see (so it is visible in the manager), the second is the real value, that will be used by your snippets (in this case, by Ditto).

          For example, if you use a checkbox input type, you see this:
          <label><input type="checkbox" value="cat1" />cat1</label>
          <label><input type="checkbox" value="cat2" />cat2</label>
          <label><input type="checkbox" value="cat3" />cat3</label>


          I don't know about the other questions. I actually build the blog in a different way. I simply make categories in the manager tree menu, and add the pages inside, then I build the category menu with Wayfinder and the articles intro section with Ditto.

          My structure of the tree usually is like this:
          +Home
          +Blog
          ++Category 1
          +++Article 1
          +++Article 2
          +++Article 3
          ++Category 2
          +++Article 1
          +++Article 2 (etc..)
          +Contact Us
            • 40386
            • 8 Posts
            hey thanks for the explanation.

            About your method, it looks like a good idea !
              • 19369
              • 1,098 Posts
              This is my code for the blog template, I hope it helps (I use 3 templates, one for each depth, blog template, category template, article template:

              Ditto Call: for the "Blog template"
              [!Ditto? &id=`a` &parents=`[*id*]` &depth=`2` &display=`15` &tpl=`blog-ditto` &orderBy=`createdon DESC` &hideFolders=`1` &paginateAlwaysShowLinks=`1` &paginate=`1`!]
              
              <!-- [Pagination] -->
              [!DittoPageSplit? &id=`a` &output=`1`!]
              <!-- [/End Pagination] -->  


              Chunk: blog-ditto
              <!-- [Blog Intro] -->  
              <article>
                  <header>
                      <h2><a href="[+url+]">[+longtitle+]</a></h2>
              		<!-- [Author Info, Comments, Category] -->
                     	<p>
              			Post by <strong>[[author? &id_author=`[+createdby+]`]]</strong>, [+createdon:date=`%d/%m/%Y`+],
              			[+phx:if=`[[Jot? &action=`count-comments` &docid=`[+id+]`]]`:is=`0`:then=`[[Jot? &action=`count-comments` &docid=`[+id+]`]]`:else=`<a href="[(site_url)][~[+id+]~]#comments-link">[[Jot? &action=`count-comments` &docid=`[+id+]`]]</a>`+]</span>.
              			Category: <a href="[~[[getfield? &docid=`[+parent+]` &field=`id`]]~]">[[getfield? &docid=`[+parent+]` &field=`menutitle`]]</a>
                      </p>
              		<!-- [/End Author Info, Comments, Category] -->	
              	</header>  
              	<!-- [Introtext] -->
                  <p>[+content:character_limit=`260`+]...</p>	
              	<!-- [/End Introtext] -->
                  <div class="clear"></div>
              </article>
              <!-- [/End Blog Intro] -->


              Snippets I've been using:

              DittoPageSplit: with this you can generate the pagination
              <?php
              //only for forum highlighting
              // Place immediately following a Ditto call
              // Based on the function written by Aaron Hall, evilwalrus.org
              // Ditto 2.1 start page fix & PHx workaround: Eol ([email protected])
              if (!function_exists("generatePagination")) {
               function generatePagination($curPage, $totResults, $resultsPerPage) {
                $totPages = ceil($totResults / $resultsPerPage);
                $pagesBefore = $curPage - 1;
                $pagesAfter = $totPages - $curPage;
                $tabArr = array();
                if ($totPages > 15) {
                  if ($pagesBefore > 7) {
                    $tabArr = array(1, 2, 0);
                    if ($pagesAfter > 7) {
                      for ($i=($curPage-4); $i<$curPage; $i++) { $tabArr[] = $i; }
                    } else {
                      for ($i=($totPages-11); $i<$curPage; $i++) { $tabArr[] = $i; }
                    }
                  } else {
                    for ($i=1; $i<$curPage; $i++) { $tabArr[] = $i; }
                  }
                  $tabArr[] = $curPage;
                  if ($pagesAfter > 7) {
                    if ($pagesBefore > 7) {
                      for ($i=($curPage+1); $i<=$curPage+4; $i++) { $tabArr[] = $i; }
                    } else {
                      for ($i=($curPage+1); $i<13; $i++) { $tabArr[] = $i; }
                    }
                    $tabArr[] = 0;
                    $tabArr[] = $totPages-1;
                    $tabArr[] = $totPages;
                  } else {
                    for ($i=($curPage+1); $i<=$totPages; $i++) { $tabArr[] = $i; }
                  }
                } else {
                  for ($i=1; $i<=$totPages; $i++) { $tabArr[] = $i; }
                }
                return $tabArr;
               }//function generatePagination end
              }
              
              $id = isset($id) ? $id.'_' : '';
              $total = isset($total) ? $total : $modx->getPlaceholder($id."total");
              $start = isset($start) ? $start : $modx->getPlaceholder($id."urlStart");
              $summarize = isset($summarize) ? $summarize : $modx->getPlaceholder($id."perPage");
              $currentPage = isset($currentPage) ? $currentPage : $modx->getPlaceholder($id."current");
              $landing = isset($tagDocumentID) ? $tagDocumentID : $modx->documentObject['id'];
              if ($total == 0 || $summarize == 0) {
                return false;
              }
              $page = ($start/$summarize)+1;
              $output = isset($output) ? $output : 0;
              $paginationArray = generatePagination($page, $total, $summarize);
              $ph = "";
              $cInc = $_GET[$id.'start'];
              foreach ($paginationArray as $page) {
                $inc = ($page-1) * $summarize;
              if ($page == 0) { 
                  $ph .= ""; // represents pages that aren't displayed
                } else if ($inc == $cInc) {
                 if  ($total  == 1)  { $ph = ""; } else {
                  $ph .= "<span class=\"pagination-current\">{$page}</span>";  }
                } else {
                  $ph .= "<a class=\"page\" href=\"".ditto::buildURL("start=".$inc, $landing, $id)."\">{$page}</a>\n";
                }
              }
              $modx->setPlaceholder("{$id}pagesplit", $ph);
              if ($output) { 
              if ($ph == "") return "";
              return "<div class=\"pagination\"><span class=\"pagination-title\">Pages:</span> {$ph}</div>";
              }
              ?>


              author: with this you can display the author name
              <?php
              $editedby_id = empty($id_author) ?
              $modx->documentObject['createdby'] : $id_author;
              // sample conversion
              $user_info = $modx->getUserInfo($editedby_id);
              $editedby_name = ($user_info['fullname'] ? $user_info['fullname'] : $user_info['username']);
               return $user_info['fullname'];
              ?>


              phx:character_limit: with this you can crop the main content text and strip html tags
              <?php
              if (strlen($output) > $options) {
                    $output = $modx->stripTags($output, '');
                    $output_cutted = substr($output, 0, $options);
                    $last_space = strrpos($output_cutted, " ");
                    $output = substr($output_cutted, 0, $last_space) . "";
                    } else {
                    $output = $modx->stripTags($output, ''); 
                    }
                    return $output;
              ?>


              getfield: with this you can get a value from a tv that is in another resource
              <?php
              /*
              ==================================================
              	GetField
              ==================================================
              
              Returns any document field or template variable from any document or any of its parents.
              
              Author: Grzegorz Adamiak [grad]
              Version: 1.3 beta @2006-11-08 14:40:04
              License: LGPL
              MODx: 0.9.2.1+
              
              See GetField.txt for instructions and version history.
              --------------------------------------------------
              */
              
              /* Parameters
              ----------------------------------------------- */
              
              # $docid [ int ]
              # ID of the document for which to get a field content.
              # Default: current document
              
              $gfIntDocId = (isset($docid)) ? $docid : $modx->documentIdentifier;
              
              # $field [ string ]
              # Name of the field for which to get the content:
              # - any of the document object fields (http://modxcms.com/the-document-object.html)
              # - template variable
              # Default: 'pagetitle'
              
              $gfStrDocField = (isset($field)) ? trim($field) : 'pagetitle';
              
              # $parent [ 0 | 1 ]
              # If set to 1, the snippet will return value for the document parent.
              # Default: 0
              
              $gfBoolParent = (isset($parent)) ? $parent : 0;
              
              # $parentLevel [ int ]
              # Specifies how high in the document tree to search for the parent of the document:
              # - $parentLevel = 0 - returns the ultimate parent (right under site root)
              # - $parentLevel = 1 - returns the direct parent
              # Default: 0
              
              $gfIntParentLevel = (isset($parentLevel) && is_int((int) $parentLevel)) ? $parentLevel : 0;
              
              # $topid [ int ]
              # Id of the topmost document in the document tree under which to search for a parent. Used only with $parent set to 1.
              # Default: 0
              
              $gfIntTopDocId = (isset($topid) && is_int((int) $topid)) ? $topid : 0;
              
              /* Do not edit the code below!
              ----------------------------------------------- */
              
              # Include logic
              include_once('assets/snippets/getfield/getfield.inc.php');
              
              # Get parent document ID
              if ($gfBoolParent)
              	$gfIntDocId = gfGetParentId($modx, $gfIntDocId, $gfIntTopDocId, $gfIntParentLevel);
              
              # Get content of the field
              $output = gfGetFieldContent($modx,$gfIntDocId,$gfStrDocField);
              
              unset($gfIntDocId, $gfStrDocField, $gfBoolParent, $gfIntParentLevel, $gfIntTopDocId);
              
              return $output;
              ?>


              PHx plugin for conditional comments: http://modx.com/extras/package/phx

              TemplateRules plugin to automatically change template depending on tree depth (As I said, I use a template for the blog page, another template for the category page, and another for the article page): http://forums.modx.com/index.php?topic=38684.0

              Ditto call: for the "Category template"
              [!Ditto? &id=`a` &parents=`[*id*]` &depth=`1` &display=`10` &tpl=`blog-ditto` &orderBy=`createdon DESC` &paginateAlwaysShowLinks=`1` &paginate=`1`!]
              
              <!-- [Pagination] -->
              [!DittoPageSplit? &id=`a` &output=`1`!]
              <!-- [/End Pagination] -->  

                • 40386
                • 8 Posts
                Wow thanks for that ! I really appreciate the help. Thank you.
                  • 19369
                  • 1,098 Posts
                  For the commenting system you can use Jot and there is a phx extender snippet to add gravatar. However Jot is a little bit difficult to configure, a simpler way to add a commenting system is by using an external script like Disqus.
                    • 40386
                    • 8 Posts
                    Thanks.
                    I just came across this: http://modx.com/extras/package/pubkitblogpkblog Have you seen it before?
                      • 19369
                      • 1,098 Posts
                      Yes, however I have never used it. When I was building my blog I decided to make it "manually" because I could change the things later on, in the way I wanted.

                      Anyway, that module is well documented, you can try with that one if you feel more comfortable.