Forum

Thread tagged as: Problem, Runway, Blog

Blog slug and URL shenanigans

I'm working with the blog in Perch Runway. I've set up all the templates for the listing page and detail pages and they are working great.

I have an issue getting the post URLs to play ball.

Current set up

Blog post page URL pattern

blog/[year:year]/[i:month]/[slug:s]

Blog settings Blog post page path

/blog/{postSlug}

Blog settings Slug format

%Y/%m/{postTitle}

With this set up, the URL is correct but when I visit the detail page, the post does not show up.

Alternative set up

Blog post page URL pattern

blog/[slug:s]

Blog settings Blog post page path

/blog/{postSlug}

Blog settings Slug format

{postTitle}

With this set up, I can view the blog post but the URL is not how I want it.

I'd like blog URLs to be in the format /blog/{year}/{month}/{postTitle}

In post.php I simply have

<?php perch_blog_post(perch_get('s')); ?>

Any idea what I am doing wrong?

Thanks

Caleb Evans

Caleb Evans 1 points

  • 6 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

Can you show me the debug from the post page when it's not working?

Here you go...


Debug Message SELECT p.pagePath, pr.routePattern, pr.routeRegExp, p.pageTemplate FROM perch2_pages p LEFT JOIN perch2_page_routes pr ON p.pageID=pr.pageID ORDER BY pr.routeOrder ASC Matched route: blog/[year:year]/[i:month]/[slug:s] Using master page: \templates\pages\blog\post.php Page arguments: Array ( [0] => /blog/2015/06/hostpipe-are-rebranding-as-coconut [year] => 2015 [1] => 2015 [month] => 06 [2] => 06 [s] => hostpipe-are-rebranding-as-coconut [3] => hostpipe-are-rebranding-as-coconut ) SELECT * FROM perch2_pages WHERE pagePath='/blog-post' LIMIT 1 SELECT * FROM perch2_pages WHERE pageNew=0 AND pageHidden=0 ORDER BY pageTreePosition ASC SELECT pageTreePosition FROM perch2_pages WHERE pagePath='/blog-post' LIMIT 1 SELECT pageID FROM perch2_pages WHERE pageTreePosition IN ('000-007-001', '000-007', '000') Using template: \templates\navigation\item.html SELECT SQL_CALC_FOUND_ROWS DISTINCT tbl.* FROM ( SELECT idx.itemID, main.*, idx2.indexValue as sortval FROM perch2_blog_index idx JOIN perch2_blog_posts main ON idx.itemID=main.postID AND idx.itemKey='postID' JOIN perch2_blog_index idx2 ON idx.itemID=idx2.itemID AND idx.itemKey='postID' AND idx2.indexKey='_id' WHERE 1=1 AND ((idx.indexKey='postSlug' AND idx.indexValue='hostpipe-are-rebranding-as-coconut')) AND idx.itemID=idx2.itemID AND idx.itemKey=idx2.itemKey GROUP BY idx.itemID ) as tbl WHERE (postStatus='Published' AND postDateTime<='2015-06-18 17:09:00' ) GROUP BY itemID ORDER BY sortval ASC LIMIT 0, 10 SELECT FOUND_ROWS() AS `count` SELECT DISTINCT settingID, settingValue FROM perch2_settings WHERE userID=0 Using template: \templates\blog\post.html Rescoping to perch:blog Using sub-template: \templates\content/blocks/blocks.html SELECT * FROM perch2_blog_posts WHERE postStatus='Published' AND postDateTime<='2015-06-18 17:09:00' AND postSlug='hostpipe-are-rebranding-as-coconut' SELECT * FROM perch2_blog_posts WHERE postID=0 AND postStatus='Published' AND postDateTime<='2015-06-18 17:09:00' Using template: \templates\blog\comment_form.html SELECT * FROM perch2_blog_comments WHERE 1=1 AND postID=0 AND commentStatus='LIVE' ORDER BY commentDateTime ASC Using template: \templates\blog\comment.html Fetching from cache: perch_blog_categories589c7a634eb12f2ec225cfedc7dc78ae Cache file not found: perch_blog_categories589c7a634eb12f2ec225cfedc7dc78ae SELECT setID FROM perch2_category_sets WHERE setSlug='blog' LIMIT 1 SELECT main.* , COALESCE(cc.countValue,0) AS `count.blog.post` FROM perch2_categories main LEFT OUTER JOIN perch2_category_counts cc ON cc.catID=main.catID WHERE 1=1 AND setID='1' AND (cc.countType='blog.post' OR cc.countType IS NULL) AND cc.countValue > 0 ORDER BY catTreePosition ASC Using template: \templates\blog\category_link.html Fetching from cache: perch_blog_tags6ea7442106790571c75e0342c3a255ef Cache file not found: perch_blog_tags6ea7442106790571c75e0342c3a255ef SELECT t.tagTitle, t.tagSlug, COUNT(p2t.postID) AS qty FROM perch2_blog_tags t, perch2_blog_posts_to_tags p2t, perch2_blog_posts p WHERE p2t.tagID=t.tagID AND p2t.postID=p.postID AND p.postStatus='Published' AND p.postDateTime<='2015-06-18 17:09:00' GROUP BY t.tagID ORDER BY t.tagTitle ASC Using template: \templates\blog\tag_link.html Fetching from cache: perch_blog_date_archive_monthsf2e7d49784704a5b24102a78c349d57c Cache file not found: perch_blog_date_archive_monthsf2e7d49784704a5b24102a78c349d57c SELECT year(postDateTime) as year, COUNT(*) AS year_qty FROM perch2_blog_posts WHERE postStatus='Published' AND postDateTime<='2015-06-18 17:09:00' GROUP BY year ORDER BY year DESC Using template: \templates\blog\months_month_link.html SELECT DISTINCT year(postDateTime) AS year, month(postDateTime) AS month, CONCAT(year(postDateTime),"-",month(postDateTime),"-01") AS postDateTime, COUNT(*) AS month_qty FROM perch2_blog_posts p WHERE year(postDateTime) = '2015' AND p.postStatus='Published' AND p.postDateTime<='2015-06-18 17:09:00' GROUP BY year, month ORDER BY month DESC Using template: \templates\blog\months_year_link.html Caching: perch_blog_date_archive_monthsf2e7d49784704a5b24102a78c349d57c SELECT * FROM perch2_twitter_tweets WHERE tweetType='mine' AND tweetIsReply=0 ORDER BY tweetDate DESC LIMIT 2 Using template: \templates\twitter\tweet.html SELECT groupID FROM perch2_navigation WHERE groupSlug='footer-nav' LIMIT 1 SELECT np.pageID, np.pageParentID, p.pagePath, p.pageTitle, p.pageNavText, p.pageNew, p.pageOrder, np.pageDepth, p.pageSortPath, np.pageTreePosition, p.pageAccessTags, p.pageAttributes FROM perch2_navigation_pages np, perch2_pages p WHERE p.pageID=np.pageID AND np.groupID=1 AND p.pageNew=0 AND np.pageDepth >=0 AND np.pageDepth<=1 ORDER BY np.pageTreePosition ASC SELECT np.pageTreePosition FROM perch2_pages p, perch2_navigation_pages np WHERE np.pageID=p.pageID AND np.groupID=1 AND p.pagePath='/blog-post' LIMIT 1 Using template: \templates\navigation\navlist.html SELECT regionKey, regionHTML FROM perch2_content_regions WHERE regionPage='/blog-post' OR regionPage='*' ORDER BY regionPage DESC Time: 0.8009 Memory: 3.6032
Drew McLellan

Drew McLellan 2638 points
Perch Support

That all looks like it's doing the right stuff. You say it just doesn't output the post?

That's right. This line outputs nothing..

<?php perch_blog_post(perch_get('s')); ?>

From looking at the debug info. It seems that the 's' is equal to "hostpipe-are-rebranding-as-coconut" but the slug attached to the post (from the database as far as I can tell) is "2015/06/hostpipe-are-rebranding-as-coconut" which I assume is why it cannot find the post.

Any ideas?

Drew McLellan

Drew McLellan 2638 points
Perch Support

Right, so you need to either add a token to match your entire slug in one go (see the "Post page routes" section on https://docs.grabaperch.com/addons/blog/runway-config/) or you need to pull the parts back together.

$post_slug = perch_get('year').'/'.perch_get('month').'/'.perch_get('s');
perch_blog_post($post_slug);

That did the trick. Thank you.