• Resolved soleman

    (@soleman)


    I have a simple line I want to put in a custom field and it just won’t show up. It works when I place the code in single.php – it just doesn’t work when I put the code in through a custom field.

    Here is what I have on my single.php page:

    <?php echo get_post_meta($post->ID, “ko_text”, $single = true); ?>

    And in my custom field named ko_text I have: <?php echo ddpl_list(1); ?>

    I’ve been searching this site and the net for hours trying to find out if there is a way to do this…. !

    Thanks for your help.

Viewing 5 replies - 16 through 20 (of 20 total)
  • how would I put an else statement in there?

    Here’s the format I use since you can use regular, unaltered html and php with it:

    <?php if (in_category('5')) { ?>
    <!-- code here -->
    
    <?php } else { ?>
    <!-- code here -->
    
    <?php } ?>
    Thread Starter soleman

    (@soleman)

    Again – sickness! Thanks!

    hmm…. I actually could use some PHP code in my Custom Fields!

    I could really use PHP in my custom fields as well. I tried EXEC-PHP but it didn’t work in a custom field.

    What I am trying to do is display all sibling pages in the sidebar on only a few pages. There is no formula for the pages that I want to use it on otherwise I would use a conditional statement.

    Any help would be greatly appreciated.

    @soleman, I had a similar situation. I wanted to use a different template for certain categories of posts, so I renamed single.php to single-default.php and created a new single.php to test the categories. If it is one of the special categories, use single-in-category.php, otherwise, use single-default.php.

    I originally hard-coded the categories in the new single.php, but as I added new ones, I had to edit the code. My solution was to use https://planetozh.com/blog/my-projects/wordpress-theme-toolkit-admin-menu/.

    This toolkit was easy to integrate with my theme and made it simple to add an option called single_in_category. This contains a comma separated list of the category slugs or IDs. Now I can add or remove a category in the Admin page.

    Here is my new single.php:

    <?php
    // single.php is now in single-default.php
    // We want to use single-in-category for
    // all categories listed in the single_in_category
    // option which is set in the Appearance->Miata Club Options panel.
    // Uses global $mclub created by themetoolkit in functions.php
    global $mclub;
    $post = $wp_query->post;
    $mycats = array();
    if ($mycatlist = $mclub->option['single_in_category']) {
      $mycats = explode(',',$mycatlist);
    }
    
    if ( in_category($mycats)) {
      include(TEMPLATEPATH . '/single-in-category.php'); }
    else {
      include(TEMPLATEPATH . '/single-default.php');
    }
    ?>
Viewing 5 replies - 16 through 20 (of 20 total)
  • The topic ‘Can You Put PHP Code In Custom Field?’ is closed to new replies.