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

Hi Hiroko,

I think I understand the problem, you'd like the category URL variable to appear in the permalink so that the site users don't have to see it, and you can have custom permalinks for each category? You can do this by manually setting up the permalinks in the Permalinks DB. 

To manually set up a permalink, log into your CMS, then navigate to Admin -> Plugins -> Permalinks DB (In the right hand column of the entry for permalinks in the list). Here you'll see a list of all the permalinks in the database. Next you need to manually create a permalink by click the create button. Now you need to set up your permalink, I think it needs to look roughly like what I have added in the image attached to this post. 

This works because when the system detects the permalink in the URL, it not only redirects the user to the correct file, but adds the category to the URL as well.

Let me know if you have any questions. 

Cheers!

Greg

Greg Thomas







PHP Programmer - interactivetools.com
Attachments:

CMS Builder.png 38K