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 MarkE
      This fieldtype and inputfield bundle was built for storing measurement values within a field, rendering them in a variety of formats and converting them to other units or otherwise modifying them via the API.
      The API consists of a number of predefined functions, some of which include...
      render() for rendering the measurement object, valueAs() for converting the value to another unit value, convertTo() for converting the whole measurement object to different units, and add() and subtract() for for modifying the stored value by the value (converted as required) in another measurement. In the admin the inputfield includes a checkbox (which can be optionally disabled) for converting values on page save. For an example if a value was typed in as centimeters, the unit was changed to metres, and the page saved with this checkbox selected, said value would be automatically converted so that e.g. 170 cm becomes 1.7 m.

      A simple length field using Fieldtype Measurement and Inputfield Measurement.
      Combination units (e.g. feet and inches) are also supported.
      Please note that this module is 'proof of concept' at the moment - there are limited units available and quite a lot of code tidying to do. More units will be added shortly.
      See the GitHub at https://github.com/MetaTunes/FieldtypeMeasurement for full details and updates.
    • By tcnet
      File Manager for ProcessWire is a module to manager files and folders from the CMS backend. It supports creating, deleting, renaming, packing, unpacking, uploading, downloading and editing of files and folders. The integrated code editor ACE supports highlighting of all common programming languages.
      https://github.com/techcnet/ProcessFileManager

      Warning
      This module is probably the most powerful module. You might destroy your processwire installation if you don't exactly know what you doing. Be careful and use it at your own risk!
      ACE code editor
      This module uses ACE code editor available from: https://github.com/ajaxorg/ace

      Dragscroll
      This module uses the JavaScript dragscroll available from: http://github.com/asvd/dragscroll. Dragscroll adds the ability to drag the table horizontally with the mouse pointer.
      PHP File Manager
      This module uses a modified version of PHP File Manager available from: https://github.com/alexantr/filemanager
       
    • By tcnet
      This module implements the website live chat service from tawk.to. Actually the module doesn't have to do much. It just need to inserted a few lines of JavaScript just before the closing body tag </body> on each side. However, the module offers additional options to display the widget only on certain pages.
      Create an account
      Visit https://www.tawk.to and create an account. It's free! At some point you will reach a page where you can copy the required JavaScript-code.

      Open the module settings and paste the JavaScript-code into the field as shown below. Click "Submit" and that's all.

      Open the module settings
      The settings for this module are located int the menu Modules=>Configure=>LiveChatTawkTo.

       
    • By tcnet
      Session Viewer is a module for ProcessWire to list session files and display session data. This module is helpful to display the session data of a specific session or to kick out a logged in user by simply delete his session file. After installation the module is available in the Setup menu.

      The following conditions must be met for the module to work properly:
      Session files
      Session data must be stored in session files, which is the default way in ProcessWire. Sessions stored in the database are not supported by this module. The path to the directory where the session files are stored must be declared in the ProcessWire configuration which is by default: site/assets/sessions.
      Serialize handler
      In order to transform session data easier back to a PHP array, the session data is stored serialized. PHP offers a way to declare a custom serialize handler. This module supports only the default serialize handlers: php, php_binary and php_serialize. WDDX was dropped in PHP 7.4.0 and is therefore not supported by this module as well as any other custom serialize handler. Which serialize handler is actually used you can find out in the module configuration which is available under Modules=>Configure=>SessionViewer.

      Session data
      The session data can be displayed in two different ways. PHP's default output for arrays print_r() or by default for this module nice_r() offered on github: https://github.com/uuf6429/nice_r. There is a setting in the module configuration if someone prefers print_r(). Apart from the better handling and overview of the folded session data the output of nice_r() looks indeed nicer.

      Links
      ProcessWire module directory
      github.com
    • By Robin S
      Repeater Easy Sort
      Adds a compact "easy-sort" mode to Repeater and Repeater Matrix, making those fields easier to sort when there are a large number of items.
      The module also enhances Repeater Matrix by allowing a colour to be set for each matrix type. This colour is used in the item headers and in the "add new" links, to help visually distinguish different matrix types in the inputfield.
      Screencasts
      A Repeater field

      A Repeater Matrix field with custom header colours

      Easy-sort mode
      Each Repeater/Matrix item gets an double-arrow icon in the item header. Click this icon to enter easy-sort mode.
      While in easy-sort mode:
      The items will reduce in width so that more items can be shown on the screen at once. The minimum width is configurable in the field settings. Any items that were in an open state are collapsed, but when you exit easy-sort mode the previously open items will be reopened. You can drag an item left/right/up/down to sort it within the items. The item that you clicked the icon for is shown with a black background. This makes it easier to find the item you want to move in easy-sort mode. You can click an item header to open the item. An "Exit easy-sort mode" button appears at the bottom of the inputfield. Configuration
      In the field settings for Repeater and Repeater Matrix fields you can define a minimum width in pixels for items in easy-sort mode. While in easy-sort mode the items will be sized to neatly fill the available width on any screen size but will never be narrower than the width you set here.
      In the field settings for Repeater Matrix you can define a custom header colour for each matrix type using an HTML "color" type input. The default colour for this type of input is black, so when black is selected in the input it means that no custom colour will be applied to the header.
      Exclusions
      The easy-sort mode is only possible on Repeater/Matrix fields that do not use the "item depth" option.
       
      https://github.com/Toutouwai/RepeaterEasySort
      https://processwire.com/modules/repeater-easy-sort/
×
×
  • Create New...