Permalink for blog list & category

4 posts by 3 authors in: Forums > CMS Builder
Last Post: January 14, 2016   (RSS)

By hiroko - January 4, 2016

Hi,

I am looking for a solution for permalink.

I want the viewer to show the list of the blogs when the category is selected. Each category has a permalink. 

This is easily done when I use the link like: <a href="/blogCategory.php?category=<?php echo $record['category'] ?>

which the url becomes /blogCategory.php?category=1

but I would like to use the permalink and <a href="<?php echo $record['_link'] ?> for this so the url will become /permalink/ or /permalink/&page=2

I have tried this but only one record will show up and the categorizing is not working.

This is what I have on the page.

 // load records from 'blog_category'
  list($blog_categoryRecords, $selectedBlog_category) = getCategories(array(
    'tableName'            => 'blog_category', //
    'categoryFormat'       => 'showall',  // showall, onelevel, twolevel, breadcrumb
    'defaultCategory'      => '',    // Enter 'first', a category number, or leave blank '' for none
  ));

  
  // load records from 'blog'
  list($blogRecords, $blogMetaData) = getRecords(array(
    'tableName'   => 'blog',
    'perPage'     => '6',
    'loadUploads' => true,
    'allowSearch' => true,
'where' => 'category',
  ));

and this is the html

  <div id="mainContent_blogList">
  <?php if ($selectedBlog_category): ?>
  <h1><?php echo htmlencode($selectedBlog_category['name']) ?></h1>
  <?php endif ?>
  <?php foreach ($blogRecords as $record): ?>
  
    <section class="blogList">
      <h1><a href="<?php echo $record['_link'] ?>"><?php echo $record['title'] ?></a></h1>
      <p><?php echo mb_substr(strip_tags($record['content']), 0, 60);?> ...</p>
      <p>category:<a href="<?php echo PREFIX_URL ?>/blogCategory.php?category=<?php echo $record['category'] ?>"><?php echo $record['category:label'] ?></a></p>
      <div class="blogList_read"><a href="<?php echo $selectedBlog_category['_link'] ?>">read more</a></div>
    </section>

    <?php endforeach ?>
    <section class="mainContent" id="pageNav">
    <!-- Page Nav -->
    <?php if ($blogMetaData['prevPage']): ?>
      <a href="<?php echo $blogMetaData['prevPageLink'] ?>">&laquo; prev</a>
    <?php else: ?>
    <?php endif ?>
    <?php
     if (@!$_GET['page']): $current_page = "1";
     else: $current_page = $_GET['page'];
     endif; ?>
     <?php
 $onePage = ($blogMetaData['totalPages'] < 2);
 ?>
        <?php foreach (range(1,$blogMetaData['totalPages']) as $page): ?>
        <?php if ($onePage): ?>
        <?php elseif ($page == $current_page): ?>
        <span class="pageNo"><?php echo $page; ?></span>
        <?php else: ?>
        <span class="pageNo"><a href="<?php echo $blogMetaData['nextPageLink'] ?>"><?php echo $page; ?></a></span>
        <?php endif ?>
        <?php endforeach; ?>

     <?php if ($blogMetaData['nextPage']): ?>
      <a href="<?php echo $blogMetaData['nextPageLink'] ?>">next &raquo;</a>
    <?php else: ?>
    <?php endif ?>
  <!-- /Page Nav -->
    </section>
  </div>

I have also tried limiting the records such as 

<?php if ($record['category'] == $selectedBlog_category['num']): ?>
blog list code

and changed at top as this

// load records from 'blog'
  list($blogRecords, $blogMetaData) = getRecords(array(
    'tableName'   => 'blog',
    'perPage'     => '6',
    'loadUploads' => true,
    'allowSearch' => false,
  ));

This sort of works, but on the first page, only two records are shown and 4 on the next page.

The url becomes like this:

http://www.xxx.com/permalink/?num=1&page=2

I think it is counting all the records.

I thought there was a post like this, but couldn't find it.

If there is one in the past, please kindly let me know or please give me some suggestions.

Thank you!

Hiroko

By ross - January 6, 2016

Hi Hiroko

Thanks for posting.

Does your code work when Permalinks is disabled? 

I think the issue here is going to be in the code and not specifically Permalinks so disabling the plugin will help us narrow down what's happening.

Let me know.

Thanks!

-----------------------------------------------------------
Cheers,
Ross Fairbairn - Consulting
consulting@interactivetools.com

Hire me! Save time by getting our experts to help with your project.
Template changes, advanced features, full integration, whatever you
need. Whether you need one hour or fifty, get it done fast with
Priority Consulting: http://www.interactivetools.com/consulting/

By hiroko - January 8, 2016

Thanks Ross,

I'm not sure what you mean by disabling Permalink ...

If I deactivate the permalink plugin, I cannot check the url and there will be a php error.

The url

http://www.kunsyodo.com/kaitori-history/?category=1

works fine whether the plugin is activated or deactivated.

This is the url I would like to use to show the exact same thing as the url above.

http://www.kunsyodo.com/kaitori-history/

I will attach the file.

Thank you for your support,

Hiroko

Attachments:

blogCategory.php 11K