Jump to content

Module: Blog


kongondo

Recommended Posts

So as an example I had a user whos username was 'test555' I changed their Display Name (required by the blog) to be Jane Doe and low and behold it changes the actual Name (username) to jane-doe so it's actually renaming the username.

 

I saw a mention of this item: AutoName or PageRenameOptions module installed which they are so I'll try updating those and report back to see if that fixed anything

 

Definitely one of those two modules - if it happens on page save then it's the former. If it happens in realtime then it is the latter. Anyway, they should both be fixed now.

You should be careful using those two modules together - one will override the other depending on your requirements.

 

Again, sorry for the hassles.

 

EDIT: Looks like our posts crossed - but glad to see it is working for you now!

Link to comment
Share on other sites

I am not sure if this is possible and maybe a bit of work to implement but I imagine a 2 textareas where the markup can be customised for the post or posts.

One for full posts (blog-post.php) and one for truncated posts ($small).

In each of these textareas html and short codes or variables could be entered which represent different parts of the post such as [featured] and [post-headline] etc...

Then this is output with renderPosts()

@dazzyweb, thanks for the ideas. I am hesitant to approach the issue in this fashion. I feel it will produce some layer of complexity (text output formatting) to achieve something that can already be achieved out of the box with the current Blog. If there is to be any 'complexity', that should be left to the dev (e.g. the $options in renderPosts()) rather than to everyday editors using the GUI to post articles. Like I stated earlier, the featured image, post-headline visibility, etc features are easily achievable via using the $options in renderPosts(). Maybe once I have posted the working code you'll see how much easier it is to achieve the layout you want. Alternatively, there is also the option of using HannaCode to output code where you want. I will also make it possible to toggle the visibility of post-by-line, post-categories and post-tags in the code I am working on. The unresolved issue is the social media buttons but we'll get to that eventually.

Cheers

Edited by kongondo
Link to comment
Share on other sites

@dazzyweb, thanks for the ideas. I am hesitant to approach the issue in this fashion. I feel it will produce some layer of complexity (text output formatting) to achieve something that can already be achieved out of the box with the current Blog. If there is to be any 'complexity', that should be left to the dev (e.g. the $options in renderPosts()) rather than to everyday editors using the GUI to post articles.

I wasn't really thinking about a case where everyday editors would alter the markup output but rather as something that would be set up by the developer in 2 areas to set out the preferred markup/output for the full posts and truncated posts dependent on the posts design layout. I was just trying to think of something whereby the developer could have more control over the markup output. Probably there is a better way than i suggested :)

 Alternatively, there is also the option of using HannaCode to output code where you want. I will also make it possible to toggle the visibility of post-by-line, post-categories and post-tags in the code

I am not sure how I would be able to make certain changes or add content inside of the markup already output by renderPosts() using hanna code without a putting hanna code inserted in the module. I understand that it could be added before or after a post. (maybe I am missing something here).

I will also make it possible to toggle the visibility of post-by-line, post-categories and post-tags in the code I am working on. The unresolved issue is the social media buttons but we'll get to that eventually.

I look forward to this.

One other things Is there a way to change the headings for post headline with current setup without editing the module?. For example there might be times that <h1> is preferred to <h2> for the post headline.

Many Thanks for all the work you are putting into this module.

Link to comment
Share on other sites

@Dazzyweb..

<h1> versus <h2>:

I'll see whether to include this in the renderPosts() $options. Of course <h1> should not be the case if outputting more than one post on a single page!

Your other questions should be answered in the following (I hope).

Social Media Icons

I did a lot of thinking regarding how to implement social media icons in both $small and full posts (whether single or a list). I bounced a few ideas around:

1. Create a Social Media Icons Widget

Seemed OK on paper, maybe with repeaters. But, there's several social networking services/sites out there as well as many approaches to include them (buttons) in one's website. OK, it mainly involves using javascript but Twitter's and G+ are different. So are FBs, etc. We don't want to be messing with that in the GUI.  So, I shelved this idea. It would be impossible to cater for all the different Social sites and the approaches to implement their icons/buttons. Twitter alone has 'share', 'follow' blah blah...

2. Include SMI using Hanna Code. Great! 

Great I thought. One could include the buttons anywhere in their blog_body. However, this wouldn't work for $small posts. This is because these are rendered after passing through strip_tags() which was stripping out everything so would strip out Hanna Codes output markup as well. It reminded me about this post. Of course strip_tags() has a second parameter for $allowable_tags! So at the API level, I have now made this configurable in renderPosts() $options. The dev can specify which tags they want not to be stripped out - e.g. place an image at the top of your post that you want to be rendered with the $small post (currently it would be stripped out). Use the feature with caution of course! :-)

In addition it would be very tedious adding Hanna Code tags in each and every post! OK, maybe one could automate this using Hanna Code API but don't know if that would work. Ideally, we want to add our icons at the template file level...I think...

3. Developer to include SMI in their template files!

At first I thought this would only work great for single posts. Render the single post and include the SMI beneath the post. This would not work well for a list of posts, whether full or $small. But aah, ProcessWire is OOP! We can manipulate objects on the fly! So, we can 'inject' some extra input into our objects properties or even create new ones and output those. Now, I would really love to hear what the other seasoned devs think about this (see code below). Any issues using this approach? Is there a better way? If posts fetched and manipulated this way were limited to some small number, would there still be issues?

So, this is what I came up with so far in my limited tests, seems to work well (especially in conjunction with $allowable_tags).  Here, we add a Twitter Share Button. I am not sure $post->url is working fine though (relative url?).  A count of tweets should be showing next to the button (see screenshot below). I haven't read up properly on how to implement the Twitter buttons. Have a read here (twitter dev).

<?php 

 $posts = $pages->find('template=blog-post, limit=10');

 foreach($posts as $post) {
    
    $socialMedia = '

      <a href="https://twitter.com/share" class="twitter-share-button" 

       data-size="large"
       data-url="' . $post->url . '">

       Tweet
     </a>';

 //we manipulate each $post object's blog_body property. we add twitter 'share' button
 $post->blog_body = $socialMedia . $post->blog_body;//prepend social media code to $post->blog_body

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

 //main content
 $content = $blog->renderPosts($posts, true);//$posts is a PageArray; true means truncate post

?>
<!-- in our HTML in appropriate places -->
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+'://platform.twitter.com/widgets.js';fjs.parentNode.insertBefore(js,fjs);}}(document, 'script', 'twitter-wjs');
</script>

<div>
<h1 id="headline">Testing Social Media Icons</h1>

<?php echo $content;?>

</div>																	

Notice here we've allowed <img><a> in the summarised post.

post-894-0-05755900-1414157048_thumb.png

Other than this, I have almost finished making renderPosts() highly configurable using $options - e.g. ability to change 'View More' to whatever you want, e.g. 'Continue Reading'; List a post's tags/categories (separately) or not and whether to list them at the top of the post or at the bottom; change 'Posted by' to whatever you want or not include this info, etc. 

Link to comment
Share on other sites

Upcoming update: Blog version 2.2.1. (dev)
 
Summary of Changes: All main methods that render HTML output are now configurable via a parameter/argument $options
 
These changes allow much greater control of your Blog features' layout/output. I will provide examples later but most of the below is hopefully self-explanatory.
 
Please note these changes supersede those introduced in version 2.1.1 and 2.1.0 (some name changes to array indices + some additions).
 
None of the changes will break your existing install if you are using the stable Blog branch. However, if you updated to 2.1.1 on the dev branch, AND started using some of its new optional features, some minor modifications to template files could be required (i.e, following the examples shown in 2.1.0, e.g. for renderPosts(), $featuredImage parameter is now $options and covers all aspects of rendered posts, not just featured images. E.g. to display a featured image on a summarised post, use array('post_small_image'=>xxx) as shown below.
 
I have updated  the dev branch for testing/comments, thanks. I will update the docs once I merge to master branch.
 
New Default Options in MarkupBlog Methods
 
renderPosts()


//default options for various aspects of posts
$defaultOptions = array(
  
  'post_count' => 1,//0=off, 1=on - for the count in: Posts 1 to 5 of 15
  'post_count_text' =>$this->_('Post'),//e.g. Posts 1 to 5 of 15
  'post_not_found' => $this->_('No posts found.'),//message when no posts found
  'post_author' => 1,//display name of post author: 0=off,1=top(below post-headline),2=bottom(in post-foot)
  'post_author_text' => $this->_('Posted by'),//
  'post_date' => 1,//display post's date: 0=off,1=top(below post-headline),2=bottom(in post-foot)
  'post_date_text' => '',//e.g. Posted by author 'on' date
  'post_more_text' => $this->_('View More'),//for $small posts - link text to full post
  'post_categories' => 2,//display post's categories: 0=off,1=top(below post-byline),2=bottom(in post-foot)
  'post_categories_text' => $this->_('Categories:'),//e.g. 'Categories', 'In', 'Filed under', etc
  'post_tags' => 2,//display post's tags: 0=off,1=top(below post-byline),2=bottom(in post-foot)
  'post_tags_text' => $this->_('Tags:'),//e.g. 'Tagged', 'Related', etc
  'post_small_allowable_tags' => '',//holds string of HTML tags for strip_tags $allowable_tags. Needs to be in format '<code><p><img>'
  'post_small_headline_tag' => 'h4',
  'post_large_headline_tag' => 'h2',
  'post_comments' => 1,//show comments info? 0=off,1=comments count top,2=comments count bottom,3=comments count top & bottom
  'post_zero_comments_text' => $this->_('No comments yet'),
  'post_comments_text' => $this->_('Comment,Comments'),//title in anchor comments icon + post-foot comments text, e.g. '2 Comments' or '1 Comment'. Must be in 'singular,plural' format
  'post_comments_label' => $this->_('Comments:'),//this appears in post-foot, e.g. 'Comments': 2 Comments
  
  //## featured images ##
  'post_image_alt' => 'description',//defaults to $image->description. Otherwise other stated field on the page, e.g. = 'title'
  'post_image_tag' => 'featured',//string: image tag to look for in blog_images//@@todo - need translation here?
    
   //** small/truncated post featured image **
  'post_small_image' => 0,//display post's featured image: 0=off,1=top(above post-headline),2=bottom(first item in post-body)
  'post_small_image_width' => '',//no width manipulation of featured image if this is blank or 0
  'post_small_image_height' => '',//no height manipulation if this is blank or 0. Note, if size is true and both width and height > 0, use size() instead
  
  /*size: 
  -	image will be resized to exact dimensions -> $img = $image->size($x, $y)
  -	where $x = 'width' and $y = 'height'*/
  'post_small_image_size' => false,//if 'size' = true AND both width and height > 0, this kicks in
  
  //** large/full post featured image NOTE: for full posts, to avoid duplication we only pull image from blog_images **
  'post_large_image' => 0,//display post's featured image: 0=off,1=top(above post-headline),2=bottom(first item in post-body)
  'post_large_image_width' => '',//no width manipulation of featured image if this is blank or 0
  'post_large_image_height' => '',//no height manipulation if this is blank or 0. Note, if size is true and both width and height > 0, use size() instead				
  'post_large_image_size' => false,//if 'size' = true AND both width and height > 0, this kicks in

);

 
renderTags()

//default options for tags
$defaultOptions = array(
  'tags_posts_text' =>$this->_('post,posts'),//come in the format 'singular,plural' for e.g. 1 'post'
);

 
renderCategories()

//default options for categories
$defaultOptions = array(
  'categories_posts_text' =>$this->_('post,posts'),//come in the format 'singular,plural' for e.g. October 5 'posts'
  'categories_not_found' => $this->_('No categories to display.'),//message when no posts found
  'categories_more_text' => $this->_('View More'),//link text to view all posts in that category
);

postAuthor()


//default options for author widget
$defaultOptions = array(
  'author_text' => $this->_('Author'),//text next to author title|name
  'author_thumb_width' => 100,//no width manipulation of author thumb if this is blank or 0
  'author_thumb_height' => '',//no height manipulation of author thumb if this is blank or 0
  'author_thumb_alt' => 'title',//defaults to $author->title. Otherwise other stated field on the page, e.g. = 'title' or if 'description' then $image->description
);

renderNextPrevPosts()


//default options for next/prev posts
$defaultOptions = array(
  'prev_post' => '<',//tag/text for previous post, e.g. «, «, etc, i.e. << >>, etc
  'next_post' => '>',//tag/text for next post, e.g. ›, etc
  'prev_post_text' => 'title',//if title or not empty: will show title of the prev post. Otherwise show specificed text, e.g. 'Older entries'
  'next_post_text' => 'title',//if title or not empty: will show title of the next post. Otherwise show specificed text, e.g. 'Newer entries'
);

 
renderComments() - was already configurable; here showing new additions only

//ADDITIONAL default options for comments
$defaultOptions = array(
  'comments_success' => $this->_('Thank you, your submission has been saved.'),
  'comments_error' => $this->_('Your submission was not saved due to one or more errors. Try again.'),
  'comments_text' => $this->_('Comment,Comments'),//comments text, e.g. 2 'Comments' or 1 'Comment' next to comments count (div#comments). Must be in 'singular,plural' format
  'comments_list_empty' => $this->_('No comments found.'),
  'comments_list_reply_text' => $this->_('replied to'),
  'comments_by_text' => $this->_('Comment by'),
  'comments_post_text' => $this->_('Post a comment'),
  'comments_prev_text' => $this->_('Back'),
  'comments_next_text' => $this->_('Next'),
);

renderArchives()


//default options for archives
$defaultOptions = array(
  'archives_posts_text' =>$this->_('post,posts'),//come in the format 'singular,plural' for e.g. October 5 'posts'
  'archives_month_view_all_text' => $this->_('View All'),//'view all' that month's archives if limit set on amount to list
);
Edited by kongondo
  • Like 6
Link to comment
Share on other sites

@Dazzyweb..

<h1> versus <h2>:

I'll see whether to include this in the renderPosts() $options. Of course <h1> should not be the case if outputting more than one post on a single page!

You can always do something like this...

echo str_replace(array('<h3>','</h3>'),array('<h4>','</h4>'),$modules->get("MarkupBlog")->renderArchives($archives));

for a bit of control over output. (It just fits in a bit better in the sidebar of my blog which is now powered by PW and Kongondo's excellent module. BTW it isn't finished yet (probably never will be) but it is live.)

  • Like 2
Link to comment
Share on other sites

Well I'm finally getting around to trying to implement the blog within an existing site. I've installed it with comments enabled because I want comments down the track, but I want to launch without them. I've put the demo templates in to work from, although the formatting is slightly screwy for me, with the grid not seeming to work, but hat's a side issue. I'm trying to replace the demo files with my own layout.

So, I'm starting with blog.php. I don't need the blog-main.inc, so I've commented it out. I want to remove the comments count at the end of the post, and the number at the top, which I think is the number of comments made? it shows 0. I've put in the options below to remove the bottom text, but how do I get rid of the '0' at the top? Or is there a better way of hiding any references to comments for now, which I can enable again later?

    $options = array('post_zero_comments_text' => '',
                    'post_comments_label' => '');
    $content .= $blog->renderPosts("limit=$limit", $options);

Thanks

*EDIT*

I've moved on to the Sidebar, looking to re-style the Categories render, and have similar questions about changing the layout to something different than the renderNav() returns. It looks to me like it's doing both the desktop and mobile layouts at the same time? I'm not sure if there's an issue detecting mobile since I'm trying to add to a standard PW site?

Should I just look at the module code and create my own render functions?

*EDIT #2*

Found some of the issues I was having were conflicts between the site profile style I was using vs the blog layout style. I can get the blog to show properly by not loading _main.php on the page, but then the style is a complete mismatch with the rest of my site.

So I guess means I have to write my own render code, which pretty much means replacing the MarkupBlog module and associated blog-main.inc with my own, doesn't it?

Link to comment
Share on other sites

@Russell

Thanks for trying out Blog...

Comments count: Good catch. I will work on an option to not show either/both comments' count (i.e. at the top and/or at the bottom) that will override the other comment settings - label, zero text etc...

Layout: If you want to use the demo files, you are better of using the blank PW install otherwise (like you found out), _main.php gets in the way :-) (but there should be ways around that). 

About a mismatch with you site, as I have time and again said, Blog's demo files are just that; demos. They are meant to help you get started. If you know what you are doing (and have read the Blog docs), you don't need to install the demo files. You don't even need to use the template files that come with Blog. You can pretty much call up MarkupBlog from anywhere. So, yes, you don't need blog-main.inc, etc. Having said that, being a Markup Module, Blog has to output some HTML - mainly divs,spans, paragraphs, and anchor tags. That's about it. Styling your site and Blog to match is something left to you, the developer - its basically just CSS.

As for renderNav(), that's just a helper method available to you. You don't have to use it; you can create your own Blog navigation. Regarding the mobile detection, it just outputs a class 'no-mobile' that you can target using media queries as shown in the demo blog.css (did you look into that file btw? As per the instructions for installing Blog, It is not copied over automatically to your /site/templates). What other render code is this that you need to rewrite? You don't need to replace MarkupBlog module :D.

Have a look at this (work-in-progress) Blog by Dave. It uses the Blog module but it is pretty much customised to his needs. Similarly, here's another Blog by Peter.

I hope these have answered you query. If not, feel free to ask more :-)

Edited by kongondo
Link to comment
Share on other sites

Thanks.

Yeah I actually started out with the blank templates, but then I realised I didn't know how to access the ProcessBlog data, so I went back and reinstalled with the demo's. My bad I looked for the docs but didn't find them. That should solve all my problems, thanks :)

Russell.

Link to comment
Share on other sites

Minor updates: Blog version 2.2.1

1. Thanks @Russell, added a 'post_comments' option to renderPosts()

0=do not show comments count on a post

1=show only the top counts icon

2=show only the bottom counts

3=show both top and bottom counts

2. A couple of code optimisations

Updated the Dev branch and above post with all the options.

Next week I'll merge 2.2.1 into Master.

Link to comment
Share on other sites

Thanks for the quick update.

I just want to double check the update process. An earlier post in the thread said you can just upload the new module and update it from the admin area. So this won't try and reinstall anything, it will just update the code? Or should i just be copying in the updated module?

Link to comment
Share on other sites

Yes, if using PW 2.5

Modules -> New -> Add module from URL-> point to the zip file in Blog dev branch (if you can't wait till this coming week when I merge to Master). PW will upgrade Blog. Nothing will be reinstalled. The code will be updated. As usual, good to test first before deploying to a production environment. Yes, alternatively, you can manually overwrite the old module files with the new ones...You might then want to refresh your modules list for latest module version numbers to show...

Link to comment
Share on other sites

@Tramvai,

Thanks for using Blog.

Unfortunately not automatically. I think you should be able to easily achieve your design with the latest Blog (dev version 2.2.1). You can have a featured image. Using CSS (and maybe PHP as shown by Dave above in post #210), you should be able to line up your Post's date, category, author and comments - I should think...

Link to comment
Share on other sites

Thank you for your wonderful module, kondongo!  :) 

1) I put the module with the test content and for some reason when creating a new post, I can't choose a category(although one test category). Can I do something installed?

2) The user manual says that you need to put ShedulePages, but ShedulePages not supported PW 2.5.2. What to do if I 2.5.2?
3) You can make a sub-categories in a module?
4) And what caching would you recommend for the blog. Procache fit?

  • Like 1
Link to comment
Share on other sites

@Atano,

Welcome to PW and the forums. Thanks to trying out Blog..:-)

1. I am not sure what is happening in your case. How are you creating a new post, using the Quick Post or as a normal PW page (i.e. via the pages tree)?

2. SchedulePages works fine in PW 2.5.2

3. No; there is no support for sub-categories

4. Have a read here for PW caching options to assess what suits your needs best: http://www.flamingruby.com/blog/processwire-caching-explained/

  • Like 1
Link to comment
Share on other sites

@Kongondo

Any plans to introduce a Comments link on the Blog dashboard.

Clicking it would display a list of comments across all posts and have batch actions (approve, disapprove, block).

Also, we might be able to filter between categories and further filter between approved, disapproved and spam?

We don't ask for much, eh?  ;)

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...