• Resolved darttiglao

    (@darttiglao)


    Hi, I would like to insert the following php below and left aligned wrapped at the start of the_content. Hope someone can help me.

    <?php the_post_thumbnail() ;?>

    <?php if((get_post_meta($post->ID, “byline”, true))) { ?>
    <p class=”inside_byline”>by <?php echo get_post_meta($post->ID, ‘byline’, true); ?>
    <span class=”coltitle”><?php echo get_post_meta($post->ID, ‘column name’, true); ?></span></p>
    <?php } ?>

Viewing 5 replies - 1 through 5 (of 5 total)
  • like to insert the following php below and left aligned wrapped at the start of the_content.

    everywhere where the_content() is used?

    possibly use a filter function; https://codex.www.ads-software.com/Plugin_API/Filter_Reference/the_content

    code added to functions.php of your theme; example:

    add_filter( 'the_content', 'info_before_the_content' );
    
    function info_before_the_content( $text ) {
      global $post;
    
      $text = '<span class="alignleft pre-content-info">';
      $text .= get_the_post_thumbnail( $post->ID );
      if((get_post_meta($post->ID, "byline", true))) {
        $text .= '<p class="inside_byline">by ' . get_post_meta($post->ID, 'byline', true);
        $text .= '<span class="coltitle">' . get_post_meta($post->ID, 'column name', true) . '</span>';
        $text .= '</p>';
      }
      $text .= '</span>'; 
    
    return $text;
    }

    use .pre-content-info { ... } for additional formatting.

    (not tested)

    Thread Starter darttiglao

    (@darttiglao)

    alchymyth, thank you so much. Looks good. Will try it out. and will post again.

    Thread Starter darttiglao

    (@darttiglao)

    Thanks for you help on this I think Im getting progress.

    Although some slight hitches:

    1. I used your code and put in functions.php.
    The thumbnail and other custom fields appeared as I wanted. Although the rest of the content did not appear.

    2. And as an extra since you asked where I want the function to apply I was hoping it the function would happen only in specific categories.

    Many thanks in advance.

    1.
    my mistake;

    1. + 2.
    try:

    add_filter( 'the_content', 'info_before_the_content' );
    
    function info_before_the_content( $text ) {
      global $post;
    
      if( is_single() && in_category( array('cat1','cat2','cat3') ) ) {
        $pretext = '<span class="alignleft pre-content-info">';
        $pretext .= get_the_post_thumbnail( $post->ID );
        if((get_post_meta($post->ID, "byline", true))) {
          $pretext .= '<p class="inside_byline">by ' . get_post_meta($post->ID, 'byline', true);
          $pretext .= '<span class="coltitle">' . get_post_meta($post->ID, 'column name', true) . '</span>';
          $pretext .= '</p>';
        }
        $pretext .= '</span>';
        $text = $pretext . $text;
      }
    return $text;
    }

    https://codex.www.ads-software.com/Function_Reference/in_category

    Thread Starter darttiglao

    (@darttiglao)

    Perfect!!! You are awesome, alchymyth! Very helpful , patient and clear.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘insert php at within the_content’ is closed to new replies.