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
×
×
  • Create New...