Jump to:

1851 Posts in 1606 Topics by 561 members

Blog Module

SilverStripe Forums » Blog Module » Post recent (TAGGED) blog posts on home page

Discuss the Blog Module.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 3081 Views
  • jloafs
    Avatar
    Community Member
    15 Posts

    Post recent (TAGGED) blog posts on home page Link to this post

    Has anyone any idea how to feature latest blog posts (in summarised form) in the sidebar of a homepage using only blog posts with a specific tag ie. "news"?

  • Willr
    Avatar
    Forum Moderator
    5508 Posts

    Re: Post recent (TAGGED) blog posts on home page Link to this post

    Have a look at tutorial 2 for a general idea for how to get a set of pages - http://doc.silverstripe.org/sapphire/en/tutorials/2-extending-a-basic-site#showing-the-latest-news-on-the-homepage.

    For the blog module tags - the tags are stored in a txt field as a comma separated list so in your database query you can use the LIKE '%news%' to filter for just news.

    function LatestNews($num=5) {
    return DataObject::get("ArticlePage", "Tags LIKE '%news%' ", "Date DESC", "", $num);
    }

  • jloafs
    Avatar
    Community Member
    15 Posts

    Re: Post recent (TAGGED) blog posts on home page Link to this post

    Hi Willr,

    Just looking at this now.

    I currently have the latest news set up as per that tutorial. If I make the suggested change in the HomePage.php file, what would I need to change in the HomePage.ss file?

    I'm new so please bear with me.

  • Willr
    Avatar
    Forum Moderator
    5508 Posts

    Re: Post recent (TAGGED) blog posts on home page Link to this post

    You wouldn't need to change the template as all you're basically doing is filtering the database query (from the PHP) to reduce and entries you're including.

  • jloafs
    Avatar
    Community Member
    15 Posts

    Re: Post recent (TAGGED) blog posts on home page Link to this post

    I must be doing something wrong.

    In my php file I have:

    function LatestNews($num=5) {
    return DataObject::get("ArticlePage", "Tags LIKE '%news%' ", "Date DESC", "", $num);
    }

    In my .ss file I have:

    <ul id="NewsList">
    <% control LatestNews %>
    <li class="newsDateTitle"><a href="$Link" title="Read more on &quot;{$Title}&quot;">$Title</a></li>
    <li class="newsDateTitle">$Date.Nice</li>
    <li class="newsSummary typography">$Content.FirstParagraph<a href="$Link" title="Read more on &quot;{$Title}&quot;"> More...</a></li>
    <% end_control %>
    </ul>

    But I'm getting an error and the page doesn't work at all.

    Have I missed something here?

  • Willr
    Avatar
    Forum Moderator
    5508 Posts

    Re: Post recent (TAGGED) blog posts on home page Link to this post

    But I'm getting an error and the page doesn't work at all.

    Posting the message (or a screenshot of the error) is much more useful. If you are getting a generic "Website Error" page then put your site into devmode. This enables full error messages.

    function LatestNews($num=5) {
    return DataObject::get("ArticlePage", "Tags LIKE '%news%' ", "Date DESC", "", $num);
    }

    If you are using the Blog then the PageType is "BlogEntry" not "ArticlePage".

    The error page will have more useful messages.

  • jloafs
    Avatar
    Community Member
    15 Posts

    Re: Post recent (TAGGED) blog posts on home page Link to this post

    Thanks for pointing that out.

    Solved.

    Much appreciated.

  • juneallison
    Avatar
    Community Member
    108 Posts

    Re: Post recent (TAGGED) blog posts on home page Link to this post

    Hi,

    I have a question that is related to this functionality. Or I guess an extension of this functionality. Even though I haven't tried it, I believe I understand how to implement what has been described in this thread if I wanted blog posts on my home page.

    I am actually looking to put a few recent posts in a sidebox that will only appear on Blog Entry pages. (I think I can figure this part out). But I want the recent posts to only be posts that have the same tag as the blog entry that you are currently viewing. This is where I am getting stuck.

    I am guessing it would use the first tag listed for the current blog entry. But I don't know what code/syntax is needed to grab the first tag associated with the post.

    Any suggestions would be great. Thanks!

    3081 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.