We are transitioning over to a new forum platform. Please post new issues there. Existing threads will be dealt with here unless you choose to move them over. Visit the new forum

Forum

Thread tagged as: Question, Problem, Addons

Help With Blog Archives

I have two issues relating to displaying links and resulting articles from post archives.

  1. This may be another bug in the Blog app or incorrect code. I referred to the docs on advice, to create a link to show posts by month and noted the count was using qty in example. However I read elsewhere that qty was now count.blog.post.

However this does not seem to work either the link displays as November, 2014 ()

Here is the code for the archive link:

<a href="/news/archive/<perch:blog id="postDateTime" format="m" />-<perch:blog id="postDateTime" format="Y" />" class="w-links-category-anchor"><perch:blog id="postDateTime" format="%B" />, <perch:blog id="postDateTime" format="%Y" /> (<perch:blog id="count.blog.post" />)</a>
  1. I have set up .htaccess rules and all relevant code to display the archived articles filtered by the month/year, it appears to function, however all articles are displaying.

Here is code for archive page:

<?php perch_blog_custom(array(
'template' => 'post_in_list.html',
'paginate'=> true,
'count' => 8,
'sort' => $sort_by,
'sort-order' => $sort_order,
));

?>

These articles have both been created in November, but I went back in and changed the creation date of one to October. Should this in theory stop it displaying if November is chosen as the archive to view?

Nigel Coath

Nigel Coath 1 points

  • 5 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

  1. What's the context of this? What are you trying to do?

  2. You're not filtering the results at all. You're setting a template, pagination, count, sort and sort-order, but not filtering on which month you want.

Sorry thought I had made that clear!

I am trying to filter posts on a listing page by month/year. I have created the link but have not filtered as not sure what to use. This is based on the months_year_link.html

Also the first point needs answering at the top of this post (sorry realised I numbered both 1…)

Drew McLellan

Drew McLellan 2638 points
Perch Support

I responded to both your points.

Oh okay I see that now, so:

  1. I have a series of links to display as e.g. October, 2014 (2) however the figure inside the bracket (which is the post count) is not generating. I have used "count.blog.post" and also tried the one in the Blog docs "qty".

  2. I am trying to filter posts on a listing page by month+year. I have created the link but have not filtered as not sure what to use. So say the link generates a month+year as per point 1 then the filter needs to display articles in that year+month.

Drew McLellan

Drew McLellan 2638 points
Perch Support

  1. Is it a post count you want?

  2. You need to add a filter. There's no magic. If you only want posts from a given month, use a filter to get them, e.g

'filter' => 'postDateTime',
'match' => 'eqbetween',
'value' => '2011-01-01 00:00:00, 2011-01-31 23:59:59',
  1. Yes its a post count, I used the same code I used in a category link that works fine in that "count.blog.post" but its not working.

  2. How do I filter it if the value is generated by the link? The link generates a month+year e.g. 10-2014

I need to crack point 1 as I am having the same problem with a page used to display articles filtered by tags only the code used in the docs "tagSlug" does not even seem to output to a link (maybe the docs are out of date?).

Drew McLellan

Drew McLellan 2638 points
Perch Support

  1. Which page function are you using?

  2. What does your URL look like?

  1. perch_blog_date_archive_months
  2. /news/archive.php?month=10&year=2014 (for example)
Drew McLellan

Drew McLellan 2638 points
Perch Support

  1. In the year template it's year_qty and in the month template it's month_qty.

  2. 'value' => perch_get('year').'-'.perch_get('month').'-01 00:00:00, '.perch_get('year').'-'.perch_get('month').'-31 23:59:59',

  1. Thats does not seem to work still its still showing (), this is what I now have:
<a href="/news/archive/<perch:blog id="postDateTime" format="m" />-<perch:blog id="postDateTime" format="Y" />" class="w-links-category-anchor"><perch:blog id="postDateTime" format="%B" />, <perch:blog id="postDateTime" format="%Y" /> (<perch:blog id="month_qty" />)</a>

I do not have a month and year link, this is called inside a template called archive_link.html, does this matter?

2.Thanks for this seems to work, I am trying to tidy it up using .htaccess however my stab must be incorrect:

RewriteRule ^news/archive/([0-9]{1,2})?/([0-9]{4})/?$ /news/archive.php?monthnum=$1&year=$2 [QSA]
Drew McLellan

Drew McLellan 2638 points
Perch Support

  1. Can you show me your function call?

  2. How is it failing? You've changed the month parameter to monthnum - is that significant?

  1. Sorry if I am being thick but do you mean this (this is the call to the archive links template):
<?php perch_blog_custom(array('count' => 8,'template' => 'archive_link.html','sort' => 'postDateTime','sort-order' => 'DESC','include-empty' => true, )); ?>
  1. Well I did some googling and someone trying to do similar with a WP blog had this, I guessed it must be monthnum as the link generated is in number form, is this incorrect? I tried as month and this did not work.

Whats happening currently is it goes to an empty set of results (I know because I placed a <noresults> block in the template.

Drew McLellan

Drew McLellan 2638 points
Perch Support

  1. You said you were using perch_blog_date_archive_months(). Is that not the case?

  2. It's not 'incorrect', you just need to be consistent.

  1. Well I based it on that but am actually using perch_blog_custom (see top of post).
  2. Consistent where? Even if I use month in rewrite it does not work.

I am close, as I know without rewrite it works.

Just need to crack why

(a) qty is not working (b) clean url is not working

Rachel Andrew

Rachel Andrew 394 points
Perch Support

You can't base one function on another, making an assumption that they will be the same.

The documentation describes the parameters for each function. Googling WordPress information is likely to confuse as you are using Perch and not WordPress. Debugging your rewrite rules is outside of what we can offer in support unless you can give us a very clear explanation, including your code and existing rewrite rules of what is going wrong.

We're very happy to help but you need to help yourself by reading the documentation and demonstrating with a simple example where, when using the documented functions as they are documented, your solution is not working. You need to explain:

  • I followed these steps
  • I expected this result
  • I got this alternate result

Then we can reproduce exactly what you have done and get the same incorrect result, at which point it is easy for us to explain what you should have done to get the correct result. At the moment there are two of us who really don't understand how you have got to where you are which makes it pretty much impossible for us to help.

Okay understood.

So I had a play and somehow cracked the mod_rewrite!

RewriteRule ^news/archive/([a-zA-Z0-9-/]+)-([a-zA-Z0-9-/]+)$ /news/archive.php?month=$1&year=$2 [L]

generates news/archive/11-2014 (or similar) and this works.

Now the second issue is the display of the post count link. I am using one template to control the link.

So far I have tried:

<perch:blog id="qty" />
<perch:blog id="month_qty" />
<perch:blog id="blog.post.count" />

none of these work all I get is Month, Year ()

So do I have to have two templates one for month and one for year? The link works so surely my approach is right?

It just seems the code above for quantity is not right.

Drew McLellan

Drew McLellan 2638 points
Perch Support

If you're using perch_blog_custom() there's no count available to you.

Okay thanks that explains it.

Just to understand to use the month_qty do I have to have two templates driving perch_blog_date_archive_months()

Ideally I just want a link for each month e.g.

November, 2014.

But by having to use months_month_link and months_year_link it displays as:

2014 November

Is there a way to combine this into one template and still display quantity?

Drew McLellan

Drew McLellan 2638 points
Perch Support

In your year template, remove everything but for

<perch:blog id="months" encode="false" />

Great thanks will try that, I wish I had known qty was not an available function in perch_blog_custom I wasted so much time thinking it was something else I had done wrong!