• Hi,

    I am using Arras 1431 with WP3.

    On my posts I include a custom field called ‘price’

    I now want to play with my code, so every post will automatically display the custom field ‘price’

    1/ So, what is the generated code for the custom field ‘price’ and how would I then change my template?

    As a working example, I want to change two things:

    2/ I want to change number of comments <?php comments_number() ? to ‘Price: € 99’

    <div class=”entry-info”>
    <abbr class=”published” title=”<?php the_time(‘c’) ?>”><?php printf( __(‘Posted on %s’, ‘arras’), get_the_time(get_option(‘date_format’)) ) ?></abbr> | <span><?php comments_number() ?>
    </span>
    </div>

    3/ I also want to change the get_the_time to the first two words of the page title, any ideas how to implement that, using,
    get_the_title combined with below code adjusted for title instead of excerpt:

    // Changing excerpt length
    function new_excerpt_length($length) {
    return 40;
    }
    add_filter(‘excerpt_length’, ‘new_excerpt_length’);

    Thanks for any input!
    Andy

Viewing 5 replies - 1 through 5 (of 5 total)
  • Output the custom field “price” by adding the following to your template:

    <?php echo get_post_meta($post->ID, 'price', true); ?>

    Thread Starter yesmaybe

    (@yesmaybe)

    Thanks freestyler,

    That’s the help I needed. However, while that works in a post, I am trying to display some highlights of a post on the main page.

    Under themes\arras-theme\library\tapestries.php I also added the get_the_ID() clause, and altered my code as below.

    if ($show_meta) {
    		$postheader .= '<span class="entry-meta"><span class="entry-price">' . get_post_meta(get_the_ID(), 'price', true). '</span>';

    Any ideas how to limit the length of the title displayed, maybe with css?

    Thanks.

    You could do it with css by making any overflow hidden but I don’t think that is the best way.

    You can limit titles by adding the following to functions.php:

    <?php function limit_title($title, $n){
    if ( strlen ($title) > $n )
    {
    echo substr(the_title($before = ”, $after = ”, FALSE), 0, $n) . ‘…’;
    }
    else { the_title(); }
    }
    ?>

    then outputting the title in the template with:

    <?php limit_title($post->post_title, 30); ?>

    30 being the limit, you should be able to modify this example to fit your needs.

    Thread Starter yesmaybe

    (@yesmaybe)

    Thanks for your help.

    I have used this code, as what you suggested messed up with the layout, maybe it was my mistake.

    $postheader .= ‘<abbr class=”published” title=”‘ . get_the_title() . ‘”>’ . substr(get_the_title(), 0 , 2) . ‘</abbr></span>’;

    Thanks.

    $postheader .= ‘<abbr class=”published” title=”‘ . get_the_title() . ‘”>’ . substr(the_title($before = ”, $after = ”, FALSE), 0 , 2) . ‘</abbr></span>’;

    try this once.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Use the 'custom field' code in templates’ is closed to new replies.