D
D
Daniil Cherny2020-07-14 09:25:02
WordPress
Daniil Cherny, 2020-07-14 09:25:02

Wordpress theme and how to split post title?

I am writing a theme for wordpress and the question arose of how to make the post title divided into two parts if it consists of a date and a month.
Perhaps there is some function that will indicate the first word in the first paragraph, and the second word in the second.
Here is a block:

<?php 

                    $args = array(
                      'numberposts' => 5,
              'category' => 2,
                      'post_status' => 'publish',
                    ); 

                    $result = wp_get_recent_posts($args);

                    foreach( $result as $p ){ 
                      ?>
                                <div class="item flex">
                                    <div class="date flex">
                                    	<p id="day"><?php echo $p['post_title']; ?></p>
                                        <p id="mounts"><?php echo $p['post_title']; ?></p>
                                    </div>
                                    <div class="details flex">
                                        <p><?php echo $p['post_excerpt']; ?></p>
                                        <a href="<?php echo get_permalink($p['ID']) ?>">
                                            <p id="more">Детальніше <img src="<?php bloginfo( 'template_directory' ) ?>/image/arrow.png"></p>
     
                                        </a>
                                        
                                    </div>
                     
                                </div>
                 
 <?php
              } 
              ?>
                            </div>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Eugene, 2020-07-14
@wannacry220

<?php
$str = explode(' ', $p['post_title']);
?>
<p id="day"><?php echo  $str[0]; ?></p>
<p id="mounts"><?php echo  $str[1]; ?></p>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question