Recommended Posts

Hello everyone,

I'm new in this forum and my english is not perfect so sorry for the mistakes.

I have an Blog Project and i will use categories. 

Here is the structure:

  • Blog -> displays all the Blogposts (template=BlogPage)
    • Post-Name -> display the specific Post (template=BlogPost)
  • Categories -> not visible in the menu (template=CategoriesPage)
    • Categorie-Name -> not visible in the menu (template=CategoriePage)

For your information:

  • (BlogPost) every blogpost has its own page
  • (BlogPost) in Admin i can select the categorie per Field -> SelectMultiple Pages (Checkbox) (fieldname=categories)
  • (Blog) displays all the BlogPosts and all the categories under the ParentTemplate CategoriesPage, which also have their own side

Now the Problem:
On Blog -> I would like to click on a category and only see the post that has this category checked in the BlogPost.

CategoriePage -> what do I have to insert there to show only the specific posts which use the checked categorie?


Let me know if you need more information

Thanks for your support

 

Share this post


Link to post
Share on other sites

Hi @adrian_gp,

Welcome to the forums.

Let's say you have a category 'Technology' whose URL is /categories/technology/.  In the template file of the template CategoriePage, you can do this:

// @note: we set a limit here. You can use pagination if you have many posts
$posts = $pages->find("template=BlogPost, limit=10, categories=$page");

$out = '';
// category title
$out .= "<h2>{$page->title}</h2>";
// found posts in this category
if($posts->count) {
    foreach($posts as $post) {
        $out .= "<h3><a href='{$post->url}'>{$post->title}</a></h3>" .
         "<p>{$post->summary}</p>";// assuming you have a summary field
}
// no posts in this category yet
else $out .= "<p>No posts found in this category</p>";

echo $out;

Quickly typed in the browser, check for errors, just an example.

 

Btw, there are blog profiles and a Blog module you can look at for more examples.

  • Like 3

Share this post


Link to post
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

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By franciccio-ITALIANO
      Hi, in wordpress homepage we can put a list of LAST ARTICLES AND COMMENTS.
      Can I do same thing with processwire?
      If yes, how?
      There is a tutorial?

      Thanks!
    • By rareyush
      I am using this function to get blogpost but I don't see what's wrong in it and why it is now showing anything in frontend.
       
      function ukBlogPost(Page $page, $options = array()) { $defaults = array( 'summarize' => null, // Display blog post summary rather than full post? (null=auto-detect) 'metaIcon' => 'info', 'moreIcon' => 'arrow-right', 'moreText' => __('Read more'), 'categoryIcon' => 'hashtag', 'bylineText' => __('Posted by %1$s on %2$s'), ); $options = _ukMergeOptions($defaults, $options); $title = $page->title; $img = $page->images->first(); $date = $page->date ? $page->date : $page->createdStr; $name = $page->createdUser->name; $body = summarizeText($page->get('body'), 100); $metaIcon = ukIcon($options['metaIcon']); $moreIcon = ukIcon($options['moreIcon']); $categoryIcon = ukIcon($options['categoryIcon']); $n = $page->comments->count(); $numComments = $n ? "<a href='$page->url#comments'>" . ukIcon('comments') . " $n</a>" : ""; $itn = $page->get('itineraries'); $ito = $itn->each( "<h4> {itineraries_title}</h4> <p>{itineraries_details} </p> "); if($options['summarize'] === null) { // auto-detect: summarize if current page is not the same as the blog post $options['summarize'] = page()->id != $page->id; } /* $categories = $page->categories->each($categoryIcon . "<a class='uk-button uk-button-text' href='{url}'>{title}</a> " );*/ if($options['summarize']) { // link to post in title, and use just the first paragraph in teaser mode $title = "<a href='$page->url'>$title</a>"; $body = explode('</p>', $body); $body = reset($body) . ' '; $body .= "<a href='$page->url'>$options[moreText] $moreIcon</a></p>"; $class = 'blog-post-summary'; } else { $class = 'blog-post-full'; } if($options['summarize']) { $heading = "<h4 class='uk-margin-remove tour-heading'>$title</h4>"; } else { $heading = "<h3 class='uk-article-title uk-margin-remove tour-heading'>$title</h3>"; } $byline = sprintf($options['bylineText'], $name, $date); if($img) { $img = $img->size(375,380); } // return the blog post article markup return " <div> <div class='uk-card'> <div class='uk-inline-clip uk-transition-toggle'> <img src='$img->url' alt='$img->description' class='uk-border-rounded uk-transition-scale-up uk-transition-opaque' > <div class='uk-overlay uk-light uk-position-bottom'> <p class='uk-text-light'>$heading</p> </div> </div> $ito </div> </div> "; }  
       
      I tried running $title, $img etc. - or are they all blank? simultaneously but nothing returns anything.
       
      I do not know why it is not working 
    • By kongondo
      The Module Blog for ProcessWire replicates and extends the popular Blog Profile.
      Blog is now in version 2.
      Please read the README in the Github link below in its entirety before using this module 
      As of 20 December 2017 ProcessWire versions earlier than 3.x are not supported
      Blog Documentation is here (Work in Progress!)
      See this post for new features in version 2 or the readme in GitHub.
      To upgrade from version 1, see these instructions.
      ##################################################
      Most of the text below refers to Blog version 1 (left here for posterity). 
       
      Blog version 1 consists of two modules:
      ProcessBlog: Manage Blog in the backend/Admin.
      MarkupBlog: Display Blog in the frontend.
      Being a module, Blog can be installed in both fresh and existing sites. Note, however, that presently, ProcessBlog is not compatible with existing installs of the Blog Profile. This is because of various structural and naming differences in respect of Fields, Templates, Template Files and Pages. If there is demand for such compatibility, I will code a separate version for managing Blog Profile installs.
      In order to use the 'Recent Tweets Widget', you will need to separately install and setup the module 'MarkupTwitterFeed'.
      Please read the README in the Github link below in its entirety before using this module (especially the bit about the Pages, etc. created by the module). 
      I'll appreciate Beta testers, thanks! Stable release works fine.
      Download
      Modules Directory: http://modules.processwire.com/modules/process-blog/
      Github: https://github.com/kongondo/Blog
      You can also install from right within your ProcessWire install.
      Screenshots (Blog version 1)

      Video Demos
      ProcessBlog
      MarkupBlog
      Credits
      Ryan Cramer
      The Alpha Testers and 'Critics' 
      License
      GPL2
    • By rafaoski
      Hello All ... I just added a new Site Profile ...
      It is important that you use the latest version that supports the new Fields => Fieldset in Tab , Fieldset ( Page ) for this time it is version 3.0.83 DEV
      A simple profile for quick start new Page ... There are several pages like About Us, Blog, Portfolio, Contact Page ...
      The profile is not based on any framework, I just used some css, flexbox, grid, font awesome, and added a simple FlexBox Grid called GRIDLEX ...
      CAN DOWNLOAD FROM THIS LINK:
      http://modules.processwire.com/modules/site-twilight/
      https://github.com/rafaoski/site-twilight
      Some Screenshots:

      OPTIONS PAGE:

      CONTACT PAGE:

      BLOG PAGE:

      ABOUT PAGE:

      PORTFOLIO PAGE:

       
      In addition, I added 2 great modules:
      Tracy Debugger:
      https://modules.processwire.com/modules/tracy-debugger/

      Markup Sitemap:
      http://modules.processwire.com/modules/markup-sitemap/

       
    • By ridgedale
      I'm in the process of finalising a pw 3.0.62 and uikit3 based site which using the Reglar-Master profile and I've noticed pagination is missing despite the Allow Page Numbers? setting being enabled under the blog template URLs tab.
      The default blog.php template is as below:
      <div id='content'> <?php echo ukHeading1(page()->title, 'divider'); $posts = page()->children('limit=10'); echo ukBlogPosts($posts); ?> </div> Reducing the limit as follows does not result in any pagination being displayed despite there being 10 news posts.
      ... $posts = page()->children('limit=6'); ... If I have understood correctly, it should not be necessary to add the MarkupPagerNav module to this profile as the capability should already be already built-in.
      If that is the case, then I can only think that some additional code is required.
      Any help would be greatly appreciated.