> Portico wordpress plugin resources analysis

Portico wordpress plugin resources analysis

Download This Plugin
Download Elegant Themes
Name Portico
Version 1.0.2
Author Dan Bettles
Rating 0
Last updated 2013-02-18 09:08:00
Downloads
566
Download Plugins Speed Test plugin for Wordpress

Home page

Delta: 0%

Post page

Delta: 0%
Portico plugin has no negative impact on PageSpeed score.

Home page PageSpeed score has been degraded by 0%, while Post page PageSpeed score has been degraded by 0%

Portico plugin added 16 bytes of resources to the Home page and 30 bytes of resources to the sample Post page.

Portico plugin added 0 new host(s) to the Home page and 0 new host(s) to the sample Post page.

Great! Portico plugin ads no tables to your Wordpress blog database.

Overview

There are just two steps to implementing a custom post-type with Portico. Here's a quick overview before we get down to the coding required.

  • Declare a class that defines your custom post type.
  • Create a display template for the new post type.

That's it! Portico handles the rest for you, and that includes building an admin interface for working with posts of the new type.

Coding

Let's take a look at a simple example, the implementation of a Podcast post-type.

Here's what the custom post-type's definition looks like:

<?php

/**
 * Podcast custom post-type implemented using the Portico plugin
 */
class Podcast extends \portico\CustomPostType
{
    protected function setUp()
    {
        //At present, "mandatory" simply marks the field as mandatory in the admin interface
        $this->addCustomField('artist', 'Artist', array(
            'mandatory' => true,
        ));

        //Default values can also be applied to text fields
        $this->addCustomField('genre', 'Genre', array(
            'values' => array(
                'Ambient' => 'Ambient',
                "Drum 'n' Bass" => "Drum 'n' Bass",
                'Dubstep' => 'Dubstep',
            ),
            'default' => "Drum 'n' Bass",
        ));

        //Set "length" to NULL to get a textarea
        $this->addCustomField('trackList', 'Track List', array(
            'length' => null,
        ));
    }
}
?>

Put the code in functions.php - or in a separate file included by functions.php - in your theme.

The next time you visit the WordPress admin area you should see a "Podcasts" section in the left-hand menu, beneath the usual "Posts" and "Pages" links. Take a look at the first screenshot to see exactly what you can expect.

All that remains is to create a custom display-template so we can view the values of a podcast's custom fields.

You can start by making a copy of single.php and renaming it after your custom post-type. Here's the template for the Podcast type, based on single.php shipped with the Modern Clix 1 theme:

<?php get_header() ?>

<div id="content" class="col span-8">

<?php if (have_posts()) : ?>

    <div class="col last span-6 nudge-2">
        <h4 class="ver small">You are reading</h4>    
    </div>
    
    <?php while (have_posts()) : the_post() ?>
        <?php $podcast = new Podcast($post, get_post_custom(get_the_ID())) ?>

    <div class="post">
        <div class="post-meta col span-2">
            <ul class="nav">
                <li>Artist: <?php echo $podcast->getSingleCustomFieldValue('artist') ?></li>
                <li>Genre: <?php echo $podcast->getSingleCustomFieldValue('genre') ?></li>
            </ul>
        </div>
        
        <div class="post-content span-8 nudge-2">
            <h3><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute() ?>"><?php the_title() ?></a></h3>

            <?php the_content('Continue reading...') ?>

            <p><?php echo nl2br($podcast->getSingleCustomFieldValue('trackList')) ?></p>
        </div>
    </div>
    
    <?php comments_template() ?>

    <?php endwhile ?>

<?php else : ?>

    <h3>Post Not Found</h3>

    <p>Sorry, but you are looking for something that isn't here.</p>

<?php endif ?>
    
</div>

<hr />

<?php get_sidebar() ?>
<?php get_footer() ?>

Important to note here is the line that creates an instance of your custom post type, <?php $podcast = new Podcast($post, get_post_custom(get_the_ID())) ?>. It's from this instance that we get the values of the custom fields.

Take a look at the second screenshot to see what you can expect from this template.

Screenshots

Resources added by plugin to Home page/Post page in kB
Total size of resources for Home page/Post page in kB
Random Theme Tests
Elegant Grunge screenshot

Elegant Grunge

by: michaeltyson

292780
100%
Summ screenshot

Summ

by: Axiu

33542
0%