在LCP模板中显示自定义字段的内容

时间:2012-06-17 作者:Zoltan Madai

优秀的插件,我唯一的问题是我无法在我想要的地方显示自定义字段的值。

我有一个自定义字段:imgxIt的值是一个HTML代码,专门用于图像,如:

<img src="mydomain.com/xxx.jpg">
我想把这篇文章标题的左边放在模板中。如何做到这一点?请发布模板文件的代码示例。我试过用“回声”,但什么也没发生。

提前感谢您的帮助!

很抱歉,我想人们会知道,如果我使用这个标签,很明显,我指的是Wordpress插件列表类别的帖子。这是我第一次来这里,伙计们:)

无论如何,这是我想要使用的模板。我的评论是这样开始的:

 //zzz
        /**
         * The format for templates changed since version 0.17.
         * Since this code is included inside CatListDisplayer, $this refers to
         * the instance of CatListDisplayer that called this file.
         */

        /* This is the string which will gather all the information.*/
        $lcp_display_output = \'\';

        // Show category link:
        $lcp_display_output .= $this->get_category_link(\'strong\');

        //Add \'starting\' tag. Here, I\'m using an unordered list (ul) as an example:
        $lcp_display_output .= \'<ul class="lcp_catlist">\';

        /**
         * Posts loop.
         * The code here will be executed for every post in the category.
         * As you can see, the different options are being called from functions on the
         * $this variable which is a CatListDisplayer.
         *
         * The CatListDisplayer has a function for each field we want to show.
         * So you\'ll see get_excerpt, get_thumbnail, etc.
         * You can now pass an html tag as a parameter. This tag will sorround the info
         * you want to display. You can also assign a specific CSS class to each field.
         */
        foreach ($this->catlist->get_categories_posts() as $single):
            //Start a List Item for each post:
            $lcp_display_output .= "<li>";

            //zzz This is where I look for the custom field (displays nothing):
            $lcp_display_output .= get_post_meta($post->ID, \'imgx\', true);

            //zzz This is where I try to display stuff:
            //zzz this works: $lcp_display_output .= \'hello world\';
            //zzz this doesn\'t: echo "hello world"

            //Show the title and link to the post:
            $lcp_display_output .= $this->get_post_title($single);

            //Show comments:
            $lcp_display_output .= $this->get_comments($single);

            //Show date:
            $lcp_display_output .= \' \' . $this->get_date($single);

            //Show author
            $lcp_display_output .= $this->get_author($single);

            //Custom fields:
            $lcp_display_output .= $this->get_custom_fields($this- >params[\'customfield_display\'], $single->ID);

            //Post Thumbnail
            $lcp_display_output .= $this->get_thumbnail($single);

            /**
             * Post content - Example of how to use tag and class parameters:
             * This will produce:<p class="lcp_content">The content</p>
             */
            $lcp_display_output .= $this->get_content($single, \'p\', \'lcp_content\');

            /**
             * Post content - Example of how to use tag and class parameters:
             * This will produce:<div class="lcp_excerpt">The content</div>
             */
            $lcp_display_output .= $this->get_excerpt($single, \'div\', \'lcp_excerpt\');

            //Close li tag
            $lcp_display_output .= \'</li>\';
        endforeach;

        $lcp_display_output .= \'</ul>\';
        $this->lcp_output = $lcp_display_output;        

1 个回复
SO网友:user45199

为要在模板代码中显示的每个自定义字段添加这样的行。可以显示多个自定义字段。您可能需要注释掉默认的custom\\u field\\u显示行。

$lcp_display_output .= $this->get_custom_fields(\'custom_field_name\', $single->ID, \'span\', \'class_name\');
    // you can copy and paste this line, changing custom_field_name for each custom field you\'d like to display    

    //    $lcp_display_output .= $this->get_custom_fields($this->params[\'customfield_display\'], $single->ID);
    // may have to comment out default custom display to call one specifically
然后,您可以使用快捷码在WP管理员的页面内容区域内调用自定义字段。

[catlist customfield_display="custom_field1,custom_field2" customfield_display_name="no"]
有关短代码和为特定cat列表创建自定义PHP模板的信息如下:http://wordpress.org/plugins/list-category-posts/other_notes/

希望这有帮助。

结束

相关推荐

在LCP模板中显示自定义字段的内容 - 小码农CODE - 行之有效找到问题解决它

在LCP模板中显示自定义字段的内容

时间:2012-06-17 作者:Zoltan Madai

优秀的插件,我唯一的问题是我无法在我想要的地方显示自定义字段的值。

我有一个自定义字段:imgxIt的值是一个HTML代码,专门用于图像,如:

<img src="mydomain.com/xxx.jpg">
我想把这篇文章标题的左边放在模板中。如何做到这一点?请发布模板文件的代码示例。我试过用“回声”,但什么也没发生。

提前感谢您的帮助!

很抱歉,我想人们会知道,如果我使用这个标签,很明显,我指的是Wordpress插件列表类别的帖子。这是我第一次来这里,伙计们:)

无论如何,这是我想要使用的模板。我的评论是这样开始的:

 //zzz
        /**
         * The format for templates changed since version 0.17.
         * Since this code is included inside CatListDisplayer, $this refers to
         * the instance of CatListDisplayer that called this file.
         */

        /* This is the string which will gather all the information.*/
        $lcp_display_output = \'\';

        // Show category link:
        $lcp_display_output .= $this->get_category_link(\'strong\');

        //Add \'starting\' tag. Here, I\'m using an unordered list (ul) as an example:
        $lcp_display_output .= \'<ul class="lcp_catlist">\';

        /**
         * Posts loop.
         * The code here will be executed for every post in the category.
         * As you can see, the different options are being called from functions on the
         * $this variable which is a CatListDisplayer.
         *
         * The CatListDisplayer has a function for each field we want to show.
         * So you\'ll see get_excerpt, get_thumbnail, etc.
         * You can now pass an html tag as a parameter. This tag will sorround the info
         * you want to display. You can also assign a specific CSS class to each field.
         */
        foreach ($this->catlist->get_categories_posts() as $single):
            //Start a List Item for each post:
            $lcp_display_output .= "<li>";

            //zzz This is where I look for the custom field (displays nothing):
            $lcp_display_output .= get_post_meta($post->ID, \'imgx\', true);

            //zzz This is where I try to display stuff:
            //zzz this works: $lcp_display_output .= \'hello world\';
            //zzz this doesn\'t: echo "hello world"

            //Show the title and link to the post:
            $lcp_display_output .= $this->get_post_title($single);

            //Show comments:
            $lcp_display_output .= $this->get_comments($single);

            //Show date:
            $lcp_display_output .= \' \' . $this->get_date($single);

            //Show author
            $lcp_display_output .= $this->get_author($single);

            //Custom fields:
            $lcp_display_output .= $this->get_custom_fields($this- >params[\'customfield_display\'], $single->ID);

            //Post Thumbnail
            $lcp_display_output .= $this->get_thumbnail($single);

            /**
             * Post content - Example of how to use tag and class parameters:
             * This will produce:<p class="lcp_content">The content</p>
             */
            $lcp_display_output .= $this->get_content($single, \'p\', \'lcp_content\');

            /**
             * Post content - Example of how to use tag and class parameters:
             * This will produce:<div class="lcp_excerpt">The content</div>
             */
            $lcp_display_output .= $this->get_excerpt($single, \'div\', \'lcp_excerpt\');

            //Close li tag
            $lcp_display_output .= \'</li>\';
        endforeach;

        $lcp_display_output .= \'</ul>\';
        $this->lcp_output = $lcp_display_output;        

1 个回复
SO网友:user45199

为要在模板代码中显示的每个自定义字段添加这样的行。可以显示多个自定义字段。您可能需要注释掉默认的custom\\u field\\u显示行。

$lcp_display_output .= $this->get_custom_fields(\'custom_field_name\', $single->ID, \'span\', \'class_name\');
    // you can copy and paste this line, changing custom_field_name for each custom field you\'d like to display    

    //    $lcp_display_output .= $this->get_custom_fields($this->params[\'customfield_display\'], $single->ID);
    // may have to comment out default custom display to call one specifically
然后,您可以使用快捷码在WP管理员的页面内容区域内调用自定义字段。

[catlist customfield_display="custom_field1,custom_field2" customfield_display_name="no"]
有关短代码和为特定cat列表创建自定义PHP模板的信息如下:http://wordpress.org/plugins/list-category-posts/other_notes/

希望这有帮助。

相关推荐