• Resolved saleb

    (@saleb)


    I have this template code that stopped working because of PHP use:

    <h3>Stories written:</h3>
    [if stories_written]
    <ul class="stories">
    [each stories_written]
    <li>
    <?php $name_tr = str_replace('-', ' ', $obj->display('post_name'));
    $name_tr = ucfirst($name_tr); ?>
    <a href="{@permalink}"><?php echo $name_tr ?></a>

    </li>
    [/each]

    </ul>
    [else]
    No stories found
    [/if]

    I have quickly changed it to:

    <h3>Stories written:</h3>
    [if stories_written]
    <ul class="stories">
    [each stories_written]
    <li>
    <a href="{@permalink}">{@post_name}</a>
    </li>
    [/each]

    </ul>
    [else]
    No stories found
    [/if]

    It works now, but I have dashes in post names. Is there a way to remove dashes without using PHP?

    Thank you

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Contributor Scott Kingsley Clark

    (@sc0ttkclark)

    <h3>Stories written:</h3>
    [if stories_written]
    <ul class="stories">
      [each stories_written]
        <li>
          <a href="{@permalink,esc_url}">{@post_name,my_custom_make_dashes_into_spaces_with_ucfirst}</a>
        </li>
      [/each]
    	
    </ul>	
    [else]
      No stories found
    [/if]

    You could try this PHP in a code snippet on your site in a custom plugin or theme:

    function my_custom_make_dashes_into_spaces_with_ucfirst( $value ) {
        // Update the value.
        $value = ucfirst( str_replace('-', ' ', $value ) );
    
        // Escape the value HTML if we do not want HTML output.
        $value = esc_html( $value );
    
        return $value;
    }
    Thread Starter saleb

    (@saleb)

    It works. Thank you

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.