WordPress.org

Ready to get started?Download WordPress

Forums

Show custom output from a plugin (4 posts)

  1. flavio
    Member
    Posted 4 months ago #

    I need to build a plugin and use it to manage some custom elements (music albums and songs) in the backend. I store data in a separate db table.

    I want to list those albums and songs in the frontend of the site. How can I can tell WP to let my plugin render the output?

    In other words, how can I show data that I have in the database, in a similar way to what Drupal/Joomla allow to do? E.g. call the plugin directly from the URL, manage the URL structure from within my plugin.. is it possible at all with WordPress?

  2. bcworkz
    Member
    Posted 4 months ago #

    You cannot call plugin files directly if you want to use WP resources. If your plugin output is intended to be its own stand alone page, I suggest you create a custom page template to handle displaying the content. Normally page templates should reside in the current theme's folder so they show up in the template pull down field when editing pages.

    Actually templates can reside anywhere as long as they do not need to show up in the drop down. For plugins this is often a good thing. Your plugin can insert new pages using wp_insert_post(). This establishes the slugs by which the page is accessed. Initially insert the page as if the default template is the one desired. After inserting the page, specify the actual page template you want to use in postmeta under the key '_wp_page_template'.

  3. flavio
    Member
    Posted 4 months ago #

    Thanks bcworkz, I've also been thinking about using shortcodes, and once an album has been defined in my own plugin admin interface, let the user show it on the site by creating a page, and add to its content a shortcode that renders the album the way I want.

    This way I don't need to deal with themes and layouts in case I'll decide to distribute the plugin, something I'd need to consider if using page templates

  4. bcworkz
    Member
    Posted 4 months ago #

    Yes, shortcodes are great for modular bits of content that need to be consistent, but you want the user to have control over when and where the content appears. A page template like I described generates all of the content between header and footer. Depending on the nature of the content, it should work well regardless of which theme is being used. It really comes down to how much user involvement there is in the page.

Reply

You must log in to post.

About this Topic