Jump to content
ridgedale

News Section Setup Query

Recommended Posts

Hi,

I just wanted to check whether or not the following topic is still valid with respect to PW 3.x:

https://processwire.com/talk/topic/22-how-to-build-a-news-page/

I am trying to integrate a news section into a basic multisite PW website installation (voluntary project) intended for a community of two villages.
Currently there are 4 subdomains (hca-site, hfi-site, hhg-site, hps-site) that link back to the main domain website (https://thehanneys.uk) by clicking on their home buttons. I had a look at the Blog (ProcessBlog & MarkupBlog) module but it is not really what I'm looking for - a simple News section.

At the moment we're just concentrating on getting the functionality in place. The styling can come later.

The first issue encountered is that there is no checkbox under the Advanced section for "Page Numbers" to turn them on for the news-index template.
Secondly, I don't understand why the following text is being displayed above the navigation when I expected it to be displayed after the page title.
Thirdly, are the story pages displayed on the index page simply by creating a new child under News (page based on news-index.php template)?

Showing 0 of 0 Article(s) | Page 1 of 0

The current code for the news-index.php template is as follows:

<?php namespace ProcessWire;

// basic-page.php template file
// See README.txt for more information

// Primary content is the page's body copy
$content = $page->body;

// If the page has children, then render navigation to them under the body.
// See the _func.php for the renderNav example function.
if($page->hasChildren) {
    $content .= renderNav($page->children);
}

// if the rootParent (section) page has more than 1 child, then render
// section navigation in the sidebar
if($page->rootParent->hasChildren > 1) {
    $sidebar = renderNavTree($page->rootParent, 3) . $page->sidebar;
}

// start the news stories list
echo "<ul>";

// get the stories for this page
$stories = $page->children("limit=6, sort=-date");

// note if you set the stories to sort by date descending on the /news/ page
// in the admin, then you can omit the "sort=-date" above.

// cycle through each story and print it in a <li>
foreach($stories as $story) {
   echo "
       <li><a href='{$story->url}'>{$story->title}</a>
       <p><strong>Date:</strong> {$story->date}</p>
       {$story->body}
       </li>
       ";      
}

echo "</ul>";

// get values for our placemarker headline
$start = $stories->getStart();
$end = $start + count($stories);  
$total = $stories->getTotal();
$num = $input->pageNum;
$lastNum =  ceil($total / $stories->getLimit());

// output the placemarker headline
echo "<h5>Showing $start - $end of $total Article(s) | Page $num of $lastNum</h5>";
          
// output pagination links
echo $stories->renderPager();

The current code for the news-story.php template is as follows:

<?php namespace ProcessWire;

// basic-page.php template file
// See README.txt for more information

// Primary content is the page's body copy
echo "<div id='bodycopy'>";
    $content = $page->body;
echo "</div>";

// If the page has children, then render navigation to them under the body.
// See the _func.php for the renderNav example function.
if($page->hasChildren) {
    $content .= renderNav($page->children);
}

// if the rootParent (section) page has more than 1 child, then render
// section navigation in the sidebar
if($page->rootParent->hasChildren > 1) {
    $sidebar = renderNavTree($page->rootParent, 3) . $page->sidebar;
}

P.S. Are there any books/tutorials specifically covering PW 3.x?

Any assistance would be greatly appreciated.

 

Share this post


Link to post
Share on other sites

@ridgedale

42 minutes ago, ridgedale said:

The first issue encountered is that there is no checkbox under the Advanced section for "Page Numbers" to turn them on for the news-index template.
Secondly, I don't understand why the following text is being displayed above the navigation when I expected it to be displayed after the page title.
Thirdly, are the story pages displayed on the index page simply by creating a new child under News (page based on news-index.php template)?

1. check the URLs tab

2. you might be using delayed output, the template files are used to set some variables which are later echoed in another file included at the end of the template file

Something like this

<?php

$header = "<header>...</header>";
$content = "<div class='content'><h1>{$page->title}</h1><div>{$page->content}</div></div>";
$footer = "<footer>...</footer>";

// echoing something here will display above the header

include ("main.php");

The main.php file

<?php
// here we echo the variables set in the template file
echo "<html><body>...";
echo $header;
echo $content;
echo $footer;
echo "</body></html>";

3. 

$stories = $page->children("limit=6, sort=-date");

the above takes the 6 latest child pages of the current page, so on pages using the news-index.php template it gets the 6 latest child pages .

 

https://processwire.com/docs/tutorials/

  • Like 1

Share this post


Link to post
Share on other sites

@ridgedale I don't use the delayed output method but looking at the page source on your site, looks like your templates are being automatically included like this to produce a final page output at yoursite.com/news/:

1) _init.php
2) news-index.php
3) _main.php

You're getting this on your page:

<!-- THIS LINE IS OUTPUTTING FROM NEWS-INDEX.PHP BECAUSE YOU GOT ECHO COMMANDS IN THERE -->
<ul></ul><h5>Showing 0 - 0 of 0 Article(s) | Page 1 of 0</h5>
<!-- THEN _MAIN.PHP LOADS AFTER THE PREVIOUS TEMPLATE -->
<!DOCTYPE html>
<html lang="en">
<head>

Your news-index.php is supposed to populate placeholders (i.e. not echo out anything), then the _main.php actually outputs the page using the predefined values. So maybe you need to do something like:

// news-index.php
// define the placemarker headline
$placeholderHeadline = "Showing $start - $end of $total Article(s) | Page $num of $lastNum";

// main.php - this outputs the final page
// put this line where you want it to show on the page
<h5><?php echo $placeholderHeadline; ?></h5>

https://processwire.com/docs/tutorials/how-to-structure-your-template-files/page4

 

Another approach is what I do, which I find easier and more obvious what's going on:

 

1) Go to config.php and modify it so that the _main.php file IS NOT appended (this is what's happening to you).

/**
 * Prepend template file
 *
 * PHP file in /site/templates/ that will be loaded before each page's template file.
 * Example: _init.php
 *
 * @var string
 *
 */
$config->prependTemplateFile = '_init.php';

/**
 * Append template file
 *
 * PHP file in /site/templates/ that will be loaded after each page's template file.
 * Example: _main.php
 *
 * @var string
 *
 */
// I COMMENT OUT THE FOLLOWING LINE
// $config->appendTemplateFile = 'main.php';


2) Create file main.php (this is used to serve ALL of my pages
3) Create template, services-index.php, create file services-index.php
4) Go to template > files tab > alternate template filename - type 'main' (I do this for EVERY template that needs its own page)

1.thumb.png.22a6179b4d4f8ef8ae7566fc1eb596f4.png

5) Put the code in the files

// main.php
<!DOCTYPE html>
<html lang='en' class='no-js'>
<head>

</head>

<body>
  <!-- my header is in another file at /templates/includes/header.inc -->
  <?php include('./includes/header.inc'); ?>

  <!-- start main content -->
  <?php include($page->template->name); ?> 

  <!-- my footer is in another file at /templates/includes/footer.inc -->
  <?php include('./includes/footer.inc'); ?>
</body>
</html>

// services-index.php
<p>I'm loaded now through main when you go to mysite.com/services/ how awesome is that!</p>

I figure that the only part that generally changes on  page is the middle section between header and footer. And if I need something to change in the header, I just include a header file like I did with the footer. Then I can use logic in that file to output different things depending on what's needed.

Hope this makes sense and gives you some ideas of the different approaches available.

Share this post


Link to post
Share on other sites

Hi fbg13 / SamC,

Apologies for not responding sooner and thank you for all your feedback.

In the end I decided to go down the route of removing everything and re-installing the development branch v. 3.0.54 that allows the regular-master profile (incorporating a blog module by default that can be customised as News) referred to in Ryan's Introducing a new ProcessWire site profile and ProcessWire 3.0.54 and Uikit 3 admin theme blog posts. This greatly simplified the integration of a news section in my offline testing.

I'm now in the process of removing everything, installing the development branch v. 3.0.58 (as this dev branch appears to be close to the stable version that is intended to be released) with the regular-master profile. The initial master site intallation went smoothly apart from a locale error/warning issue which I have detailed in the Warning about Server Locale after update from 3.0.52 > 3.0.53 - Help!  forum topic and am hoping to to resolve.

The issue I've found with the tutorials referred to is that they practically all deal with version 2.x or earlier of Processwire, btw.

Many thanks again for your help.

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 rjgamer
      Hi,
      is there a hook after the current (active) page got created? Or which method got called in the Page class after the Constructor of the current page got initialized?
      Thanks.
       
    • By rjgamer
      Hi guys,
      the field "redirect_last" of type DateTime got not updated. The update on the field "redirect_counter" works and got saved.
      Does anybody know what I did wrong in my code?
      if ($input->urlSegment(1) === 'redirect') { $page->of(false); $page->redirect_last = time(); $page->redirect_counter += 1; if ($page->save('redirect_counter')) { $session->redirect($page->website_url, 302); } } Thanks.
    • By theoretic
      Hi there! And thanks for Processwire!
      I have an interesting task which i cannot fulfill as i want. Maybe someone could help me please?
      Let's imagine a simple page structure of this kind:
      Category 1
      + Item 1.1
      + Item 1.2
      Category 2
      + Item 2.1
      + Item 2.2
      My task is to attach some items to more than one category, at least to show some items on different frontend category pages. With PW, it's a piece of cake. I've just created a field called Items (of type Page Reference) and attrached it to Category template. Since i have lots of items inside each category i preferred to use Page Autocomplete input for my Items field. The pages available for autocomplete are restricted by a very simple selector:
      template=item
      It works like a charm. But later i decided to make this autocomplete even smarter and to exclude current category children items from it. I tried to update my selector this way...
      template=item,parent!=(page)
      ...and oops, this broke my selector. My autocomplete founds nothing. Sorry, i had to replace the square braces by () because of this forum limitations, i swear i'm using square brackets in real-life selector!
      What am i doing wrong? And is there any way to include current page info in autocomplete-related selectors? Thanks in advance!
       
    • By fruid
      I'm having and always have a hard time building PaginatedArrays, I never know where to put the "limit=24" selector so please enlighten me.
      Here's what I'm doing…
      $categories = $page->protable('start=0, limit=999999'); // this I need in order to retrieve the pages's "categories" and I don't know how to make use of $rows instead for that purpose because of this confusing limit-API $rows = $page->protable; // put ("limit=20") here? $custom = buildSelector($input, $rows); // this function returns an array of selectors depending on the user input $items = new PaginatedArray; // or here? // or here? $items->find("limit=20") // or like this? $items("limit=20") // or like this? $items = $items("limit=20") // or like this? $items = $items->find("limit=20") foreach ($rows as $r) : if ($custom->get('selector')->matches($r)) : $items->add($r); endif; endforeach; // or at this point? and then
      if ($items) { // or maybe somewhere here?     echo '<span class="grey">'.$items->getPaginationString(array(     'label' => 'entries',     'zeroLabel' => '0 entries', // 3.0.127+ only     'usePageNum' => false,     'count' => count($items),     'start' => $items->getStart(),     'limit' => count($items),     'total' => $items->getTotal()     )); and then of course…
      $pager = $modules->get("MarkupPagerNav"); echo '<div class="uk-flex uk-flex-center">'.$pager->render($items, $options).'</div>'; I'm out of ideas and confused cause it doesn't make sense to me either way.
      ____
      The buildSelector function above returns and array…
      $selected = new Selectors("$letter, $searchterm, $category"); $custom = new Wirearray; $custom->set('selector', $selected); $built->set('sort', $sort); return $custom; and each of the new selectors are basically strings ("category=whatever")
      Also, you cannot put the "sort=title" or whatever as a selector for the Selectors function (see above). Why, I know not.
      I don't know if that is the proper way but selecting kind of works now as opposed to many other ways I tried. Selectors always require a lot of trial and error, it seems to have a very sensitive API, always depends on double quotes, single quotes and how you concatenate.
      Thanks for help!
    • By picarica
      Hello si have this gallery, pretty good website, but yesterday client uploaded over 3000 images oto the site, and it cannot handle filtering them out and showing them at the same time , i wanted some simple pagination maybe infinite scrool or onclikc load whatever, but i cannot seem to implement infinite ajax scrool and any other JS methods, nut sure why i still got stuck at the next method, like there is not next page.
      so i wanted to implement PW method of paginating i wanted to use MarkupPagerNav
      so far i have  this code for outputting images
      $pa = $pages->find("template=basic-page|art_gallery, images.tags!=''"); /* $pa = $pages->find("has_parent!=2,id!=2|7,status<".Page::statusTrash.",include=all"); */ echo "<div class='js-filter' id='gal' >"; /* row gtr-50 gtr-uniform */ $frame = $pages->get('/settings/')->watermark; foreach ($pa as $p) { foreach($p->images as $image) { if(!$image->hasTag("act")) { $options = array('quality' => 80, 'upscaling' => true, 'cropping' => 'north', 'sharpening'=>'medium'); $large = $image->size(1200, 0, $options); $wmImage = $large->pim2Load('wm1', ['quality'=>80, 'upscaling' => true, 'sharpening'=>'medium', 'defaultGamma'=>-1])->watermarkLogo($frame, $position='se',$padding=1.5)->pimSave(); /* zmazanie variacii, treba odpoznakovat ked sa menia nastavenie vyssie */ /* $image->pim2Load('wm1')->removePimVariations(); */ $thumb = $image->size(400, 300, $options); echo "<div class='$image->tags grid-item' style=''>"; echo "<span style='overflow:hidden;'class='image fit'>"; echo "<a class='hvr-reveal' href='$wmImage->url'>"; echo "<img uk-scrollspy='cls: uk-animation-fade; repeat: false' src='$thumb->url' alt='$image->tags'>"; echo "</a>"; echo "</span>"; echo "</div>"; } else { $options = array('quality' => 80, 'upscaling' => true, 'cropping' => 'north', 'sharpening'=>'medium'); $large = $image->size(1200, 0, $options); $wmImage = $large->pim2Load('wm2', ['quality'=>80, 'upscaling' => true, 'sharpening'=>'medium', 'defaultGamma'=>-1])->pixelate(25)->smooth(255)->watermarkLogo($frame, $position='se',$padding=1.5)->pimSave(); /* zmazanie variacii, treba odpoznakovat ked sa menia nastavenie vyssie */ /* $image->pim2Load('wm2')->removePimVariations(); */ $thumb = $image->size(400, 300, $options); echo "<div class='$image->tags blur grid-item' style=''>"; echo "<span style='overflow:hidden;'class='image fit'>"; echo "<a class='hvr-reveal' href='$wmImage->url'>"; echo "<img uk-scrollspy='cls: uk-animation-fade; repeat: false' src='$thumb->url' alt='$image->tags'><span>18+</span>"; /* <span>BY OPENING THIS IMAGE YOU CONSET THAT YOU'RE 18 YEARS OR OLDER</span> text copyraightova,y dat vedla obrazky potom */ echo "</a>"; echo "</span>"; echo "</div>"; } } }; to put it  simply, it first searches for sites, and then outputs all images from those sites, pretty simple, it also uses watermarking and uikit filtering
      i have filtering done like this
      $num = 1; echo "<ul class='uk-subnav uk-subnav-pill'>"; foreach(array_unique($alltags) as $key => $tag) { echo"<li uk-filter-control='filter: .$tag;group: $num' class='butt$num' uk-toggle='target: .butt$num ; animation: uk-animation-fade; queued: true'><a href='#'>$tag</a></li>"; echo"<li uk-filter-control='group: $num' class='butt$num active' aria-hidden='true' hidden='' uk-toggle='target: .butt$num; animation: uk-animation-fade'><a href='#'>remove - $tag</a></li>"; $num++; } echo "</ul>"; simple, but i have NO idea how to implement pagination, just because it seems to work that it like find all images, and stores with limit, and then just paginates them, but i cannot apply this method in my code.
      any idea how to make any JS inifite scroll work ? or just how to make this work ? with my setup, or with some modifications, it just have to work as is now
×
×
  • Create New...