Jump to content

Module: Blog


kongondo

Recommended Posts

1 hour ago, kongondo said:

Strange. So, what does this return;


$posts = $pages->find('template=blog-post,limit=5,include=all');
echo $posts->count;
// OR asking Tracy
bd($posts);

 

The echo returns '1', which is correct. There is one post published.

The TracyDebugger dumps returns a big array which I think is correct too:

ProcessWire\PageArray #71aa
selectors protected => ProcessWire\Selectors #0607
finderOptions protected => array ()
lazyLoad protected => FALSE
keyIndex protected => array (1)
11903 => 0
numTotal protected => 1
numLimit protected => 5
numStart protected => 0
data protected => array (1)
0 => ProcessWire\Page #9d06
extraData protected => array ()
itemsRemoved protected => array ()
itemsAdded protected => array ()
duplicateChecking protected => TRUE
useFuel protected => TRUE
_instanceNum private => 1718
localHooks protected => array ()
trackChanges private => 2
changes private => array ()
_notices protected => array (3)
errors => NULL
warnings => NULL
messages => NULL
_wire protected => ProcessWire\ProcessWire #1005
debug protected => FALSE
fuel protected => ProcessWire\Fuel #4473
data protected => array (29) [ ... ]
lock protected => array (21) [ ... ]
requiredInterfaces protected => array (1) [ ... ]
pathSave protected => ""
instanceID protected => 0
shutdown protected => ProcessWire\WireShutdown #090d
useFuel protected => TRUE
_instanceNum private => 3
localHooks protected => array ()
trackChanges private => 0
changes private => array ()
_notices protected => array (3)
errors => NULL
warnings => NULL
messages => NULL
_wire protected => ProcessWire\ProcessWire #1005 { RECURSION }

EDIT:

I do get an error by TracyDebugger though when I click on the 'Blog' tab in the backend: 

Illegal offset type on line 916 in ProcessBlog.module $posts->title => array('published' => $qn['blog-post'], 'unpublished' => $qn['unpublished'] ),

I can skip the error while everything keeps working. I don't know if that has anything to do with it. Just wanted to let you know.

Link to comment
Share on other sites

17 minutes ago, Harmen said:

The echo returns '1', which is correct. There is one post published.

Just two things then. If you run the same code without the 'include=all', what do you get? If you still get something, then your post is published. Secondly, do you echo out $content; anywhere?

18 minutes ago, Harmen said:

I do get an error by TracyDebugger though when I click on the 'Blog' tab in the backend: 

It is unrelated and has been on my todo list :-), thanks.

Link to comment
Share on other sites

13 minutes ago, kongondo said:

If you run the same code without the 'include=all', what do you get?

Nothing. But the page is published, so it should be listed right?

408332055_Schermafbeelding2018-10-04om14_51_00.png.d68270067e75576e1fe7a2839a4f06e5.png

1223336938_Schermafbeelding2018-10-04om14_50_47.png.3fe40eb951896a2a930fef86aedf6b00.png

13 minutes ago, kongondo said:

Secondly, do you echo out $content; anywhere?

Yeah I use $content all the time. I just wanted to list the posts so I could apply my own CSS after the code for the listing is done.

So my blog.php file looks like this now:

<?php namespace ProcessWire;

// CALL THE MODULE - MarkupBlog
$blog = $modules->get("MarkupBlog");

// === Get the limit
$settings = $pages->get('template=blog-settings');
$limit = $settings->blog_quantity;

// === Initialize $content
$content = '';

// Render limited number of posts on Blog Home Page
$content .= $blog->renderPosts("limit=$limit"); // => Returns "No posts found"

// === Code for testing purposes to see the difference
//$posts = $pages->find('template=blog-post,limit=5, include=all'); => Returns 1
$posts = $pages->find('template=blog-post,limit=5'); // => Returns 0
$content .= $posts->count;

$options = array(
    "Breadcrumbs" => true,
);

// === Function to render the whole page, including some options and markup
$content = renderPage($page, $content, $options);

 

Link to comment
Share on other sites

3 minutes ago, Harmen said:

Nothing. But the page is published, so it should be listed right?

If it returns nothing and the page is published (as we can see from your screenshot), the only thing left is some access control cascading down to your blog template.  Do you just have the one post? Could you create a couple more and test? This one has me stumped to be honest.

 

Link to comment
Share on other sites

So i've created 3 more posts with some sample content:

1348148196_Schermafbeelding2018-10-04om15_11_34.png.1e728c9c7d962b2ef42d67f3ceac3192.png

The $blog->renderPosts("limit=$limit") function still returns that it can't find any posts. If I add include=all to the line to find the post, then I can find all the posts. IDK what is going on here

 

Link to comment
Share on other sites

On 10/4/2018 at 5:15 PM, kongondo said:

I'm getting a 404 on that page 🙂

Yeah I finally found the culprit. This is a multi-lingual website with up to 9 languages. I guess the module created the pages with only one language enabled to be viewed and I had to click the checkbox for the other pages manually. I should've seen this earlier 😕 Thanks for the great and fast support though. 

Link to comment
Share on other sites

4 minutes ago, Harmen said:

Yeah I finally found the culprit. This is a multi-lingual website with up to 9 languages. I guess the module created the pages with only one language enabled to be viewed and I had to click the checkbox for the other pages manually. I should've seen this earlier 😕 Thanks for the great and fast support though. 

Glad you got it sorted 🙂

Link to comment
Share on other sites

  • 4 weeks later...

 


Hello, let's see if anyone can help me. I'm new to processwire and php, and that's probably the problem.

I am using the module and it works well for me and I understand it. The problem is that I have a template with its corresponding div and styles, and I would like to take comments for a post, for example.

I get show everything with
 

$ blog-> renderComments ($ page-> blog_comments)

But I would like individually the author of the comment, the date, the body. Then with a loop assign it and repeat it as many times as there are comments, and so keep the style of my page.

 

Maybe this is not the right way to do it, but I can not think of another way, if you can help me I'll be very grateful, a greeting

Link to comment
Share on other sites

1 hour ago, colinosoft said:

But I would like individually the author of the comment, the date, the body. Then with a loop assign it and repeat it as many times as there are comments, and so keep the style of my page.

The blog module uses PW's core Comments field type. You can either use its render() method and pass in templates that generate the desired output, or iterate over the comments yourself and assemble the HTML. All of that is explained in FieldtypeComment's documentation.

  • Like 1
Link to comment
Share on other sites

2 hours ago, BitPoet said:

The blog module uses PW's core Comments field type. You can either use its render() method and pass in templates that generate the desired output, or iterate over the comments yourself and assemble the HTML. All of that is explained in FieldtypeComment's documentation.

Thank you very much, just what I needed, now I have everything much more clear, thank you.

Link to comment
Share on other sites

20 hours ago, BitPoet said:

The blog module uses PW's core Comments field type. You can either use its render() method and pass in templates that generate the desired output, or iterate over the comments yourself and assemble the HTML. All of that is explained in FieldtypeComment's documentation.

 

Ok I almost have it, the only thing I can not do is style the form to leave comments, the textbox and the send button do not just take the style of my page. If you can help me, I would greatly appreciate it, greetings.

Link to comment
Share on other sites

  • 3 months later...

Hello

Several years ago I made a PW website using the blog module ( https://olikehrli.ch/ ).

The internet provider is updating the PHP now. The blog module is using PHP 5.6 and it will be PHP 7.

Can somebody tell me if it will still run as it should, and if not what can i do to make sure it works fine.

 

What is the best action here?

What could happen in the worst case?

How do I make sure that everything will run as it should?

 

Any help would be greatly appreciated. I am somehow lost on this topic.

 

Thanks

Jakob

Link to comment
Share on other sites

I would simply backup the site and run it locally, e.g. with Laragon and a recent PHP version. Activate debug-mode in site/config.php, and test everything (backend and frontend). If there are PHP errors or warnings, it should be easy to fix them.

  • Like 3
Link to comment
Share on other sites

5 hours ago, kuba2 said:

Can somebody tell me if it will still run as it should

Working fine here on PHP 7.2. However, I'd still do what @dragan suggested. Upgrades have a tendency to go awry :-). Also note that despite your best efforts to test locally, things may not always work as they should in your remote install. Often times it is because your host changed a setting in the server during the upgrade and worse, didn't even tell you about it! You'd be left in the dark blaming PHP 7 or some other module or ProcessWire only to realise a couple of emails later that actually, none of these were to blame 🙂 and the culprit was a seemingly unrelated server setting. Hopefully, this doesn't happen to you...I'm not scaremongering; just thought you should be aware 😃.

  • Like 2
Link to comment
Share on other sites

  • 2 months later...

Is there a way to call the featured image function separate from the renderPosts function?  We have a need to both render that separately in some footer widgets we built plus I need to get access to the feature image for some JSON output that we provide to another team for inclusion in another web app.

Link to comment
Share on other sites

On 4/26/2019 at 8:34 PM, Karinne Cyphers said:

Is there a way to call the featured image function separate from the renderPosts function?  We have a need to both render that separately in some footer widgets we built plus I need to get access to the feature image for some JSON output that we provide to another team for inclusion in another web app.

How are you setting up your featured image? Blog will first attempt to check for a featured image by getting the first image with the tag 'featured' or whatever tag you passed to it in the option 'post_image_tag'. If no image is found and the rendered Blog Post is a 'small one', i.e. summarised, it will try to get the first embedded image in blog_body if blog_body is not blank. Assuming you are using the former approach (meaning you tag your featured images), you can just use ProcessWire API directly to get the featured image using getTag(). Here are some examples:

# retrieve first image with the tag 'featured' or user-specified 'tag' #

// assuming you are on a blog-post page
$image = $page->blog_images->getTag('featured');
$image = $page->blog_images->getTag($options['post_image_tag']);
$image = $page->blog_images->getTag('some-tag');

// getting the blog page(s) from another page
$p = $pages->get(1234);
$image = $p->blog_images->getTag('my-tag');

// we got an image
if($image) {
// go wild
}

 

Link to comment
Share on other sites

On 4/27/2019 at 4:58 PM, kongondo said:

How are you setting up your featured image? Blog will first attempt to check for a featured image by getting the first image with the tag 'featured' or whatever tag you passed to it in the option 'post_image_tag'. If no image is found and the rendered Blog Post is a 'small one', i.e. summarised, it will try to get the first embedded image in blog_body if blog_body is not blank. Assuming you are using the former approach (meaning you tag your featured images), you can just use ProcessWire API directly to get the featured image using getTag(). Here are some examples:


# retrieve first image with the tag 'featured' or user-specified 'tag' #

// assuming you are on a blog-post page
$image = $page->blog_images->getTag('featured');
$image = $page->blog_images->getTag($options['post_image_tag']);
$image = $page->blog_images->getTag('some-tag');

// getting the blog page(s) from another page
$p = $pages->get(1234);
$image = $p->blog_images->getTag('my-tag');

// we got an image
if($image) {
// go wild
}

 

We have a large number of imported posts that have no featured image tagged... moving forward the content folks will start tag a featured image, but for these older posts we have been using the summarized one when we use the renderPosts function with the small option.  Since we have a number of other pages where we just need to pull out select chunks of the blog post, like the summary, featured image, etc, it would be nice to be able to get the first embedded image in blog_body.

Link to comment
Share on other sites

On 4/29/2019 at 8:29 PM, Karinne Cyphers said:

it would be nice to be able to get the first embedded image in blog_body

I have something nearly ready for this as well as similar methods I worked on in the past but never got a chance to commit. I hope to conclude these by the end of this week. I'll post here when done.

Link to comment
Share on other sites

Update: Blog 2.4.3

Changelog

  1. Added method to find embedded images for use as featured image(s), for example. Thanks @Karinne Cyphers

How to use the method findEmbeddedImages($markup, $limit=1).

$blog = $modules->get("MarkupBlog"); 

$posts = $pages->find("template=blog-post,sort=-blog_date,limit=10");
foreach($posts as $post) {
		// get only one embedded image
		// $embeddedImages = $blog->findEmbeddedImages($post->blog_body);	
		// get 5 embedded images
		$embeddedImages = $blog->findEmbeddedImages($post->blog_body,5);
		// if embedded images found
		if(count($embeddedImages)) {
			// do something with $embeddedImages array
			// simple array where each value is a URL to the embedded image
		}
}

As you can see, the $markup is not limited to blog_body.

Module has been updated in the modules directory.

  • Like 1
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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Robin S
      This module lets you add some custom menu items to the main admin menu, and you can set the dropdown links dynamically in a hook if needed.
      Sidenote: the module config uses some repeatable/sortable rows for the child link settings, similar to the ProFields Table interface. The data gets saved as JSON in a hidden textarea field. Might be interesting to other module developers?
      Custom Admin Menus
      Adds up to three custom menu items with optional dropdowns to the main admin menu.
      The menu items can link to admin pages, front-end pages, or pages on external websites.
      The links can be set to open in a new browser tab, and child links in the dropdown can be given an icon.
      Requires ProcessWire v3.0.178 or newer.
      Screenshots
      Example of menu items

      Module config for the menus

      Link list shown when parent menu item is not given a URL

      Advanced
      Setting child menu items dynamically
      If needed you can set the child menu items dynamically using a hook.
      Example:
      $wire->addHookAfter('CustomAdminMenus::getMenuChildren', function(HookEvent $event) { // The menu number is the first argument $menu_number = $event->arguments(0); if($menu_number === 1) { $colours = $event->wire()->pages->findRaw('template=colour', ['title', 'url', 'page_icon']); $children = []; foreach($colours as $colour) { // Each child item should be an array with the following keys $children[] = [ 'icon' => $colour['page_icon'], 'label' => $colour['title'], 'url' => $colour['url'], 'newtab' => false, ]; } $event->return = $children; } }); Create multiple levels of flyout menus
      It's also possible to create multiple levels of flyout submenus using a hook.

      For each level a submenu can be defined in a "children" item. Example:
      $wire->addHookAfter('CustomAdminMenus::getMenuChildren', function(HookEvent $event) { // The menu number is the first argument $menu_number = $event->arguments(0); if($menu_number === 1) { $children = [ [ 'icon' => 'adjust', 'label' => 'One', 'url' => '/one/', 'newtab' => false, ], [ 'icon' => 'anchor', 'label' => 'Two', 'url' => '/two/', 'newtab' => false, 'children' => [ [ 'icon' => 'child', 'label' => 'Red', 'url' => '/red/', 'newtab' => false, ], [ 'icon' => 'bullhorn', 'label' => 'Green', 'url' => '/green/', 'newtab' => false, 'children' => [ [ 'icon' => 'wifi', 'label' => 'Small', 'url' => '/small/', 'newtab' => true, ], [ 'icon' => 'codepen', 'label' => 'Medium', 'url' => '/medium/', 'newtab' => false, ], [ 'icon' => 'cogs', 'label' => 'Large', 'url' => '/large/', 'newtab' => false, ], ] ], [ 'icon' => 'futbol-o', 'label' => 'Blue', 'url' => '/blue/', 'newtab' => true, ], ] ], [ 'icon' => 'hand-o-left', 'label' => 'Three', 'url' => '/three/', 'newtab' => false, ], ]; $event->return = $children; } }); Showing/hiding menus according to user role
      You can determine which menu items can be seen by a role by checking the user's role in the hook.
      For example, if a user has or lacks a role you could include different child menu items in the hook return value. Or if you want to conditionally hide a custom menu altogether you can set the return value to false. Example:
      $wire->addHookAfter('CustomAdminMenus::getMenuChildren', function(HookEvent $event) { // The menu number is the first argument $menu_number = $event->arguments(0); $user = $event->wire()->user; // For custom menu number 1... if($menu_number === 1) { // ...if user does not have some particular role... if(!$user->hasRole('foo')) { // ...do not show the menu $event->return = false; } } });  
      https://github.com/Toutouwai/CustomAdminMenus
      https://processwire.com/modules/custom-admin-menus/
    • By tcnet
      This module for ProcessWire sends a notification email for each failed login attempt. Similar modules exists already in the module directory of ProcessWire. However, this module is designed to notify, even if specified user doesn't exist.
      Settings
      The settings for this module are located in the menu Modules=>Configure=>LoginFailNotifier.
      Notification email
      Specifies the email address to which the notification emails should be sent.
        Email subject
      Specifies the subject line for the notification email.
        Post variables
      Specifies the $_POST variables to be included in the notification email. Each variable must be separated by a comma. For example: login_name,login_pass
        Server variables
      Specifies the $_SERVER variables to be included in the notification email. Each variable must be separated by a comma. For example: REMOTE_ADDR,HTTP_USER_AGENT
      Link to ProcessWire module directory:
      https://processwire.com/modules/login-fail-notifier/
      Link to github.com:
      https://github.com/techcnet/LoginFailNotifier
    • By Fokke
      ProcessWire 3.x markup module for rendering meta tags in HTML document head section. Note that this module is not a full-blown SEO solution, but rather a simple tool for rendering meta tags based on module configuration. Adding custom meta tags is also supported.
      Built-in meta tags
      The following meta tags are supported out-of-the-box:
      Document title consisting of page title and site name Character set Canonical Viewport Description Keywords Hreflang tags Open Graph og:title og:site_name og:type og:url og:description og:image og:image:width og:image:height Twitter meta tags twitter:card twitter:site twitter:creator twitter:title twitter:description twitter:image Facebook meta tags fb:app_id The full documentation with configurable options can be found here: https://github.com/Fokke-/MarkupMetadata
       
      Requirements:
      ProcessWire>=3.0.0 PHP >=7.1 Installation using Composer
      composer require fokke/markup-metadata Manual installation
      Download latest version from https://github.com/Fokke-/MarkupMetadata/archive/master.zip Extract module files to site/modules/MarkupMetadata directory.
    • By m.sieber
      ITRK-Service for ProcessWire
      Module for the automated transfer of imprint, data protection declaration and terms and conditions from IT-Recht Kanzlei to your ProcessWire installation
      What is ITRK Service for ProcessWire?
      ITRK-Service for ProcessWire is a free module for ProcessWire CMS. It provides an interface to the update service of IT-Recht Kanzlei, via which the legal texts of your online presence are automatically updated. In this way, the texts remain legally secure and warning-proof in the long term. Imprint, data protection declaration, revocation and general terms and conditions are currently supported.
      You can find our documentation (in german language) here: https://www.pupit.de/itrk-service-for-processwire/dokumentation/

      Download: https://www.pupit.de/itrk-service-for-processwire/
      Github: https://github.com/pupit-de/pwItrkServiceConnector
    • By LuisM
      Symprowire is a PHP MVC Framework based and built on Symfony using ProcessWire 3.x as DBAL and Service-Provider
      It acts as a Drop-In Replacement Module to handle the Request/Response outside the ProcessWire Admin. Even tough Symfony or any other mature MVC Framework could be intimidating at first, Symprowire tries to abstract Configuration and Symfony Internals away as much as possible to give you a quick start and lift the heavy work for you.
      The main Goal is to give an easy path to follow an MVC Approach during development with ProcessWire and open up the available eco-system.
      You can find the GitHub Repo and more Information here: https://github.com/Luis85/symprowire
      Documentation
      The Symprowire Wiki https://github.com/Luis85/symprowire/wiki How to create a simple Blog with Symprowire https://github.com/Luis85/symprowire/wiki/Symprowire-Blog-Tutorial Last Update
      16.07.2021 // RC 1 v0.6.0 centralized ProcessWire access trough out the Application by wrapping to a Service https://github.com/Luis85/symprowire/releases/tag/v0.6.0-rc-1 Requirements
      PHP ^7.4 Fresh ProcessWire ^3.0.181 with a Blank Profile Composer 2 (v1 should work, not recommended) The usual Symfony Requirements Features
      Twig Dependency Injection Monolog for Symprowire Support for .env YAML Configuration Symfony Console and Console Commands Symfony Webprofiler Full ProcessWire access inside your Controller and Services Webpack Encore support Caveats
      Symfony is no small Framework and will come with a price in terms of Memory Usage and added Overhead. To give you a taste I installed Tracy Debugger alongside to compare ProcessWire profiling with the included Symfony Webprofiler

      So in a fresh install Symprowire would atleast add another 2MB of Memory usage and around 40ms in response time, should be less in production due to the added overhead of the Webprofiler in dev env
       
×
×
  • Create New...