Jump to content

Building a blog / news system from scratch


Neo
 Share

Recommended Posts

In order to learn and better understand how PW works, I would like to build a simple blog / news system, where articles can be posted under different categories and an overview page lists all available posts with pagination. Within the site's menu (I am using Markup Simple Navigation), the overview page should just be displayed ("blog / news") without showing any child pages.  

I don't want to use a module. 

The only tutorial I found so far is the following:

http://wiki.processwire.com/index.php/Simple_News_System

Is this the only tutorial available / the recommended approach?

Would appreciate your guidance and advice.

Link to comment
Share on other sites

building a news system could take some in depth knowledge of the api - i would read all of the docs and study the cheatsheet.

the navigation is trivial; there are innumerable ways to include/exclude pages (MSN supports selectors)

  • Like 1
Link to comment
Share on other sites

I am just wrapping up a fairly simple blog/news system and I unfortunately don't have the time to do a tutorial, but I would be happy to share my code if you were wanting to see how to execute anything. I took some ques from Ryan's profile as well as his blog module. I think it would be a really good place to start.

here is my public(ish) dev version:

http://www.muchdevelopment.com/spa/

Link to comment
Share on other sites

@MuchDev sure, always happy to see ideas and input.

Setting up the basic structure with the pages is fairly simply.

What I am struggling with a bit is a category function for each post.

Instead of having to create a specific page in the tree for each category under which you can post new items,

I would like to be able to create / assign the category within the news item's page.

Link to comment
Share on other sites

@MuchDev sure, always happy to see ideas and input.

Setting up the basic structure with the pages is fairly simply.

What I am struggling with a bit is a category function for each post.

Instead of having to create a specific page in the tree for each category under which you can post new items,

I would like to be able to create / assign the category within the news item's page.

Cathegories...are simple by pagefields.

(Even nice functions like "See also" could be just simple pagefield to select.)

Easy example on a site for a diary like newssystem with use of URL segments....really great stuff for little functions like /archive/ or /2015/ or /my-cat/ just with different URL segements...

Newspage:

http://waldkindergarten-altfraunhofen.de/aktuelles/#start

URL Segment for archive show all:

http://waldkindergarten-altfraunhofen.de/aktuelles/archiv/#start

URL Segment 2 for year:

http://waldkindergarten-altfraunhofen.de/aktuelles/archiv/2015/#start

or for cathegory name:

http://waldkindergarten-altfraunhofen.de/aktuelles/archiv/ausfluege/#start

every single item lives under /aktuelles/:

http://waldkindergarten-altfraunhofen.de/aktuelles/unser-waldkater-2015-05-11/

(it get on creation a name + date combination)

some codeexamples for URL Segments are here - this works with just a few lines of code so great, so easy, so cool...ähh sorry but in every second post i have to write how much i like PW!! ;)

https://processwire.com/talk/topic/9476-new-project-a-nice-growing-kindergarten/#entry91259

(attention - it's may not the best code but it works so far)

some backend pics...

post-2327-0-88872400-1433687843_thumb.jppost-2327-0-95763900-1433687860_thumb.jppost-2327-0-45238200-1433687874_thumb.jp

I only have one single cat to choose since i use this in the isotope view to sort!

best regards mr-fan

  • Like 3
Link to comment
Share on other sites

I am just wrapping up a fairly simple blog/news system and I unfortunately don't have the time to do a tutorial, but I would be happy to share my code if you were wanting to see how to execute anything. I took some ques from Ryan's profile as well as his blog module. I think it would be a really good place to start.

here is my public(ish) dev version:

http://www.muchdevelopment.com/spa/

how did you implement the categories and tagging something like  /?cat=  /?tag=     on the url ?

  • Like 1
Link to comment
Share on other sites

@adrianmak - if you use the GET variables (aka query string parameters), then you can use them in a selector, once sanitized; and then use that selector to present the relevant posts.

I have used that option, but now i always use segments, since i can cache those pages.  i would probably only use get vars if i was maybe filtering client side, so still able to cache the page itself...

Edited by Macrura
clarified technical terms
  • Like 2
Link to comment
Share on other sites

I utilized the method demonstrated by MR FAN. Add a page field to your template, or in my case an autocomplete field with the part of the tree that houses categories or for the tags part of the tree for the tags. Then you just search for pages that have that page title within them. 

//look for get strings
if($searchString = $sanitizer->selectorValue($input->get->tag)){
	$tagTitle = $pages->get("template=tag,sort=-created,name=$searchString")->title;
	$query = $defaultQuery.",tags.name=".$searchString;
	$headerText = 'Posts tagged with "'.$tagTitle.'"';
}elseif($searchString = $sanitizer->selectorValue($input->get->cat)){
	$catTitle = $pages->get("template=category,sort=-created,name=$searchString")->title;
	$query = $defaultQuery.",categories.name=".$searchString;
	$headerText = 'Posts relating to "'.$catTitle.'"';
}else{
	$query = $defaultQuery;
	$headerText = "Current posts";
}

//find posts based on query
$posts = $pages->find($query);
  • Like 1
Link to comment
Share on other sites

@adrianmak - if you use the get vars, then you can use them in a selector, once sanitized; and then use that selector to present the relevant posts.

I have used that option, but now i always use segments, since i can cache those pages.  i would probably only use get vars if i was maybe filtering client side, so still able to cache the page itself...

What is get vars ?

a pw's api ?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...