I'm trying to create my own template in CMS WordPress. I would like to have live editable text on my page http://restaurant.g6.cz/. I want to create something like posts and edit them from the web, because I can't think of anything better. I tried to paste into (page.php) something like
<?php
$my_post = get_post(168);
echo $my_post->post_content;
?>
and tried edit the text with plugin Live Editor but I wasn't successful, so I tried to write
<?php query_posts('cat=5&showposts=1'); ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<?php the_content(); ?>
<?php endwhile; endif; ?>
<?php wp_reset_query(); ?>
this was editable but every post needed it's own category. Does anyone know, how to do this in PHP or better way without plugins? Thank you all very much :)
Example
Related
I am using my own custom WordPress theme and I am running into trouble displaying the content of blog posts. I can display the title and the date it was published using php but I can't get any of the paragraphs, images, headings, etc. to display on the page. I am using Gutenberg blocks (default) for the content of the blog posts.
I have tried using php functions to grab the content but they don't seem to be working.
<div class="col-md-6 col-md-offset-3">
<p class="date"><span class="glyphicon glyphicon-time">
</span> <?php echo get_the_date();?></p><br />
<p><?php $content = apply_filters('the_content', $post-
>post_content);?></p>
</div>
I am expecting the content of the post to display within the div container but the function is not grabbing the content. Any help would be appreciated!
It sounds like you may be trying to retrieve the post content from outside the loop.
If you look at the post template for a theme e.g. 2017, it is this bit that does the magic. It’s not even necessary to pass a post ID:
<?php
while ( have_posts() ) : the_post();
get_template_part( 'components/page/content', 'page' );
// If comments are open or we have at least one comment, load up the comment template.
if ( comments_open() || get_comments_number() ) :
comments_template();
endif;
endwhile; // End of the loop.
?>
E.g. you should just be able to do:
<?php
while ( have_posts() ) : the_post();
the_content();
endwhile; // End of the loop.
?>
Might be a good idea to start with the code on the link above, or copy the single.php file for the theme you’re using and use that as the basis for your custom post page?
I'm trying to use shortcode in post to display gallery but on website it puts out shortcode itself as text.I'm using
<?php the_content();?>
in php file.
Same shortcode works well with
<?php echo do_shortcode('[shortcode here]')?>
but in this case I need it to be shortcode in post editor.
No need to write PHP code and just put [shortcode here] in the WordPress Post Editor.
If you want to use short code in wordpress post editor then no need to write php code.
And if you want to user the_content() in any wordpress .php file then you need to write and follow code pattern.
for example (example of single.php)-
<?php
while (have_posts()) : the_post();
the_title();
the_content();
endwhile;
?>
Lets consider that you are on the checkout page, in the dashboard > Pages > Checkout Page you enter this [woocommerce_checkout] and
In page-checkout.php file of your wordpress you can write your custom code to make it work.
Here is an example of my custom code :
<?php
if (have_posts()) : while (have_posts()) :
the_post(); ?>
<div class="container">
<div class="checkout-page my-4">
<?php the_content(); ?>
</div>
</div>
<?php endwhile; endif; ?>
Sorry for bad English :-P
Try adding following code in your active themes functions.php
add_filter( 'the_content', 'do_shortcode' );
I've read, watched so many articles and videos and just can't seem to put my hands on one thing. Any help would be appreciated.
So here it goes..
I have a wordpress blog and that has been integrated into my website in the blog.php, so that people can see my blog from my website instead of being linked to wordpress.. I wanted my clients to post comments from my blog.php site and currently it's only showing the default comment_form part(which is too big and not what I wanted) So I installed comments plugin called "DISQUS", but currently it's only showing up on my wordpress page and not my website at blog.php.
Could there be a php code that I'm missing to post on my blog.php?
So far this is what I have on the top of the blog.php page
<?php require('../wordpress/wp-blog-header.php');?>
and where I'm showing my blog part
<?php require('../wordpress/wp-blog-header.php');?>
<?php get_header();?>
<?php $posts = get_posts('numberposts=10&order=orderby=post_date'); ?>
<?php foreach ($posts as $post) : setup_postdata( $post ); ?>
<?php the_title(); ?>
<?php the_time('m/d/y') ?>
<?php get_footer(); ?>
<?php the_content(); ?>
<?php comment_form(); ?>
<?php endforeach; ?>
So am I missing something here? Should I be changing comment_form into something else? Or am I completely off?
Thanks Everyone.
My Wordpress websites are not using single.php to show posts on the website. Every time I open a post, it opens it in index.php.
My single.php looks like this
<?php get_header(); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<? echo the_content(); ?>
<? endwhile;
endif; ?>
<? get_footer();
?>
How can I fix this?
I had the same problem with neither the single-CUSTOM-TYPE.php nor the single.php being rendered after clicking the single-post-link.... only index.php instead of the correct file...
What helped me was a simple change back to Standard Permalinks in "Settings" -> "Permalinks" and a restore back to "Name of the Post" (Beitragsname)....
...maybe this might help someone else as well...
greetz
This happens if the LOOP is not correctly setup ensure that index.php, and single.php contains the LOOP.
The loop normally looks something like this, but will change to setup requirements.
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
The Wordpress Codex site is pretty awesome and will answer most questions, check out http://codex.wordpress.org/The_Loop
Furthermore questions and discussions such as this one is more ideal if you post on stacks sister site Wordpress Stackexchange. I expect this question will be deleted or moved to https://wordpress.stackexchange.com/.
You should check your loop.php or loop-single.php weather it is routing from these files or not this are the page from where it will bring the data from database
In wordpress Twenty Eleven theme how to show read more after one post without writing any <!--read more--> in post page
Go wordpress admin panel and click reading under reading, choose summary instead of full text. That will help you.
Dashboard --> Settings --> Reading and click on "Summary" instead of "Full text"
EDIT:
The above settings for feeds. for showing in the home page, While you adding post put your cursor where you want to add "more" tag and then click Alt+Shift+T or click the button left to spell checker it will insert a more tag on your posts. I think this might work..
use the_excerpt() function in your post and add filter excerpt_more and add readmore.. link.
here this blog uses same function which is develop by me [Latest smartphone apps][1]
[1]: http://latestsmartphoneapps.com here on index page all post summery is given and readmore.. link is given which then display full post.
If you want such functionality let me know.
Use this code for Excerpt.
<?php query_posts('cat=ID'.'&showposts=NO. OF POST') ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<h3><?php the_title(); ?></h3>
<?php the_post_thumbnail(); ?>
<p><?php echo substr(get_the_excerpt(), 0,65).' [...]'; ?></p>
Read More...
<?php endwhile; ?>
<?php wp_reset_query(); ?>
<?php endif;?>
The a look at the_excerpt