Articles Tagged with wordpress

You are currently browsing 3 articles tagged with wordpress.

  • Creating a Basic Wordpress Plugin

    Published Friday 3rd of February 2012

    I recently created my very first Wordpress plugin (I've been coding themes for a few years though) and I thought I'd write down a little getting started for other plugin noobs out there.

    I'll cover how to configure your plugin, connect to the database using the WPDB, install and uninstall DB tables, create a page in the admin and submit forms.

    Be the first to post a comment

  • How to Create a Restaurant Menu in Wordpress 3 using Custom Post Types and Taxonomies

    Published Wednesday 18th of January 2012

    I recently created a restaurant website in Wordpress and for the first time got to use Wordpress 3's new "Custom Post Types" feature. Here I thought I'd explain how you too can create a menu using the same.

    We'll create a menu where each dish has a title, picture, description and price. Each dish will also be grouped under a category like "Meat" or "Fish".

    First, we'll create our new post type for our dishes. Put this in your theme's functions.php file:

    <?php
    register_post_type
    ('dishes', array(
        
    'label'                => __('Dishes'),
        
    'singular_label'    => __('Dish'),
        
    'public'            => true,
        
    'show_ui'            => true,
        
    'capability_type'    => 'post',
        
    'hierarchical'        => false
        
    'query_var'            => false
        
    'supports'            => array(
            
    'title',
            
    'editor',
            
    'excerpt',
            
    'thumbnail',
            
    'author',
            
    'page-attributes'
        
    )
    ));

    Refer to the Wordpress Codex if you're curious about all the options.

    That's all that's needed for a new menu item to show up in the admin; "Dishes". You could use "custom-fields" for the price but I think it's easier for the admin if we use the excerpt instead.

    Now let's create a custom taxonomy for grouping our dishes:

    <?php
    register_taxonomy
    ('dish_types''dishes', array(
        
    'label'            => __('Dish Type'), 
        
    'hierarchical'    => true
    ));

    That's it. Now when you add a new "Dish" you'll get to choose from your "Dish Types". Go ahead and add some new "Dish Types" and then add a couple of "Dishes" to each type.

    Now we have everything we need in the admin / backend. All that's left is to display the menu on our website. We'll create a custom template for our menu called "menu.php". You can make it a copy of "page.php" so that the admin can still add text to the menu page. You need to set the "Template Name"-comment in the top of the file for Wordpress to recognize our new template:

    <?php /* Template Name: Menu */ ?>

    No let's write the code we need to fetch all our dish types as well as dishes. This code goes in the previously created menu.php, below the page-specific stuff:

    <section id="menu">

        <?php $types get_terms('dish_types', array('orderby' => 'id')) ?>

        <?php foreach ($types as $type) : ?>
            <h3><?php echo htmlspecialchars($type->name?></h3>

            <?php if ($type->description) : ?>
                <p><?php echo htmlspecialchars($type->description?></p>
            <?php endif ?>

            <?php $dishes get_posts(array('post_type' => 'dishes''dish_types' => $type->slug)) ?>

            <ul>
                <?php foreach ($dishes as $post) : setup_postdata($post?>
                    <li>
                        <h4><?php the_title() ?></h4>

                        <?php the_post_thumbnail() ?>

                        <p class="price"><strong><?php the_excerpt() ?></strong></p>

                        <?php the_content() ?>
                    </li>
                <?php endforeach; wp_reset_postdata() ?>
            </ul>
        <?php endforeach ?>

    </section>

    The code should hopefully be pretty self explanatory. The meat of it is first the call to get_terms() which retrieves all the terms for a taxonomy and get_posts() which is used to retrieve any post type based on params.

    As you can see I use the_excerpt() to store the price of the dish. If you'd rather use a custom fields called "Price" you would display it like this: echo get_post_meta($post-&gt;ID, &apos;Price&apos;, true).

    Happy Wordpressing!

    Join 6 others and post a comment

  • HTML5 Base Wordpress Theme

    Published Tuesday 3rd of January 2012

    Like so many others I've now also written my own HTML5 starter theme for Wordpress.

    It's based on the Bones Wordpress Theme which is based on the HTML5 Boilerplate.

    A few things I've changed from Bones:

    • Removed all the class names from the markup (clearfix in particular)
    • Removed all the CSS but normalize + some mixins (you're meant to style the site yourself)
    • "Modularized" the code (each module is contain within its own file rather than all the modules for one page being in one file)
    • Went through every line of code in every file and tidied things up

    The theme comes with some widget areas and menu spots but you'll most likely wanna change them for your own site. It also supports post thumbnails and attachments (the plugin) support is on its way.

    This is actually version 2 of this theme. The first version was based on I think the Kubrick theme from I dunno, before 3.0 anyway, so I felt it was time to brush things up and enable some new features.

    I've also studied best practice theme development articles and spent time in the Wordpress "codex" trying to figure out the fucking mess that Wordpress is to make sure this theme is as robust as possible.

    It's mainly written for myself but of course anyone is free to use it.

    Join 6 others and post a comment

Random jQuery Plug-ins

  • Togglable DL

    Use this plug-in on your definition-lists (dl-elements) to allow the dd:s for a dt to be toggled when clicking the dt. Don't use it unless it's semant...

    Details

  • Slide Presentation

    A sort of slide/presentation kind of plug-in. Displays sliding images with text floating on top. This one's pretty specific but perhaps someone will f...

    Details

  • Numeric DL

    This tiny plug-in numbers definitions in a definition-list if there are more than one definition for a term. Can be useful for FAQs, actual lists of d...

    Details

More Plug-ins

Recent Comments

Powered by Disqus