Support » Fixing WordPress » Problem with patterns

  • Resolved bobitza2010

    (@bobitza2010)


    I updated my wordpres from 5 to 6, everything died,

    So i started again with new theme base on a copy of twentytwentythree

    My problem is:

    i want to create a custom post-content in foreach of posts in home.html

    <!-- wp:query {"query":{"perPage":3,"pages":0,"offset":0,"postType":"post","order":"desc","orderBy":"date","author":"","search":"","exclude":[],"sticky":"","inherit":true},"displayLayout":{"type":"block"},"layout":{"type":"constrained"}} -->
    							<!-- wp:post-template {"align":"wide", "className":"entry"} -->
    						
    								<!-- wp:pattern {"slug":"xbackup4all_2023/post-content"} /-->
    								
    								<!-- wp:spacer {"height":"var(--wp--preset--spacing--40)"} -->
    								<div style="height:var(--wp--preset--spacing--40)" aria-hidden="true" class="wp-block-spacer"></div>
    								<!-- /wp:spacer -->
    							<!-- /wp:post-template -->
    
    							<!-- wp:query-pagination {"paginationArrow":"arrow","align":"wide","layout":{"type":"flex","justifyContent":"space-between"}} -->
    								<!-- wp:query-pagination-previous {"label":"Newer Posts"} /-->
    								<!-- wp:query-pagination-next {"label":"Older Posts"} /-->
    							<!-- /wp:query-pagination -->
    						<!-- /wp:query -->

    The post-content pattern:

    <?php
    /**
     * Title: Post Content
     * Slug: xbackup4all_2023/post-content
     * Inserter: no
     */
    ?>
    
    <div class="entry-timeline">
    	<span><!-- wp:post-date {"format":"d"} /--></span><span><!-- wp:post-date {"format":"M"} /--></span>
    	<div class="timeline-divider"></div>
    </div>
    <div class="entry-title">
    	<!-- wp:post-title {"isLink":true} /-->
    </div>
    <ul class="entry-meta clearfix">
    	<li><i class="fa fa-user"></i><!-- wp:post-author {"isLink":true} /--></li>
    	<li><i class="fa fa-folder"></i><!-- wp:post-category {"isLink":true} /--></li>
    </ul>
    <div class="entry-content">
    	<!-- wp:post-excerpt {"moreText":"Read more"} /-->
    </div>
    

    I want this: <!– wp:post-date {“format”:”d”} /–> to be writted with <?php echo get_the_date(‘d’); ?> because <!– wp:post_date return me an html i want pure date output echo ex: 23 not <div>….23</div>

    If i try with <?php echo get_the_date(‘d’); ?>in pattern on that <span> i get empty output why ? Why i cannot use <php ?> format in patterns ? Where i find full documentation of all of these wp new html markers <!– wp:

Viewing 6 replies - 1 through 6 (of 6 total)
  • Gutenberg Editor doesn’t understand php. It written with react blocks which is a javascript library. Gutenberg converts from react blocks to html with comments(which is stored in the post database) and then to HTML for the front end. You can’t use PHP in the gutenberg editor. It simply not supported. It a totally different programing language.

    lisa

    (@contentiskey)

    2 resources I’ve found useful to learn about creating block patterns:

    Thread Starter bobitza2010

    (@bobitza2010)

    @mrtom414 ok, my problem is next, i used a theme from 2007 until wordpress 6.1 release,, i updated eveything died… How can i use olds format, i have controlers php ex: index.php, single.php, content.php with PHP and don’t use this template markers ?

    The classical themes can still be used with php. So all the pages will still work as long as you are using a classical theme. The Content from the blocks are returned as html. If you look at them in the post database they are stored as html with a comment section. The comments are data that used by the blocks that can not be converted into html. If it can be converted to say a css element it will be put as an inline item. When wordpress returns your post It strips all the comments off and returns it as html. The same as before. The block editor doesn’t use php it using javascript. The block templates have the same hierarchy as the classical themes. so your single index 404 pages are ok.

    All the templates in the new editor are html not php. They are stored in a folder named templates. The new block templates don’t have any required php files. As of wordpress 6.0 you don’t even have to include the index.php file. But, I think it a good ideal to include index.php and functions.php even if they are empty. It really easy to start from nothing in the new block editor and create a complete theme. You can do it without writing any php code. I think the most difficult part is understand the theme.json file.

    Thread Starter bobitza2010

    (@bobitza2010)

    The documentation on all new things for wordpress 6 + are very bad…i thought i can use both methods, php + marker template like this

    <?php
    /**
     * Title: Post Content
     * Slug: xbackup4all_2023/post-content
     * Inserter: no
     */
    ?>
    
    <div class="entry-timeline">
    	<span><?php get_the_date('d'); ?></span><span><!-- wp:post-date {"format":"M"} /--></span>
    	<div class="timeline-divider"></div>
    </div>
    <div class="entry-title">
    	<!-- wp:post-title {"isLink":true} /-->
    </div>
    <ul class="entry-meta clearfix">
    	<li><i class="fa fa-user"></i><!-- wp:post-author {"isLink":true} /--></li>
    	<li><i class="fa fa-folder"></i><!-- wp:post-category {"isLink":true} /--></li>
    </ul>
    <div class="entry-content">
    	<!-- wp:post-excerpt {"moreText":"Read more"} /-->
    </div>
    

    mrtom414

    (@mrtom414)

    No because you are not dealing with php you will have to do it with a block. In the Theme section of the blocks you will find a few things that might help you. Since you are wanting dates look for a block for post date it should be in the theme section . You should find other similar blocks for the author, post title and so. You can use the block for the post date to add and format your dates. In the sidebar you will see an option for default post date. If you turn this option off a drop down will appear for alternative date formats. The last option will allow you to enter a custom format. Select which ever you need. You should find most of the blocks you need in the theme section of the block editor. There is also a loop query block which will allow you to run the wordpress loop and visually format the output.

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