Forums

[resolved] [Plugin: PHP Code Widget] PHP echo Custom Field (5 posts)

  1. seemsse
    Member
    Posted 3 years ago #

    Is it possible to use the PHP Code widget to display the results of a custom field. I have tried to setup the PHP Code Widget to do this:

    <?php echo get_post_meta($post->ID, "right feature", true); ?>

    but when I enter the custom field "right feature" nothing happens. Is this possible with the widget?

    Thanks,

    http://wordpress.org/extend/plugins/php-code-widget/

  2. esenterre
    Member
    Posted 3 years ago #

    Is it possible to use the include inside this widget. When I run my PHP code alone, it works fine, but when I try it inside that widget it seems to break.

    I want to include the magpie rss reader...

  3. Otto
    Tech Ninja
    Posted 3 years ago #

    @seemsse: The code inside the widget runs inside a function scope, meaning that "$post" is undefined unless you declare it to be in the global scope.

    <?php
    global $post;
    echo get_post_meta($post->ID, "right feature", true);
    ?>

    @esenterre: Yes, however it is difficult to say where your current location is when the code is running. You should use the various defines to define the location of the included file precisely. Also, you should include_once it, to prevent it from loading twice.
    include_once(ABSPATH . WPINC . '/rss.php');

  4. seemsse
    Member
    Posted 3 years ago #

    Otto42 -

    Thank you so much, that worked great.

  5. henigushi
    Member
    Posted 3 years ago #

    Hi Otto,

    I'm using your plugin to make the latest post for a certain category appear in my sidebar, and it works great.

    I am having a style problem, however. I have two widgets in my sidebar. One is yours, with the following code:

    <?php $recent = new WP_Query("cat=351&showposts=1"); while($recent->have_posts()) : $recent->the_post();?>
    <b><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></b>
    <?php the_content(__('Read the story &raquo;'));?><div style="clear:both;"></div>
    <?php endwhile; ?>

    The second is a text widget with two sentences in it.

    My stylesheet separates widgets into blocks, all separated by a gray border. Your plugin, however, combines the content of both widgets into a single block.

    Is there a way to break them up? I've used <div> tags for both, without success.

    Thanks!

Topic Closed

This topic has been closed to new replies.

About this Topic