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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By EyeDentify
      I have been experimenting with the new $page->meta() method and find it useful.

      Once i figured out that the data i "save" with it is tied to the page where i called the method from.

      So this is not obvious at least not for me in the documentation:
      https://processwire.com/api/ref/page/meta/
       
      So i just wanted to share that revelation with the community so you don´t get as confused as i was.

      Happy Coding Everyone.
    • By stanoliver
      In the new page-meta-method (https://processwire.com/blog/posts/pw-3.0.133/#comments) there is an example how to ouput "world". 
      Could may someone give me a snippet of code so that the output is one of the colors (red, green, blue).
    • By MateThemes
      Hello everyone!
      I have a problem with pagination. I have following code:
      <div class="uk-section"> <?php $results = $pages->find("template=gallery, limit=10, sort=title"); $pagination = $results->renderPager(); echo $pagination; echo "<ul class='uk-pagination uk-flex-center'>"; foreach($results as $result) { echo "<li><a href='{$result->url}'>{$result->title}</a></li>"; } echo "</ul>"; echo $pagination; ?> </div> Which works fine. And this markup results in following html code:
      <div class="uk-section"> <ul class='uk-pagination uk-flex-center'> <li> <a href='/galerie-bisheriger-projekte/'>Galerie bisheriger Projekte</a> </li> <li> <a href='/galerie-bisheriger-projekte/galerie-1/'>galerie-1</a> </li> </ul> </div> But instead of "Galerie bisheriger Projekte" and "galerie-1" I want to have a number.
      And as last question, how can I add a previous and next button?
      Thanks for your help!
    • By Liam88
      Hi all,
      Quick question as I haven't found anything from my Googling. 
      I have a blog on the site which utilises pagination. On the standard blog page I have a custom header which has featured posts.
      Below that I then have recent posts like mosts blogs.
      Now if i click to page two or three I want the header to disappear and just show a continuation of the standard posts.
      I'm not sure how to go about this so any direction would be helpful.
      Thanks
    • By VeiJari
      Hello forum. I'm trying to figure out how to detect if current form has errors after saving it in pw admin page. This is so that our event location isn't added in database if we detect errors. But I can't seem to find a correct way to detect errors? I only found the wire()->errors() and it always triggers even if I don't have any errors. 
      How can I detect errors in a form?
      By error I mean $page->error('this is the red error');
×
×
  • Create New...