0

I have customized a template. This is my code

<?php

global $paged;
//echo "<input id=\"varpag\" type=\"hidden\" value=\"$paged\" />";
if ($paged != 1){


echo"<style> .pintanto{display:none;}</style>";


}

/**
 * The template used for displaying page content in loops
 *
 * @package WordPress
 * @subpackage Twenty_Eleven
 * @since Twenty Eleven 1.0
 */
$theid = get_the_ID();
 $tipo = get_post_type( $theid );

$showImgEvidenza = is_page('storie-test') || $tipo == 'numeri';

 if (get_post_meta($theid,'nonclick', true)) {
    $hdiv = 'auto';
    $myExcerpt = get_the_content(); } else {

if ((is_page('magazine')) ||(is_page('ditalia'))||(is_page('english'))) {

     $myExcerpt = limit_content(get_the_excerpt(), 220);
     //$hdiv = '69px';
    } elseif ((is_page('gospel'))) {
         $myExcerpt = get_the_excerpt();
        }
        elseif ((is_home()) || (is_front_page())) {

            if (in_category('intanto')) {
                $myExcerpt = limit_content(get_the_excerpt(), 440);
                } else {
                $myExcerpt = limit_content(get_the_excerpt(), 220);
                }    




        } elseif (($tipo == 'numeri')&&($post->post_parent))
     { //&&(!get_post_meta($post->ID, 'approfondimento', true))echo $post->post_parent;

        $myExcerpt = limit_content(get_the_excerpt(), 220);
     $hdiv = 'auto';
        } elseif(is_page('approfondimenti')) {
     $myExcerpt = get_the_excerpt();
     $hdiv = '54px';
    } elseif(is_category()||is_search()) {
     //$myExcerpt = limit_content(get_the_excerpt(), 220);
      $myExcerpt = get_the_excerpt();
         $hdiv = 'auto';
    }

     else {
 $myExcerpt = limit_content(get_the_excerpt(), 75);
     $hdiv = '54px';
} }
$category = get_the_category();
        $parent = get_cat_name($category[0]->category_parent);


$titoloarc = the_title('','',false);



$src = wp_get_attachment_image_src( get_post_thumbnail_id($theid), 'thumb-loop', false );
//$src = wp_get_attachment_image_src( get_post_thumbnail_id($theid), array( 72,72 ), false, '' );

$fotohome = get_post_meta($theid,'fotohome', true);
?>
<?php if(($src)&&(!$fotohome)&&(!is_category())&&(!is_search())) {
    if ((is_page('approfondimenti'))||(is_page('gospel'))||(is_page('storie-da-leggere'))) {
        ?>
<li class="approfondimento" ><img style="width:72px" src="<?php echo $src[0]; ?>" alt="<?php echo $titoloarc; ?>"/>


<div style="float: left;padding: 20px 0 0 0;vertical-align: baseline;width: 340px;  height: 54px;overflow: hidden;">

    <?php } else {

        ?>
<li class="approfondimento" ><img style="width:141px" src="<?php echo $src[0]; ?>" alt="<?php echo $titoloarc; ?>"/>
<div style="float: left;padding: 0;vertical-align: baseline;width: 271px;

    <?php if ( (is_home()) || (is_front_page())|| (is_page('magazine')) ) { } else { ?>
    height: 54px;overflow: hidden;
    <?php } ?>
    ">
<?php

}

} else { ?>






<li class="approfondimento  <?php if (in_category('intanto') ) { echo 'pintanto"'; } else { echo '"'; } ?> >






    <div style="<?php if (in_category('intanto')) { echo 'width:386px;';} else { echo 'width:422px;';}
         if ( (is_home()) || (is_front_page()) ) { } else {
        //|| (is_page('lemag')) ?>
    height: <?php echo $hdiv; ?>;overflow: hidden;
    <?php } ?>
    ">
<?php }  ?>
<?php if (get_post_meta($theid,'occhiello', false)||(has_category()&& !in_category( 1 ))) {

    if ( $showImgEvidenza && has_post_thumbnail() ) {?>
    <?php };

    echo '<span class="autore">';

    //style="width:'.$widz.';"
    if ((has_category())&&( !in_category(  array(1, 154 )))) {
        the_category(' ');
        } elseif (in_category (154)) {
    ?>

            <a href="/storie-intanto/" title="Visualizza tutti gli articoli in INTANTO">INTANTO</a>
        <?php
            }
    echo get_post_meta($theid,'occhiello', true).'</span>' ; }

    if (!get_post_meta($theid,'nonclick', true)) {




    ?>

<?php
$the_link = get_permalink();
if( get_field('url_field_past') ) {
    $the_link = get_field('url_field_past');
}
?>

<a style="color:#000000!important;" class="thome" title="<?php echo $titoloarc; ?>"

    <?php  /* if (in_category('intanto') ) {
    echo 'href="/storie-intanto';
         } else { */ 
         ?>

    href="<?php echo $the_link; ?>

<?php //}  ?> 
">
<?php echo $titoloarc; ?></a>


<?php
} else {
     echo '<span style="color:#000000!important;float:left; font-size:15px; font-style:normal; font-weight:bold; line-height:17px; margin-bottom:6px;">'.$titoloarc.'</span>';
 }

   ?>
<?php if ( (is_home()) || (is_front_page()) ) {
        if (in_category('intanto')) {
        echo '<p class="phome" style="font-style:italic;" >'.$myExcerpt.'</p>';  } else {

    echo '<p class="phome">'.$myExcerpt.'</p>';     ?>
<div class="entry-meta">
<?php twentyeleven_posted_on(); ?> | <?php the_time('G:i'); ?>
</div>
<?php
}

} else {
    if ((is_page('magazine')) ||(is_page('ditalia'))||(is_page('english'))||is_single()||is_category()||is_search()) {
        echo '<p class="phome">'.$myExcerpt.'</p>';
    } else {
    echo '<p>'.$myExcerpt.'</p>';
    } } ?>
</div></li>

I need to display .. when get_field('url_field_past')

I try to insert:

    if( get_field('url_field_past')) {
        $myExcerpt = limit_content(get_the_excerpt(), 440);
        return '...';
        } 

But display nonthing excerpt.

Where wrong?

2
  • Where are you inserting this? Why are you using return?
    – cjbj
    Aug 29 '16 at 8:29
  • Insert on row #41 after 'if (in_category('intanto')'. I use return becouse i need to display 3 point (...) when post excerpt.
    – skifast
    Aug 29 '16 at 9:03
0

First of all return is used in PHP to return a value from a function. If you want to display something you need echo.

Second, no excerpt is displayed in the lines you are pointing to. The excerpt is retrieved and then stored in a variable $myExcerpt. If you want to add ... to the excerpt you must look in your code where it is displayed. This happens in several lines near the end of the code where under different conditions there are lines like this:

echo '<p class="phome">'.$myExcerpt.'</p>';

You easily get your three dots by changing that to

echo '<p class="phome">'.$myExcerpt.' ...</p>';
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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