Home Forums Weaver X Tutorials and Hints tutorial to add and display custom post

This topic contains 21 replies, has 3 voices, and was last updated by  scrambler 2 years, 5 months ago.

Viewing 16 posts - 1 through 16 (of 22 total)
  • Author
    Posts
  • #19212

    davidm
    Participant

    Hi really love the power xtreme puts at you finger tips, my problem is finding good tutorials on how best to use that power.
    Like to see a tutorial about adding custom fields, custom posts and taxonomies and how best to create templates to display them,
    I’m finding it difficult making sense of all the different plugins, shortcodes, how to add php for template formatting ect.
    Any help greatly appreciated
    Thanks
    David

    #29162

    Weaver
    Keymaster

    Most of what you are asking is beyond normal theme responsibilities – they are more general WordPress questions. When it comes to creating templates to display them, that is normally a very advanced custom WordPress theme (or child theme) developer question – way beyond the level of support we can offer.

    BUT – Weaver Xtreme is in fact somewhat unique in its ability to display custom post types. (Using custom fields is 100% dependent on custom PHP coding or a specialized plugin in a custom page type or custom post type handler, and way beyond any support we can offer.)

    Normally, custom post  types are used by plugins to display custom content (e.g., Weaver Show Sliders). Often, there will be plugin specific shortcodes to display that custom content via a shortcode.

    But if you use a plugin to generate custom post type content (the only way I know to do that), you can use the existing Weaver Xtreme Page with Posts. After you set a page to the Page with Posts template, you then can specify the slug of the “Custom Post Type”, and the content of those custom posts will be displayed using the default Weaver Xtreme post content display code. You can also do the same thing with the Weaver Show Posts plugin and shortcode.

    But beyond that, using and understanding Custom Post Types is outside the realm of any theme. I don’t have any recommendations on tutorials on how to do all that. There are all sorts of plugins to manipulate and use custom fields – but again, we have no recommendations.

    #29163

    scrambler
    Moderator

    I use Custom Post types on an Xtreme site as well as Custom filed for them.
    I use the Free Plugin Toolset Types below to do that
    https://wordpress.org/plugins/types/

    The plugin lets you create Custom Post types and Custom Fileds, and adds the custom fields User Interface in the Post editing page. It also gives you Shortcodes to insert the custom fields in your content where you need them.

    Then I simply use the Xtreme Theme “Page with posts template” to display them like I would any other posts.
    Just create a standard page, select the “Page with posts template” in the page attribute box and publish. You then have all the Xtreme theme option fro this page available, including a filter box for custom post types.

    Do make sure you have installed the Xtreme Theme Support Plugin.

    #29164

    davidm
    Participant

    Weaver, Scrambler Thanks very much for your input.
    I’m just struggling to get my head around all Weaver’s got to offer, problem is I can see the potential so I don’t want to give up.
    Scrambler I’m going to go with your suggestion and give Types a try – as a matter of interest do you know if I can do the same thing with “Advanced Custom Fields” ’cause that’s what I’ve been using for custom fields and post types, by creating the php templates, my problem is here the templates are more complex and my php coding skills aren’t to strong.
    Anyway thanks again, I’ll give Types a try – do you use the rest of the Toolset Package, Views and CRED with Weaver?
    If I use Types and “Page with posts template” do you suggest I use a child theme?

    #29165

    scrambler
    Moderator
    You have to separate creating the Custom Post types and custom fields, and creating templates.

    To create the Custom Post Types and Custom Fields, you definitely want a plugin.

    Then the question is how do you want to display these Custom post types. Depending on the type of layout you need, you will likely be able to simply use the Page with posts template provided by the theme with its options and eventually some custom CSS.
    An alternate solution is to use Weaver Show Posts Plugins, which also accepts Custom post types, and allows you to combine several Show_posts shortcodes with regular content on any given page.

    Once you have the Custom Post types / Custom Fields created, you need to experiment with both, and if you run into difficulties, explain in detail what you are trying to achieve. Then we can help determine if you may need to create Custom templates.

    As far as the Types plugin versus the Advanced Custom Field, I cannot answer as I do not know the later. But as far as creating Custom Post types and custom field, any plugin should provide the basics, and let you test if you can layout your posts using the theme tools or the show_posts plugin.

    #29166

    davidm
    Participant

    Hi Scrambler,
     I see that Advanced Custom Fields also has some shortcodes (and I think they have a better selection of fields eg. multi select list), but more importantly I understand it’s possible to create and “do_shortcode()” in functions.php, do you have any advice or pointers about using do_shortcode with Weaver?

    Thanks for your help
    David

    #29167

    scrambler
    Moderator

    if you have Plus, you can define your shortcode by putting the PHP in Advanced options > Head Section > Action & Filter Box.

    if not, then you will need to create a Child theme and make your modifications in there. Below is an example I did in a tutorial. But I am no PHP expert so I cant help with any of the details if you go the PHP route
    http://forum.weavertheme.com/discussion/8406/actions-filters-tips-and-examples-part2

    #29168

    davidm
    Participant

    Hi Scrambler,
    I’m not having much success with the shortcode route, mainly because the shortcodes are limited to simple text fields – select lists, check-boxes and taxonomy fields aren’t covered. So I’d like to try using custom post templates, I’ve done this successfully before but with a much simpler starter theme – underscores  (I’m going from 1 extreme to the other)
    Like to check with you if this is the right way to do it

    1. copy single.php to single_cpt.php
    2. In single_cpt.php change line <?php get_template_part( ‘templates/content’, ‘single’ ); ?> to
                                                   <?php get_template_part( ‘templates/content’, ‘single-cpt’ ); ?>
    3. Copy templates/content-single.php to templates/content-single-cpt.php

    4. Make the changes in templates/content-single-cpt.php

    Thanks for your help
    David

     

    #29169

    scrambler
    Moderator

    I cant help you with PHP.
    But If you want to create your own templates, you must do that in a Child theme, or else all your changes will be lost in the next update.
    You create your child theme, you copy the template you want to modify in there with a new name, and you edit them to do what you want.

    #29170

    davidm
    Participant

    Hi Scrambler,
    I’ve created some shortcode to display a table of medicinal plants, I’ve included this shortcode as a plugin.
    When I try to include the shortcode in a page, only the table header appears:


    Here’s the shortcode for the above:

    <?php
    /*
    * Plugin Name: Medicinal Plant Table
    * Description: Display all medicinal plants in a table
    * Version: 1.0
    * Author: David
    * Author URI: sharethecure.org
    */

    function plant_table()  {
        $output .= ‘<style>th {text-align:center}</style>’;
        $output .= ‘<table border=”1″ bordercolor=”#DDDDDD” class=”table table-striped” style=”width:70%”>’;
        $output .= ‘<caption>Test Table</caption>’;
        $output .= ‘<thead><th>Medicinal Plant</th>’;
        $output .= ‘<th style=”text-align: left;”><div>Family<br/><div style=”margin-left: 20px”>Genus<br/></div><div style=”margin-left: 40px”>Species</div></div></th>’;
        $output .= ‘<th>Parts Used</th>’;
        $output .= ‘<th align=”center”>Medicinal Use</th>’;
        $output .= ‘<th>view/hide details</th>’;
        $output .= ‘</thead><tbody>’;

    The function returns $output, but only the above appears on the page, all the table content that follows and is also added to $output is ignored, any idea why this should be happening? – The whole table appears correctly on my localhost using another theme

    Thanks for any help
    David

    #29171

    davidm
    Participant

    I guess it’s because the query:

        $args = array(‘post_type’ => ‘medicinal_plant’,  ‘author_name’ => ‘david’);    //  ‘posts_per_page’ => 5   
        $the_query = new WP_Query( $args );
        $row_cnt = 0;
    // The Loop
    while ( $the_query->have_posts() ){
        $the_query->the_post();   

    isn’t returning anything. What’s wrong with the above?

    #29172

    scrambler
    Moderator

    As I mentioned,  I do not have any real knowledge of PHP.

    So for PHP support, unless weaver decides to jump in, you will need to ask on the WordPress forum or a PHP dedicated site.

    #29173

    davidm
    Participant

    Ok, thanks Scrambler, actually you’re answer was helpful, now I know there’s not a Weaver reason it’s not working and I have to look at the PHP.

    Thanks
    David

    #29174

    Weaver
    Keymaster

    Using the WP loop is VERY tricky. If you have a shortcode/plugin that tries to run the loop, as yours does, then you will mess up the instance of the loop used by the page or post processing. In other words, you can’t nest instances of the loop without a lot of special processing, or things simply get lost.

    If you need an example, you could look at the code for the Weaver page with posts template (paget.php, I think). There is also similar code in the Weaver Show Posts shortcode.

    So, it is more of a theme related issue (actually, any theme, not just Weaver).

    And you are asking PHP and WP questions that are way beyond the level of support we provide – which must be theme or Weaver plugin related only. We are sometimes pretty broad in that interpretation, but creating general PHP code is beyond that. 

    #29175

    davidm
    Participant

    Ok, Thanks Weaver,
    In my naivety I thought that as a shortcode plugin it would run as a separate, independent piece of code and just return the output to the page. So if not could I use the shortcoder option in Weaver Xtreme Plus to output the table? Or do you have an alternative suggestion for outputting custom posts in a table format as per the table header above?
    Thanks for any help
    David

    #29176

    Weaver
    Keymaster

    You are on the correct track. It is typical to use a shortcode supported by plugin to output custom post content in whatever format needed. For example, the Weaver Show Sliders will use a custom slider post type to define the slider content, and a [show_sliders] shortcode to get that content. For this slider, the list of posts is defined as part of the short code, so there is no need to use the loop.

    But that is the standard approach for displaying custom post content.

    If the actual content of your custom post type is already formatted as a table that would fit under you table header stuff, then you might be able to use the Weaver Show Posts short code to display a defined set of your custom posts. – put the header on a standard page, and use [show_posts] to display your posts.

Viewing 16 posts - 1 through 16 (of 22 total)

You must be logged in to reply to this topic.