Display the latest posts from two sections on a page
I've added this to the html to show the latest posts from the news section in this case and to use a custom template.
<?php perch_blog_section(perch_get('news')); ?>
<?php
perch_blog_custom(array(
'section' => array('news'),
'template' => 'custom-template.html',
));
?>
But it returns this error on the page:
Warning: PDO::quote() expects parameter 1 to be string, array given in /home/jpespartners/public_html/perch/core/lib/PerchDB_MySQL.class.php on line 378
What am I doing wrong?
Try this :)
perch_blog_custom(array( 'section' => perch_get('news'), 'template' => 'custom-template.html', ));
Thanks but this doesn't output anything on the page.
Are you using a query string? Is there a link you could share?
Developing on my computer.
Not even getting the code straight out of the example 'section.php' to work:
OK, from what I can tell, the problem is that the section option is being passed an array, and it only accepts a string. Hope that helps!
Not a programmer, so struggling!
It helps to reduce problems to a simpler form. Firstly, you need to fix the PHP error. I'd try just passing in a string for the section slug you want. Once that's showing content, look at grabbing that value from the query string.
True!
I've done this:
<?php perch_blog_section(perch_get('news')); ?>
'news' does exist as the slug in the CMS and has a post.
But the web page outputs nothing there.
perch_blog_section doesn't output posts, only information about a section. Do you see the section title?
It's not outputting anything. Checked the HTML and there's no information there.
Adding: <?php perch_blog_sections(); ?>
lists the section titles for me.
Yeah, that comes from another template. What's the code in your section.html template?
As default:
<h1><perch:blog id="sectionTitle" type="text" /></h1>
<perch:blog label="Image" id="image" type="image" width="800" height="200" crop="true" density="2" output="tag" />
I just want to be able to output a list of the posts in the section so I was trying to use post_in_list.html
What HTML does perch_blog_sections output for you?
<ul>
</ul>
I take it I'm using sections as the most appropriate way of having a blog and a news section which operation within the blog app.
Ah. You need it to be:
<?php perch_blog_section(perch_get('s')); ?>
<?php perch_blog_custom(array( 'section' => perch_get('s'), 'template' => 'custom-template.html', )); ?>
I've changed 'section' to 'news' to pull in the news section posts only. And the template name to 'post_in_list.html' and it does output a list of posts (not getting the clean URLs working yet but that's a separate problem) but this code seems to be displaying all the blog posts including those in the default 'posts' section and not just the 'news' section posts.
Exact code I have is:
<?php perch_blog_section(perch_get('s')); ?> <?php perch_blog_custom(array( 'news' => perch_get('s'), 'template' => 'post_in_list.html', )); ?>
You changed the option, not the value. It should be this:
<?php perch_blog_section(perch_get('s')); ?> <?php perch_blog_custom(array( 'section' => perch_get('s'), 'template' => 'post_in_list.html', )); ?>
Try:
That works great thanks.
I can't link to the posts. Shall I post this as a new thread?