Strict Standards: Redefining already defined constructor for class Object in /home/dizz/cake_1.2.5/cake/libs/object.php on line 63

Strict Standards: Non-static method Configure::getInstance() should not be called statically in /home/dizz/cake_1.2.5/cake/bootstrap.php on line 47
Creating Featured Posts for Croogo CMS |

Creating Featured Posts for Croogo CMS

Posted by Andrew on November 15th 2009, 7:02am

In this post I will describe how I created the featured post on the home page of my blog with Croogo. Looking at the database schema I noticed that there was a column named "sticky" that was not being utilized anywhere in the code so I thought that it would be a good place to store whether a post was featured or not. The first thing I did was edit the admin add and edit views to allow me to mark posts as featured under the publishing tab.

<div id="node-publishing">
    echo $form->input('sticky', array('label' => __('Featured', true)));
    echo $form->input('status', array('label' => __('Published', true)));
    echo $form->input('promote', array('label' => __('Promoted to front page', true)));
    echo $form->input('created');

All I did here was add one line that will display a checkbox similar to the published and promoted checkboxes. The next thing I had to do was retrieve the latest featured post from the database. I did this in the nodes controller under the promoted action since this is the default home page for Croogo.

$featured = $this->Node->find('first', array(
    'order' => 'Node.created DESC',
    'conditions' => array('Node.sticky' => true)
$this->set('featured', $featured);

This just finds the first post marked as featured, ordered by the created date. I then set a variable for the view so that I can access this featured post in my view. The next step was displaying the featured post. For this I created a "featured" element and rendered it in the layout template if the current action was "promoted".

<? if ($this->action == 'promoted') : ?>
<? endif ?>

Inside of featured.ctp in the elements directory.

<p><?=$html->link($featured['Node']['title'], $featured['Node']['url'], array('class' => 'link'))?><p>
<p><?=$text->trim(strip_tags($featured['Node']['body']), 200, '...', false, true)?></p>
<p><?=$html->link('Read More...', $featured['Node']['url'])?></p>

This is a dumbed down version of what I am using but should still get you started. If you know your way around CakePHP you should be able to understand what is happening. I am using the text helper to show an excerpt from the post body then display a read more link below that will direct the user to the post.

This should be enough to get you started. In my next post I will explain how to use custom fields in your posts. I am using them to display the image beside my featured posts on the home page. If you have any questions leave a comment and I should get back to you shortly.

Bookmark and Share
Posted in Croogo

1 Comment

Angelnotdie said on October 1st 2010, 9:54pm
Could you show me how can i create a new menu in menu manger and link to blog, node, or page. Just one in them...
I try create a news.php in model, news_controller in controller and folders news in view.
But when i submit a new post in News... croogo not for me post with a line
" Security Error

The requested address was not found on this server."

Because i just learn Cakephp. Could you demo a tutorial???
Thanks a lot !!!
Add New Comment