How can I insert a block code inside a php page? [closed] - php

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I have this front-page.php page in my site and I want to put a block code directly in the php page. So I got a div and I want to put it in there. But the code is like
<!-- wp:latest-posts {"postsToShow":3,"displayPostContent":true,"excerptLength":30,"displayPostDate":true,"postLayout":"grid","displayFeaturedImage":true,"featuredImageSizeSlug":"large","align":"wide","className":"tw-mt-8 tw-img-ratio-3-2 tw-stretched-link is-style-default"} /-->
It's from a widget. I coudn't make it work please help :D

You can insert block code into any php template by using the function do_blocks() and passing in (valid) block content as a string, eg:
<?php
$block_content = '<!-- wp:latest-posts {"postsToShow":3,"displayPostContent":true,"excerptLength":30,"displayPostDate":true,"postLayout":"grid","displayFeaturedImage":true,"featuredImageSizeSlug":"large","align":"wide","className":"tw-mt-8 tw-img-ratio-3-2 tw-stretched-link is-style-default"} /-->';
echo do_blocks($block_content);
?>

Related

is there a php code that include/require a page and not a file? (PHP) [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
I have a page 'Error 404' and the address is like http://myurl.com/error404
the php file of error404 require's the index.php to properly show it.
I need a php code that will load or show the content in the url above without redirecting/changing the url. thanks
echo file_get_contents("http://myurl.com/error404");
Works also for URLs.
DOCS

How can I split <?php the_content();?> in two different parts on same page [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
I'm trying to achieve the following below:
Click here to see a diagram of what I'm trying to do
Pull first content using the code in figure 1.
Have some sort of slideshow/gallery system.
Pull the remaining content using the code in figure 2.
Currently I just get duplicate content, I'm obviously doing something wrong.
Can anyone advise?
Yes, It is wrong. You can use <?php the_content();?>only once in one page. If you want to show different content, put that content in widget and call the widget in page.
<?php dynamic_sidebar('id-of-widget-goes-here'); ?>
for example :-- <?php dynamic_sidebar('sidebar'); ?>

How can i repeat my div through loop in php WordPress [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I have one div so i want to repeat the same div three time when the someone open the page.
If anyone knows please help me out
You want to use foreach (but this can only be used with PHP, and not HTML directly)
<?php for($i=0;$i<10;i++): ?>
<div>your code</div>
<?php endfor; ?>
this will repeat 10 divs for you. save as .php file

Add an html footer/header in php files [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have an html website, I then have a php section of the website in wordpress for a shop page.
I want to use my current footer and header from my html pages for my php shop pages.
Any suggestions?!
Put the section inside the tags of your HTML page, and you should be good to go. Make sure to rename your files from name.html to name.php, otherwise the PHP code inside cannot be used. Without specific code examples, we are not able to help you much more then this: If you can, update your question with code examples and what you've tried already, so we are more likely to be able to help you.
Code example
<html>
<body>
<!-- Normal content goes in here -->
<?php
// Your PHP code goes in here
?>
</body>
</html>

Adding HTML menus to Includes(PHP) [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I am making a website using HTML. I am not familiar with PHP. I need the navigation and header part to be in a single place. i.e., Once I change the menus in one place it should reflect in all other pages. Kindly help me on this.
Thanks in Advance.
You could use include or require to add your Menu-Html file in every page you wish.
you could add something like this:
<?php
include('menu.html');
?>
wherever your menu should appear in your HTML, having a menu.html file of course.
and you'll need an apache server or any other that can 'read' your php files.
include php documentations
require php documentations

Categories