Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Excellent plugin, my only problem is that I can't get the value of a custom field displayed where I want to.

I have a custom field: imgx It's value is an HTML code, specifically for an image, like:

<img src="mydomain.com/xxx.jpg">

I want to place this left of the post title in the template. How do this? Please post a code sample for the template file. I tried with 'echo', but nothing happens.

Thanks in advance for your help!

Sorry about this, I thought that people would know that if I'm using this tag, it woulf be obvious, that I'm referring to the Wordpress plugin List Category Posts. It's my First time here guys :)

Anyway, here's the template that I want to get working. My comments start like this: //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;        
share|improve this question
2  
What Plugin (link to Extend listing)? We need to see the code for how the post custom meta is saved. –  Chip Bennett Jun 17 '12 at 19:30
1  
There is no echo in your code example. Guessing games are not … useful. –  toscho Jun 17 '12 at 20:44
    
Thanks for reminding me, I just edited the post. It's my first time.. :) –  Zoltan Madai Jun 18 '12 at 7:37
    
So much for community support, aye? I would've expected at least an "ok, coming soon" from the plugin developer, but never mind. Good luck for all the others trying to get help here... –  Zoltan Madai Jun 20 '12 at 7:25
1  
Although lots of support are offered here, this is not a "support site". For that you have the plugin support page. BTW, is the plugin author aware of this question of yours? :::: I suggest that you strip your code to the bare minimum and use var_dump or print_r to check for the variable values. Also shouldn't it be $single->ID instead of $post->ID? –  brasofilo Jun 22 '12 at 21:43
add comment

1 Answer

Add a line like this for each custom field you'd like to display in your template code. You can display multiple custom fields. You may have to comment out the default custom_field_display line.

$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

Then you can use the shortcode to call custom your fields from your within your page content area in your WP admin.

[catlist customfield_display="custom_field1,custom_field2" customfield_display_name="no"]

Info on shortcodes and creating a custom PHP template for the a specific cat-list are here: http://wordpress.org/plugins/list-category-posts/other_notes/

Hope that helps.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.