I'm having a strange problem. I created a custom home page template to pull the latest 5 posts from two different categories into the layout (see "Learn and "Play" columns).
http://sensoryrevolution.com.s177767.gridserver.com/
I'm pulling in 4 fields through a custom query I copied+pasted from this very site:
Post thumbnail
Permalink
Post title
Excerpt
Only the excerpt is wrong. It's displaying the excerpt from the blog post above it.
Here's the code I'm using to pull this in. The weird thing is that it was working, and now it's broken. I've backed out some other custom code I had that was limiting the number of characters in the excerpt, so this is purely the_excerpt() working its magic.
<?php $posts = get_posts('category=213&orderby=desc&numberposts=5'); foreach($posts as $post) { ?>
<h4><?php the_title(); ?></h4>
<?php the_post_thumbnail('blog-large'); ?>
<p><?php the_excerpt() ?><?php // echo excerpt(22) ?></p>
<?php } ?>
This is driving me crazy! Does anyone have any ideas?
The post excerpt takes the excerpt from the excerpt field in wordpress. By default the excerpt field is not shown on wordpress single posts/pages in the admin backend. You can add it by clicking the "screen options" in the top right of the "add new" post/page (or custom pages). You can then input any text you would like as the excerpt.
As you can see by your var_dump, it is saying there is no excerpt in the post:
" ["post_title"]=> string(14) "It Makes Sense" ["post_excerpt"]=> string(0).
As stated before, the_excerpt() does not look for the excerpt in the main content body. If you don't feel like adding the excerpt field in the back end, you can do something like this:
$content = get_the_content(); echo substr($content, 0, 20);
This will output the first 20 characters of the string (which is the content of the page/post/custom post). Obviously you can do 40 or something like that as well, to appropriately output what you feel is the rite amount.
Happy coding!
Related
I've made a custom post type called 'news', plus an index page called 'archive-news'. In the archive page the excerpt is replaced with the content of the post. Can't work out how to change it.
I've been using HTML for over a year, familiar with the idea of Wordpress PHP but probably not deep enough yet. Had a look for similar problems. The input area for the excerpt has not been left blank (when you edit a custom post). I've heard that if it doesn't then it defaults to use content instead of excerpt. Cleared the cache many times and given it time to refresh.
<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
<div class="postExcerpt">
<p><?php the_excerpt(); ?></p>
</div>
<?php endwhile; wp_reset_query(); ?>
should show the excerpt and not the content in the archive-news
I've created a static page and by using the "Posts in page" plugins, have added a single post to the page.
but it seems that the post is cut off and adds a [...] at the end of the post.
I've checked the page.php file and it says <?php the_content(); ?>
where the content should appear.
How can I show the complete post, without getting it trimmed?
In
posts-in-page/posts_loop_template.php
Change
"the_content" to "the_excerpt"
LOL, I got them seer skillz.
So I had the idea to create a div with the class 90. where the <?php the_title( '<h3>', '</h3>' ); ?> of the page is shown in a 90° angle.
Works great. Just some tweaking to get the layout working correctly.
I added in the reading settings the option that A static page is selected for my posts.
Now I want that the page titel is shown in the DIV 90 and not the post title. But apparently the <?php the_title ?> is for both of them.
Is there a way to determine what title you want selected? So in this case load/echo the page title and dismiss the post title.
Hope I explained it right.
You should do a search in the WordPress codex, has a lot of useful information there..
https://codex.wordpress.org/
This is what I believe you are after:
<h3><?php wp_title(); ?></h3>
https://developer.wordpress.org/reference/functions/wp_title/
I'm teaching myself Wordpress, and my current goal is to display 4 thumbnails of images posted in a particular category.
I've already got the posts being pulled in by category, however I cannot pull ONLY the images. It's either the images and post text, or none at all.
My code is posted here: http://pastebin.com/NZ7fyyPA
I've tried simply replacing
<?php the_content(); ?>
with:
<?php the_post_thumbnail(); ?>
but that didn't work at all. Nothing came back at all!
I've even tried simply removing:
<?php the_content(); ?>
and same as above! I was thinking that because I have
<div class="entry-thumbnail">
<?php the_post_thumbnail(); ?>
</div>
That would pull the thumbnail in only, so I thought removing the content would help but nope!
I've read through the Codex here: http://codex.wordpress.org/Function_Reference/the_post_thumbnail
and the only question I have from that, is that immediately the Codex says:
"Use get_the_post_thumbnail($id, $size, $attr ) instead to get the featured image for any post."
Which I don't think I'm doing, because I haven't setup anything related to a 'featured image' in my theme...or is what I'm trying to do considered using a featured image? I'm only uploading images and posting them inside of the blog posts.
Sorry for the long write up, I'm sure it's something simple!
Thanks!
One more thing you can set a featured image from admin and call that image with this code the_post_thumbnail( $size, $attr ); and when you want to show anything from content part then you can call with this code simply. the_content();
you can also use excerpt for this as the_excerpt();
Thanks
This is a bit of a hack; however, it works.
While viewing your Wordpress website, use the browsers developer tools to target the 'post text'. You'll be able to see the id that is associated with that data-set.
Then, in your CSS. Target that id and use display:none;
Example:
#posttext {
display:none;
}
i am trying to insert a post/page into one of my themes files and it wont display shortcodes or php
i have created a page called home in the wordpress admin-paned and inserted into my code the following:
<div id="home_page"> <!-- echos the content from the page "home" id:43 -->
<?php $home_id = 43;
$home_page = get_page( $home_id );
?>
<?php echo $home_page->post_content; ?>
</div> <!-- end #home_page -->
and non of the shortcodes that i have in the page work.
i installed a php in post or page and tried useing php and it doesnt work.
when i insert
echo do_shortcode('[youtube_sc url=http://www.youtube.com/watch?v=Db3XGpt6nNU]');
directly into the code it works.
does anyone know y this happens?
thank you.
I got an answer in wordpress.stackexchange.com
I Quote:
You need to apply the filter the_content e.g.:
<?php echo apply_filters('the_content',$home_page->post_content); ?>
Also, you don't need custom shortcodes for youtube, just put the URL in the content (but not a hyperlink), and it'll be swapped out for a youtube player at runtime. No plugins or extra code needed thanks to oembed.
Thank You Tom J Nowell
The $home_page->post_content value is the exact post content as stored in the database. Echoing this does not give any of your shortcodes a chance to run.
You should use a "WordPress Loop" to display the content, as this sets things up to allow you to use template tags such as the_title() and the_content() - this will call the processing functions for shortcodes and other functions like wpautop() that "massage" post content for output.
If you don't want to use a Loop, you could output the content using
echo do_shortcode($home_page->post_content);
This will run the post content through the shortcode processor, giving the shortcodes a chance to run.
For more on how WordPress "massages" post content, you can look here: http://codex.wordpress.org/How_WordPress_Processes_Post_Content