Chris J. Davis escribió:
> I am not sure if anyone has gotten back to you yet, but this is the  
> process for creating post types and then displaying them, as far as I  
> remember:
>
> In your plugin you should have two methods, one that creates the post  
> type upon activation, and then on that removes it when deactivating:
>
>       function action_plugin_activation( $plugin_file ) {
>               if( Plugins::id_from_file(__FILE__) ==  
> Plugins::id_from_file($plugin_file) ) {
>                       Post::add_new_type( 'my_post_type' );
>               }
>       }
>       
>       public function action_plugin_deactivation ( $file='' ) {
>               
>               if ( Plugins::id_from_file( $file ) ==  
> Plugins::id_from_file( __FILE__ ) ) {                 
>                       // deactivate our custom post type
>                       Post::deactivate_post_type( 'my_post_type' );
>               }
>       }
>
> Then you need to have a custom set of rewrite rules that tell habari  
> when to show the new post type:
>
>       public function filter_default_rewrite_rules( $rules ) {        
>               $rules[] = array(
>                       'name' => 'display_ my_post_type',
>                       'parse_regex' => '%^ 
> my_post_type(?:/page/(?P<page>[2-9]|[1-9] 
> [0-9]+))?/?$%',
>                       'build_str' => 'my_post_type/(page/{$page})',
>                       'handler' => 'PluginHandler',
>                       'action' => 'display_ my_post_type',
>                       'priority' => 90,
>                       'description' => 'Display my_post_type',
>               );
>                return $rules;
>       }
>       
> And finally you need to have a method to actually handle the display.  
> Notice that the naming of this method matches the action in the rules  
> array.
>
>       public function action_plugin_act_display_ my_post_type($handler) {
>               $paramarray = array();
>               $paramarray['fallback'] = array(
>                       'my_post_type.multiple',
>                       'my_post_type.single',
>                       'home',
>               );
>               
>               // Makes sure home displays only entries
>               $default_filters = array(
>                       'content_type' => Post::type( 'my_post_type' ),
>               );
>
>               $paramarray['user_filters']= $default_filters;
>               return $handler->theme->act_display( $paramarray );
>       }
>
> Finally in your my_post_type.multiple you would call the post loop  
> like so:
>
>       <?php foreach ( $posts as $post ) : ?>
>               <?php $theme->content($post, 'home_posts'); ?>
>       <?php endforeach; ?>
>
> This is mostly from memory, so the syntax might not be exactly write,  
> but I think it will give you a clear starting point.
>
> On May 23, 2009, at 11:46 AM, Tomas Gonzalez Dowling wrote:
>
>   
>> Hi all,
>>    I want to create a new post type, i inserted a new row in posttype
>> table and after that i see at the admin that i can create that type of
>> posts. But how I show that stuff from my theme?
>>
>> I'm using Habari 0.6.2.
>> The main reason for doing this is to mantain a portfolio and manage  
>> it easy.
>>
>> You can see my page at http://macshack.com.ar/habari-0.6.2
>>
>>
>> Thanks in advance,
>>
>> -- 
>>   (                  )
>>   )\         )    ( /(       )
>> (((_)  (    (     )\())(    (
>> )\___  )\   )\  '(_))/ )\   )\  '
>> ((/ __|((_)_((_)) | |_ ((_)_((_))
>> | (__/ _ \ '  \()|  _/ _ \ '  \()
>>  \___\___/_|_|_|  \__\___/_|_|_|
>>    43  6F   6D     74  6F  6D
>>
>>
>>     
Hi again,
    I'm still in trouble. My plugin seems to work perfectly when i enter
the admin area. If i logout the posts doesn't show up.

I'm using these lines to show the posts (they are images as you can
see). I did try with the first commented line with the same results. All
the following code is on theme.php on my theme. I call this function
from header.php on my theme.


    public function galeria()
    {
        //$posteos=Posts::get(array ( 'status' => 'published',
'content_type' => 'portfolio', 'offset' => ($pagination)*($page),
'limit' => 5, ) );
       
        $posteos = Posts::get('content_type=portfolio');

        $i=0;
        //if  ($i <= 5 ) {
            foreach ( $posteos as $post ) {
                $i=$i+1;
                $url=$post->info->version;
                echo "<a title=\"$post->title\" href=\"$url\"
class=\"imagen\"><img id=\"thumb$i\" src=\"$post->content\" alt=\"\"
style='opacity: 0.5;' /></a>";
            }
        //}
    }


Also, i show to you my plugin:


<?php
 
class Portfolio extends Plugin
{
 
    /**
    * Return plugin metadata for this plugin
    */
    public function info()
    {
        return array(
            'name' => 'portfolio',
            'version' => '1.0',
            'url' => 'http://macshack.com.ar',
            'author' => 'Tomás González Dowling',
            'authorurl' => 'http://macshack.com.ar',
            'license' => 'GPL v3',
            'description' => 'Una galeria simple'
         );
    }
 
    /**
     * On plugin activation
     */
    public function action_plugin_activation( $file )
    {
        // Don't process other plugins
        if(Plugins::id_from_file($file) ==
Plugins::id_from_file(__FILE__)) {
 
            // Insert new post content types
            Post::add_new_type( 'portfolio', true );
       
        }
    }
 
 
    /**
     * Manage portfolio
     */
    public function action_form_publish( &$form, &$post )
    {
         if( $form->content_type->value == Post::type('portfolio') ) {
            
            // Add portfolio settings fields
            $settings = $form->publish_controls->append('fieldset',
'portfolioSettings', _t('Portfolio Settings'));
 
            // Add version entry
            $settings->append('text', 'version', 'null:null', _t('Full
image URL'), 'tabcontrol_text');
            $settings->version->value = $post->info->version;
 
            // Add license entry
            $settings->append('text', 'license', 'null:null',
_t('License'), 'tabcontrol_text');
            $settings->license->value = $post->info->license;
        }
    }
 
 
    /**
     * Now we need to save our custom entries
     */
    public function action_publish_post( &$post, &$form )
    {
        // Run this action, Habari doesn't and we need our form inputs
        //$this->action_form_publish( $form, $post );
 
        if( $form->content_type->value == Post::type('portfolio') ) {
           
            // Save settings
            $post->info->version = $form->version->value;
            $post->info->license = $form->license->value;
            // No, it really is that easy to save data
        }
    }
 
 
    /**
     * Handle displays
     */
    public function filter_theme_act_display_portfolio($handled, &$theme)
    {
        /**
         * Tell Habari which files are to be used,
         * we attempt to get any portfolio theme file first.
         * if that fails we goto single and then multiple
         */
        $paramarray['fallback']= array(
         'portfolio.{$id}',
         'portfolio.{$slug}',
         'portfolio.tag.{$posttag}',
         'portfolio.single',
         'portfolio.multiple',
         'single',
         'multiple',
 
        );
 
        // This is like Post::get().. Get one row, one item
        $paramarray['user_filters']= array(
         'fetch_fn' => 'get_row',
         'limit' => 1,
        );
 
        return $theme->act_display( $paramarray );
    }

}

?>



What i'm doing wrong?

Thanks again,

-- 
   (                  )            
   )\         )    ( /(       )    
 (((_)  (    (     )\())(    (     
 )\___  )\   )\  '(_))/ )\   )\  ' 
((/ __|((_)_((_)) | |_ ((_)_((_))  
 | (__/ _ \ '  \()|  _/ _ \ '  \() 
  \___\___/_|_|_|  \__\___/_|_|_|  
    43  6F   6D     74  6F  6D


--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at http://groups.google.com/group/habari-dev
-~----------~----~----~----~------~----~------~--~---

Reply via email to