1 2014-02-10 16:38:33 (edited by tovic 2014-02-21 08:37:03)

Topic: Blog Pagination (Next/Previous) for Morfy CMS

Index Page

http://i61.tinypic.com/2pysz6p.png

Item Page

http://i57.tinypic.com/153tob9.png

Installation

1. Download and extract this file, put the nextprev folder with its contents in plugins folder.

2. Update you config.php file:

 array(
            'markdown',
            'sitemap',
            'nextprev' // <= Activation
        ),
        'nextprev_config' => array( // <= Configuration
            'param' => 'page', // <= Page parameter name in URL
            'limit' => 5, // <= Number of posts to display per page
            'classes' => array( // <= List of item's HTML classes
                'page_item' => 'page',
                'nav' => 'pager',
                'nav_prev' => 'previous',
                'nav_next' => 'next',
                'nav_disabled' => 'disabled'
            ),
            'labels' => array( // <= List of item's readable text or labels
                'nav_prev' => '← Previous',
                'nav_next' => 'Next →',
                'not_found' => '

Not found.

' ) ) );

Updating Template File

The plugin includes index_nextprev for posts listing page and item_nextprev for individual page.

1. For blog.html, all posts loop will be replaced by the plugin:



runAction('theme_content_before'); ?> runAction('index_nextprev'); ?> runAction('theme_content_after'); ?>

2. For blog_post.html, the plugin will only return as a next/previous navigation:



runAction('theme_content_before'); ?>

Posted on

runAction('item_nextprev'); ?> runAction('theme_content_after'); ?>
XSS Testing

tovic's Website

2 2014-02-11 00:43:33 (edited by tovic 2014-02-11 00:44:57)

Re: Blog Pagination (Next/Previous) for Morfy CMS

There is a little update. Please re-download the plugin. Still trying to deal with pages that have more than one subpage. No error displayed, but all of the items, however depth the folders, are displayed within a single array if called with Morfy::factory()->getPages()

There’s no API method that can be used to retreive pages (file only) that’s only in the current folder, exluding the subfolder.

In CSS, you may know this kind of selector:

#root > folder > .file
#root
  -  folder
  -  -  i'll be selected
  -  -  folder
  -  -  -  but i'll not
  -  -  i'll be selected
  -  -  i'll be selected

We need that API.

XSS Testing

tovic's Website

Re: Blog Pagination (Next/Previous) for Morfy CMS

good job! big_smile

I'm not like them but I can pretend.

4 (edited by tovic 2014-02-12 01:13:09)

Re: Blog Pagination (Next/Previous) for Morfy CMS

Aryandhani wrote:

good job! big_smile

Hi thanks! I also already update the plugin to follow Bootstrap’s pagination markup and commented out the stylesheet hooks by default as you suggest. So users no longer need to append the extra stylesheet for this.

XSS Testing

tovic's Website

Re: Blog Pagination (Next/Previous) for Morfy CMS

My mistake. A little bug fix:

Replace this code in index_nextprev

to this:

Or just re-download the file.

XSS Testing

tovic's Website

Re: Blog Pagination (Next/Previous) for Morfy CMS

ok. I've was tried it. but, there is something wrong in index_nextprev on my themes. This:

echo $post['description'] ? '
' . $post['description'] . '
' : "";

Short content not show up. but when I replace it with this (content_short):

echo $post['content_short'] ? '
' . $post['content_short'] . '
' : "";

successfully. How could that be?

I'm not like them but I can pretend.

7 2014-02-14 00:20:40 (edited by tovic 2014-02-14 00:23:00)

Re: Blog Pagination (Next/Previous) for Morfy CMS

Aryandhani wrote:

ok. I've was tried it. but, there is something wrong in index_nextprev on my themes. This:

echo $post['description'] ? '
' . $post['description'] . '
' : "";

Short content not show up. but when I replace it with this (content_short):

echo $post['content_short'] ? '
' . $post['content_short'] . '
' : "";

successfully. How could that be?

That’s come from different field. $post['description'] come from here:

Title: Welcome
Description: Some description here. // <= this
Keywords: key, words
Author: Awilum
Date: 2013-12-31 00:00:00
Tags: tag1, tag2
Robots: noindex, nofollow
Template: index

Usually used to fill the content for SEO purpose. While the $post['content_short'] come from $post['content'] before {cut}

I will be your post description. // <= this
{cut}
Vitae, velit, temporibus sequi mollitia dolorem voluptatibus assumenda et cumque soluta laudantium commodi odit cupiditate eos nobis quisquam obcaecati vero rerum ut.

You can create a simple conditional function to make sure the post description become visible if available, if not, show the content short:

if(strlen($post['description']) > 0) {
    echo '
' . $post['description'] . '
'; } elseif (strlen($post['content_short']) > 0) { echo '
' . $post['content_short'] . '
'; } else { echo '
Description not available.
'; }
XSS Testing

tovic's Website

Re: Blog Pagination (Next/Previous) for Morfy CMS

ok thanks

I'm not like them but I can pretend.

Re: Blog Pagination (Next/Previous) for Morfy CMS

can be pagination for each template separately as exemplified below;

blog template



runAction('theme_content_before'); ?> getPages($url,$order_by,$order_type,$ignore,$limit); // $url is a folder of posts $url = CONTENT_PATH . '/blog/'; // $order_by is a order like date or title $order_by = 'date'; // $order_type is a order type like ASC or DESC $order_type = 'DESC'; // $ignore = array of files to ignore $ignore = array('404','index'); // $limit is a number of posts $limit = 2; $posts = Morfy::factory()->getPages($url,$order_by, $order_type,$ignore,$limit); foreach($posts as $post) { // use default image if not write Thumbnail $thumbnail = ($post['thumbnail']) ? $post['thumbnail'] : $config['Site_url'].'public/images/default.jpg'; echo '

'.$post['title'].'

Posted on '.$post['date'].'

'.$post['title'].'
'.$post['content_short'].'
'; } ?> runAction('index_nextprev'); ?> runAction('theme_content_after'); ?>

news template



runAction('theme_content_before'); ?> getPages($url,$order_by,$order_type,$ignore,$limit); // $url is a folder of posts $url = CONTENT_PATH . '/news/'; // $order_by is a order like date or title $order_by = 'date'; // $order_type is a order type like ASC or DESC $order_type = 'DESC'; // $ignore = array of files to ignore $ignore = array('404','index'); // $limit is a number of posts $limit = 2; $posts = Morfy::factory()->getPages($url,$order_by, $order_type,$ignore,$limit); foreach($posts as $post) { // use default image if not write Thumbnail $thumbnail = ($post['thumbnail']) ? $post['thumbnail'] : $config['Site_url'].'public/images/default.jpg'; echo '

'.$post['title'].'

Posted on '.$post['date'].'

'.$post['title'].'
'.$post['content_short'].'
'; } ?> runAction('index_nextprev'); ?> runAction('theme_content_after'); ?>

Re: Blog Pagination (Next/Previous) for Morfy CMS

Try jeje i think yes

..::: Moncho Varela ::::..   ..::: @Nakome ::::..   ..::: Github ::::..

nakome's Website

Re: Blog Pagination (Next/Previous) for Morfy CMS

nakome wrote:

Try jeje i think yes

?

Re: Blog Pagination (Next/Previous) for Morfy CMS

Yes, the plugin will automatically detect the current folder via URL path.

Example:

  • hxxp://latitudu.com/notes/morfy-cms (blog page)

  • hxxp://latitudu.com/notes/morfy-cms/plugins (plugins page)

  • hxxp://latitudu.com/notes/nursing (another blog page)

Note: Here I put the blog pagination in blog.html, so all of the page above only use blog.html template. But again, It works only by detecting folder names from URL, so it will work if you put them in news.html template for example as an alternative for blog.html or has the same behavior with the blog.html template.

XSS Testing

tovic's Website

13 (edited by tovic 2015-02-20 12:56:52)

Re: Blog Pagination (Next/Previous) for Morfy CMS

Update:

Oh, so you want to make the blog pagination separated from the posts list. Hm, you will need to modify the source code yourself.

Put the content of the plugin definition from here to here to replace the runAction('index_nextprev'); ?> line in your template.

XSS Testing

tovic's Website

Re: Blog Pagination (Next/Previous) for Morfy CMS

tovic wrote:

Update:

Oh, so you want to make the blog pagination separated from the posts list. Hm, you will need to modify the source code yourself.

Put the content of the plugin definition from here to here to replace the runAction('index_nextprev'); ?> line in your template.



 * @copyright 2014 Romanenko Sergey / Awilum
 * @version 1.0.4
 *
 */
// Include `shell.css` in header
// Uncomment the hook function below if you are not using Bootstrap.
// Morfy::factory()->addAction('theme_header', function() {
//     echo '' . "\n";
// });
// For posts listing page
// Usage => Morfy::factory()->runAction('index_nextprev');
Morfy::factory()->addAction('index_nextprev', function() {
    // Configuration data
    $config = Morfy::$config['nextprev_config'];
    // Get current URI segments
    $path = Morfy::factory()->getUriSegments();
    $path = implode('/', $path);
    // Number of posts to display per page request
    $per_page = isset($config['limit']) ? $config['limit'] : 5;
    // Get all posts
    $all_posts = Morfy::factory()->getPages(CONTENT_PATH . '/' . $path . '/', 'date', 'DESC', array('404', 'index'));
    // Calculate total pages
    $total_pages = ceil(count($all_posts) / $per_page);
    // Get current page offset
    $current_page = isset($_GET[$config['param']]) ? $_GET[$config['param']] : 1;
    // Split all posts into chunks
    $posts = is_array($all_posts) ? array_chunk($all_posts, $per_page) : array();
    // Build the pagination
    $html  = '
'; echo $html; }); // For single article // Usage => Morfy::factory()->runAction('item_nextprev'); Morfy::factory()->addAction('item_nextprev', function() { // Configuration data $config = Morfy::$config['nextprev_config']; // Get current URI segments $path = Morfy::factory()->getUriSegments(); array_pop($path); $path = implode('/', $path); // Get all posts $all_posts = Morfy::factory()->getPages(CONTENT_PATH . '/' . $path . '/', 'date', 'DESC', array('404', 'index')); // Count total posts $total_posts = count($all_posts); // Get current page URL $current_url = Morfy::factory()->getUrl(); // Get current page data $current_page = Morfy::factory()->getPage($current_url); // Testing... // echo $current_page['date']; // Find next and previous link from current page $prev_page = $next_page = null; for($i = 0; $i < $total_posts; $i++) { if($current_page['date'] == $all_posts[$i]['date']) { $prev_page = isset($all_posts[$i - 1]['url']) && ! empty($all_posts[$i - 1]['url']) ? $all_posts[$i - 1]['url'] : null; $next_page = isset($all_posts[$i + 1]['url']) && ! empty($all_posts[$i + 1]['url']) ? $all_posts[$i + 1]['url'] : null; } } // Build the pagination $html = ''; echo $html; });

this is right;

15 2015-02-21 06:03:42 (edited by tovic 2015-02-21 06:04:24)

Re: Blog Pagination (Next/Previous) for Morfy CMS

Something like this:



runAction('theme_content_before'); ?> getUriSegments(); $path = implode('/', $path); // Number of posts to display per page request $per_page = isset($config['limit']) ? $config['limit'] : 5; // Get all posts $all_posts = Morfy::factory()->getPages(CONTENT_PATH . '/' . $path . '/', 'date', 'DESC', array('404', 'index')); // Calculate total pages $total_pages = ceil(count($all_posts) / $per_page); // Get current page offset $current_page = isset($_GET[$config['param']]) ? $_GET[$config['param']] : 1; // Split all posts into chunks $posts = is_array($all_posts) ? array_chunk($all_posts, $per_page) : array(); // Posts loop if(isset($posts[$current_page - 1]) && ! empty($posts[$current_page - 1])) { foreach($posts[$current_page - 1] as $post) { echo '
'; echo $post['title'] ? '

' . $post['title'] . '

' : ""; echo $post['date'] ? '

Published on: ' . $post['date'] . '

' : ""; if(strlen($post['description']) > 0) { echo '

' . $post['description'] . '

'; } elseif(strlen($post['content_short']) > 0) { echo '

' . $post['content_short'] . '

'; } echo '
'; } } else { echo '
' . $config['labels']['not_found'] . '
'; } // Build the pagination $html = ''; echo $html; ?> runAction('theme_content_after'); ?>
XSS Testing

tovic's Website

16 2015-02-21 09:16:19

Re: Blog Pagination (Next/Previous) for Morfy CMS

Thank you!
there is an error runAction('item_nextprev'); ?> when we go to the last page after not going back sad

17 2015-02-21 15:56:11

Re: Blog Pagination (Next/Previous) for Morfy CMS

Really? It should be faded to a gray button on the last/first page.

XSS Testing

tovic's Website

Re: Blog Pagination (Next/Previous) for Morfy CMS

is ok! I just had to post all the same date so they do not go back!
I changed the dates and it works fine!

Re: Blog Pagination (Next/Previous) for Morfy CMS

Just advice: http://forum.monstra.org/topic/550/prop … t-for-post

XSS Testing

tovic's Website

Re: Blog Pagination (Next/Previous) for Morfy CMS

@tonic
how do I replace the parameters in config.php

'nextprev_config' => array( // <= Configuration
            'param' => 'page', // <= Page parameter name in URL
            'limit' => 5, // <= Number of posts to display per page
            'classes' => array( // <= List of item's HTML classes
                'page_item' => 'page',
                'nav' => 'pager',
                'nav_prev' => 'previous',
                'nav_next' => 'next',
                'nav_disabled' => 'disabled'
            ),
            'labels' => array( // <= List of item's readable text or labels
                'nav_prev' => '← Previous',
                'nav_next' => 'Next →',
                'not_found' => '

Not found.

' ) )

only exist in the file nextprev.php ?

21 Yesterday 14:39:51

Re: Blog Pagination (Next/Previous) for Morfy CMS

I don’t get it.

XSS Testing

tovic's Website

22 (edited by dextra Yesterday 16:02:31)

Re: Blog Pagination (Next/Previous) for Morfy CMS

@tovic

I mean something like this

    // Build the pagination
    $html  = '
';
    // Build the pagination
    $html  = '
    '; $html .= $current_page > 1 ? '' : ''; $html .= $current_page < $total_pages ? ' ' : ' '; $html .= '
';

I mean to have no parameters config.php