Apart from the horribly format issues you also have a typo:
<?php
$my_excerpt = $item->post_excerpt;
if ($my_excerpt){
echo Str::limit($my_excerpt, 120);}
else
$content = ($item->post_content);{
$contentexcerpt = substr($content, 0, 150);
echo $contentexcerpt, '...';
}
?>
These lines:
else
$content = ($item->post_content);{
should be:
else {
$content = ($item->post_content);
The parser registered a single line of code corresponding to the else
statement, mainly this: $content = ($item->post_content);
After that, the code between the curly brackets:
{
$contentexcerpt = substr($content, 0, 150);
echo $contentexcerpt, '...';
}
is treated like any other block of code and that is why if the if ($my_excerpt)
conditioned is passed it will still output the custom excerpt.