Add point on excerpt post

时间:2016-08-29 作者:skifast

我定制了一个模板。这是我的密码

<?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>
我需要显示。。什么时候get_field(\'url_field_past\')

我尝试插入:

    if( get_field(\'url_field_past\')) {
        $myExcerpt = limit_content(get_the_excerpt(), 440);
        return \'...\';
        } 
但显示非内容摘录。

哪里错了?

1 个回复
最合适的回答,由SO网友:cjbj 整理而成

首先return 在PHP中用于从函数返回值。如果你想显示你需要的东西echo.

其次,在您指向的行中不显示摘录。检索摘录,然后将其存储在变量中$myExcerpt. 如果要添加... 对于摘录,您必须查看代码的显示位置。这发生在代码末尾附近的几行中,在不同的条件下,有如下几行:

echo \'<p class="phome">\'.$myExcerpt.\'</p>\';
通过将其更改为

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