WordPress.org

Ready to get started?Download WordPress

Forums

Custom Content Type Manager
[resolved] How do I call a template for the shortcode (7 posts)

  1. linuxplayground
    Member
    Posted 1 year ago #

    Hi,

    I am using a shortcode as follows:

    [summarize-posts post_type="bio" taxonomy="post_tag" taxonomy_term="farm" order="ASC" orderby="menu_order"]
    <p style="min-height:10px;clear:both;"> </p>
    <div class="bio_title">
    <h2 class="storytitle"><a href="[+permalink+]">[+post_title+]</a></h2>
    </div>
    <img class="mugshot" src="[+bio_mugshot:to_image_src+]" alt="" /><span class="bio_meta_heading">Position</span><span class="bio_meta_content">[+bio_position+]</span>
    <span class="bio_meta_heading">Phone</span><span class="bio_meta_content">[+bio_phone_number+]</span>
    <span class="bio_meta_heading">Email</span><span class="bio_meta_content"><a href="mailto:[+bio_email_address+]">[+bio_email_address+]</a></span>
    
    [+post_content+]
    
    <div class="fixfloat"></div>
    [/summarize-posts]

    What I really want to do is something like this:

    [summarize-posts post_type="bio" taxonomy="post_tag" taxonomy_term="farm" order="ASC" orderby="menu_order" tpl="path/to/bio.tpl]

    Where bio.tpl is:

    <p style="min-height:10px;clear:both;"> </p>
    <div class="bio_title">
    <h2 class="storytitle"><a href="[+permalink+]">[+post_title+]</a></h2>
    </div>
    <img class="mugshot" src="[+bio_mugshot:to_image_src+]" alt="" /><span class="bio_meta_heading">Position</span><span class="bio_meta_content">[+bio_position+]</span>
    <span class="bio_meta_heading">Phone</span><span class="bio_meta_content">[+bio_phone_number+]</span>
    <span class="bio_meta_heading">Email</span><span class="bio_meta_content"><a href="mailto:[+bio_email_address+]">[+bio_email_address+]</a></span>
    
    [+post_content+]
    
    <div class="fixfloat"></div>

    Is this possible. The private static function _get_tpl on wp-content/plugins/custom-content-type-manager/includes/SummarizePosts.php would seem to suggest this. But it never works.

    Please can you help. I don't want my editors to have to deal with the formatting of their "people" pages. I just want them to be able to enter in the shortcode and then they don't have to revert to HTML and can stay in happy WYSIWYG land.

    Thanks heaps for any help you can provide.

    Regards
    David Latham

    http://wordpress.org/extend/plugins/custom-content-type-manager/

  2. fireproofsocks
    Member
    Plugin Author

    Posted 1 year ago #

    I'm not fully awake, but from looking at the code, that should be possible (did you forget closing quotes on your tpl value?). I hadn't thought of using it that way, but that's a good idea.

  3. linuxplayground
    Member
    Posted 1 year ago #

    First of all - Good morning :) (its night time over in New Zealand)

    I guess the closing quotes was just a typo when completing the post.
    After posting this I added a help=1 option to the short code and this appeared:

    Shortcode:
    [summarize-posts offset="" orderby="menu_order" orderby_custom="" order="ASC" post_type="bio" taxonomy="post_tag" taxonomy_term="farm" tpl="wp-content/themes/fastfood-child/bios.tpl" help=1]

    Relevant part of response:

    Summarize Posts
    Errors
    There were no errors.
    Warnings
    Search parameters ignored: search_term and search_columns must be set.
    Notices

      Filtering on direct column/value: tpl: = wp-content/themes/fastfood-child/bios.tpl

    Execution Time
    0.01 seconds
    Arguments
    orderby: menu_order
    order: ASC
    post_type: Array (bio)
    omit_post_type: Array (revision, nav_menu_item)
    post_status: Array (publish, inherit)
    taxonomy: post_tag
    taxonomy_term: Array (farm)
    taxonomy_depth: 1
    search_columns: Array (post_title, post_content)
    join_rule: AND
    match_rule: contains
    date_column: post_modified
    tpl: wp-content/themes/fastfood-child/bios.tpl

    Its that line, "Filtering on direct column/value" that is worrying me.

    Maybe a cup of espresso will help clear things up ? :)

    Thanks for your help.
    Regards
    David Latham

  4. linuxplayground
    Member
    Posted 1 year ago #

    Sorry - here is the SQL it generated:

    SELECT wp_8_posts.ID FROM wp_8_posts LEFT JOIN wp_8_term_relationships ON wp_8_posts.ID=wp_8_term_relationships.object_id LEFT JOIN wp_8_term_taxonomy ON wp_8_term_taxonomy.term_taxonomy_id=wp_8_term_relationships.term_taxonomy_id LEFT JOIN wp_8_terms ON wp_8_terms.term_id=wp_8_term_taxonomy.term_id LEFT JOIN wp_8_postmeta ON wp_8_posts.ID=wp_8_postmeta.post_id WHERE ( 1 AND (wp_8_postmeta.meta_key = 'tpl' AND wp_8_postmeta.meta_value = 'wp-content/themes/fastfood-child/bios.tpl') AND wp_8_posts.post_type NOT IN ('revision','nav_menu_item') AND wp_8_posts.post_type IN ('bio') AND wp_8_posts.post_status IN ('publish','inherit') AND wp_8_term_taxonomy.taxonomy = 'post_tag' AND wp_8_terms.name IN ('farm') ) GROUP BY wp_8_posts.ID ORDER BY wp_8_posts.menu_order ASC

    Its adding the value of my template to a where clause... Huh?

  5. linuxplayground
    Member
    Posted 1 year ago #

    OK - I think I have it resolved. I had to edit your code. Never a good thing for me because when you update the plugin, my edits will all be gone. But it's that important to me.

    After much inserting of var_dump($blah); exit; lines I figured out what was happening.

    The changes I made are as follows:

    1. In the get posts function I included a block to unset $raw_args['tpl'] as follows (just after the block that unsets the help option... :) :

    //added code to unset tpl from raw_args so it's not used in filter.
            if (isset($raw_args['tpl']) ) {
                unset($raw_args['tpl']);
            }

    2. I had to change the test order for the template. So the heirachy is: if there is a template argument, try to use it. If not or it fails to load the template then look for the $content value. If that's not provided then use the default or if it is provided, read it and parse the bit between the open and close shortcode.

    Here is the new function:

    //------------------------------------------------------------------------------
        //! Private functions
        //------------------------------------------------------------------------------
        /**
         * Get the template (tpl) to format each search result.
         *
         * @param string  $content
         * @param array   $args    associative array
         * @return string
         * EDIT - DAVID LATHAM - Changed order of test for empty(content) and
         *                       empty(args[tpl])
         */
        private static function _get_tpl($content, $args) {
            $content = trim($content);
            if( !empty($args['tpl']) ) {
                // strip possible leading slash
                $args['tpl'] = preg_replace('/^\//', '', $args['tpl']);
                $file = ABSPATH .$args['tpl'];
    
                if ( file_exists($file) ) {
                    $content = file_get_contents($file);
                }
                else {
                    // TODO: throw an error
                }
            }
            elseif ( empty($content) ) {
                $content = self::result_tpl; // default
            }
            // Read from between [summarize-posts]in between[/summarize-posts]
            else {
                $content = html_entity_decode($content);
                // fix the quotes back to normal
                $content = str_replace(array('”', '“'), '"', $content );
                $content = str_replace(array('‘', '’'), "'", $content );
            }
            return $content;
        }

    Maybe you want to give this some review time, and possibly include it in your next update? Otherwise - I will have to stick with this version or update your next update to suite...

    I really like the idea of handing out this short code to the editors and having the template take care of itself. Maybe it's something we could load into the database even from the manager side. But that's for another rainy day. I don't care about it ***THAT*** much.. :)

    Regards
    David Latham

  6. fireproofsocks
    Member
    Plugin Author

    Posted 1 year ago #

    Put this into the bug-tracker please -- once it's in there, I'll remember to add it to the next version of the plugin. Your edit makes sense -- the function there allows flexible filtering on custom fields, so it was considering "tpl" as a custom field name.

  7. linuxplayground
    Member
    Posted 1 year ago #

    Have raised issue on google code wiki here:
    http://code.google.com/p/wordpress-custom-content-type-manager/issues/detail?id=427

    Marking this thread as resolved.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic