My code:
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<div class="posts" id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<h2>
<?php the_title(); ?>
</h2>
<div class="entry">
<?php the_content();?>
</div>
</div><!--post end-->
<?php endwhile; ?>
<?php else : ?>
<h3>no content</h3>
<?php endif; ?>
I put the code into my customed wordpress theme file single.php. Why it can't output the post content, it can output the post title. thank you.
You can try the following to see if it works instead of the_content
<?php echo wpautop($post->post_content); ?> // content with p tags
<?php echo $post->post_content; ?> //without p tags
Also an option
<?php echo wpautop( get_the_content() ); ?> // content with p tags
see if that works for you.
When developing Wordpress themes it's advisable for you to switch the debug mode (found on your installation's root in wp-config.php) to true. This will alert you if you have any errors.
In your case, try out the <?php the_excerpt(); ?>.
Also, this may sound a bit dumb, but do you actually have posts? Not pages or rather content in that post?
Many a times i have come across queries from developers or first time theme developers about not able to show the_content() on their custom template page.
The issue is that the_content() function runs inside the WP loop so for example
if (have_posts()) {
while (have_posts()) {
the_post();
the_content();
}
} ?>
This will work, but in some cases you want to call the function outside the loop – the solution for that is:
echo $post->post_content;
Related
I want to display the title from a parent field within a single child post (these are custom posts created with wp-types).
At the moment, all I seem to get is the title of the current post, and not the parent.
Below is my markup.
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<h2><?php the_title(); ?></h2>
<div class="the-copy">
<?php the_content(); ?>
</div>
<div class="parent-title">
<?php
$parent_title = get_the_title($post->post_parent);
echo $parent_title;
?>
</div>
<?php endwhile; ?>
<?php endif; ?>
Am I doing something wrong or have I missed something?
Thanks for you help, from what I can see this should be simple but it's just not working for me.
Managed to find the solution here
Essentially, as I was using the Types plugin standard parent / child wordpress code wouldn't work
I used the following code in my page template:
<?php
while(have_posts()):the_post();
the_content();
?>
But nothing is displayed. The loop is not working. I'm sure that, there is sufficient information as content in my template page.
You should use if condition to check if post exists else skip the loop. Make sure to ON the error log and check the exact error.
<?php wp_reset_query(); ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<?php the_content(); ?>
<?php endwhile; else: ?>
<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
<?php endif; ?>
<?php
/**
* Template Name: My Template
*/
the_post();
the_content();
?>
If you save the following code as a page template and call the page template into a page by choosing it, then the page will show the page content without any hassle.
Note: it's THE minimal bit of code.
use the following code
Try using wp_reset_query()
<?php
wp_reset_query();
while(have_posts()):the_post();
the_content();
endwhile;
?>
http://www.florence.inspiremeland.gridhosted.co.uk/
I tried every single possible way to remove my feature images from my single posts while keeping the images when you visit my home page.
First of all I tried to use the following code:
.single-post .attachment-post-thumbnail {
display: none;
}
Along with many other in my style.css or single post file without any success.
This is in my single.php file:
<?php get_header(); ?>
<div class="container">
<div id="content">
<div id="main" <?php if(get_theme_mod('sp_post_layout') == 'full') : ?>class="fullwidth"<?php endif; ?>>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php get_template_part('content'); ?>
<?php endwhile; ?>
<?php endif; ?>
<?php if(get_theme_mod('sp_post_layout') == 'full') : else : ?><?php get_sidebar(); ?><?php endif; ?>
</div>
<?php get_footer(); ?>
Let me know what part you need from my CSS perhaps if you could help?
I am really desperate to solve this :(
2.
When I visit my blog posts the sidebar is below content and not at the side, my website is not live yet so I cannot show you that but if you could help I would really appreciate it.
Betty
Have a look at standard.php in includes/post-formats/ and you should find something like <?php the_post_thumbnail('thumbnail'); }?> which you can remove.
So i'm quite a beginner, trying to make a custom theme. In a page i want to have a gallery. Uploaded images, made a gallery all fine.
When I view the page it outputs only the shortcode:
[gallery orderby="post_date"]
my page.php file basically has:
<?php $content = get_page( $page_id ) ?>
<div id='content' class='shadow'>
<div id='innercontent'>
<!---page title-->
<?php echo "<h1>".$content->post_title."</h1><br>" ; ?>
<?php echo $content->post_content ?>
</div>
</div>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
I really don't understand how to get this to show correctly, any pointers would be greatly appreciated. Cheers, Matt
get_page returns the raw page data. There are a few ways to do what you want:
BAD WAY:
<?php $content = get_page( $page_id ) ?>
<div id='content' class='shadow'>
<div id='innercontent'>
<!---page title-->
<?php echo "<h1>".$content->post_title."</h1><br>" ; ?>
<?php echo do_shortcode($content->post_content); ?>
</div>
</div>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
do_shortcode() renders all registered shortcode that's found within a given string. In this case, your page's content will have all shortcode rendered before being written to the document. I say this is the "bad" way, only because it doesn't follow the usual Wordpress format. Which leads us to the:
BETTER WAY:
<?php if(have_posts()) : while(have_posts()) : the_post(); ?>
<div id='content' class='shadow'>
<div id='innercontent'>
<!---page title-->
<h1><?php the_title(); ?></h1><br>
<?php the_content(); ?>
</div>
</div>
<?php endwhile;endif; ?>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
This is what's called "The Loop". It is pretty much the standard for all Wordpress Themes in retrieving all Post or Page Data, as well as running queries against the database.
I would suggest getting to know it, as well as running Wordpress queries to modify the loop using WP Query. This is getting into a more complex area of Wordpress, but it will help you in the longrun with figuring out how to gather up all of the posts and pages you want to retrieve in your theme that aren't provided by Wordpress' globals.
Good luck.
So I have a page called "latest news" and using a custom template t_latest_news.php
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div class="latest-news" id="post-<?php the_ID(); ?>">
<?php the_content(); ?>
<?php edit_post_link('Edit this page','<p class="edit-link">','</p>'); ?>
</div><!-- /.latest-news -->
<?php endwhile; endif; ?>
I've created a page item and put some content into that page. Now, I want to show the content on the sidebar. How can I do that please?
I've tried something like:
<?php include(get_query_template('t_latest_news.php')); ?>
<?php include(TEMPLATEPATH . 't_latest_news.php'); ?>
<?php get_query_template('t_latest_news.php') ?>
<?php get_template_part( 't_latest_news.php' ); ?>
But none of them works. HELP!
<?php query_posts('page_id=76'); ?>
<?php while (have_posts()) { the_post(); ?>
<h2><?php the_title(); ?></h2>
<?php the_content(); ?>
<?php } ?>
<?php wp_reset_query(); ?>
It works with "page_id" but not pagename. any idea?
To query a specific page by name you do this:
<?php
query_posts('pagename=about'); //retrieves the about page only
?>
You should remove the .php at the end so that it reads t_latest_news
I was just showing this as an example, please be advised:
The query_posts function is intended to be used to modify the main page Loop only. It is not intended as a means to create secondary Loops on the page. If you want to create separate Loops outside of the main one, you should use get_posts() instead. Use of query_posts on Loops other than the main one can result in your main Loop becoming incorrect and possibly displaying things that you were not expecting.
see: http://codex.wordpress.org/Template_Tags/get_posts for more information