We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 22844
    • 7 Posts
    I keep looking at tutorials for blogs that have much more features than I need. i am not very well experienced in PHP. All I want is to be able to add a news story, which has a heading, a date, and a bit of content.

    I’ve already set up my page here:

    http://zumbawithjacqui.co.uk/index.php?id=2

    This is how I want it to look, but I don’t know how to implement it so that the client can add new articles as she likes. I have downloaded GetResources and I know that it can be done with this.

    In my template for the News Page Resource, I’ve got the code:

    <div id="content">
    
      <h1>[[*introtext]]</h1>
      
      <p class="post-info">
      Posted on [[*publishedon:strtotime:date=`%b %d, %Y`]] </p>
        <hr />
        <p>[[*content]]</p>
        <hr />
    
    </div>
    


    I have a feeling that this code should be in a chunk or a snippet but I’m not sure which and also unsure of how I can make this a simple procedure to add new articles.

    Any help appreciated. smiley
      • 22019
      • 390 Posts
      Just skip the bits in http://rtfm.modx.com/display/revolution20/Creating+a+Blog+in+MODx+Revolution that you’re not going to use (comments, sections, archives - not sure if you’re going to use tags or not?).

      1. Create a BlogPost template (you don’t strictly even need this if you’re not using any of the blog extras), but you might as well. Using the template in the tutorial, strip out anything you’re not using in the class=post-info paragraph tag, and remove the postmeta and post-comments class divs entirely.

      2. Create a document under your news folder using that template

      3. Create a blogPost chunk (a mini-template) that you want to use on the News index page - a really stripped down version of the one in the tutorial:
         <div class="post">  
              <h2 class="title"><a href="[[~[[+id]]]]">[[+pagetitle]]</a></h2>  
             <p class="post-info">Posted by [[+createdby:userinfo=`fullname`]]  
           </p>  
              <div class="entry">  
              <p>[[+introtext]]</p>  
              </div>  
             <p class="postmeta">  
              <span class="links">  
        <a href="[[~[[+id]]]]" class="readmore">Read more</a> | <span class="date">[[+publishedon:strtotime:date=`%b %d, %Y`]]</span>  
              </span>  
            </p>  
        </div>



      4. In your News resource (which uses your normal or default template), first make sure that the Rich Text toggle is OFF (at the bottom). Then put this in the Content:
         [[!getResourcesTag?  
          &element=`getResources`  
          &elementClass=`modSnippet`  
          &tpl=`blogPost`  
          &pageVarKey=`page`  
          &parents=`[[*id]]`  
          &includeTVs=`1`  
          &includeContent=`1`
          &limit=`10`  
         ]]  
         [[!+page.nav:notempty=`  
         <div class="paging">    
         <ul class="pageList">    
         [[!+page.nav]]    
         </ul>    
         </div>  
         `]]  


      You can get rid of the paging stuff if you want. You only need ’includeTVs’ if you are using the tags. If your client publishes a lot of news, you might want to up the &limit number - but if this happens you probably want to introduce some form of sectioning or archiving anyway.

      5. And really, that should be more or less that. getResources will automatically sort by the published on field, so your client can either duplicate an existing blog/news entry or create a new one (using the BlogPost template) and publish it, and it will automatically appear in the News page - as long as she creates the news item under ’News’.

      Hope this helps.

        Writer > E-consultant > MODx developer || Salesforce || modx 2.x || PHP 5.2.13 || MySQL client 5.0.86
        • 22844
        • 7 Posts
        This helped a lot, thanks!

        I did an even more stripped down version of your code. I didn’t want links to new pages, i wanted the news to appear all within the News page, as you can see here...

        http://zumbawithjacqui.co.uk/index.php?id=2

        However, a few more quick questions that should be simple enough to solve...

        I currently have the CSS for my "content" div set to overflow:auto so that a scroll bar just appears as the more news stories are put in. I’m not sure if this is the best option. Perhaps the page could go down to a certain length and then an "older" link appears? How could I achieve this?