I am trying to get a custom single page to spit out the title and content of the post, the title works fine, the content of the post doesn't seem to want to come through. I don't work much in wordpress so I am in the dark here, can someone tell me how to fix this? Here is my single-news.php code:
<?php get_header(); ?>
<div class="decade1">
<?php
echo get_the_title().'<br/>'; //Output titles of queried posts
echo get_the_content().'<br/>';
?>
</div>
<?php get_footer(); ?>
Thanks!!
You need the WordPress Loop before using tags like get_the_title().
<?php get_header(); ?>
<div class="decade1">
<?php
if ( have_posts() ) {
while ( have_posts() ) {
the_post();
echo get_the_title() . '<br/>';
echo get_the_content() . '<br/>';
} // end while
} // end if
?>
</div>
<?php get_footer(); ?>
get_the_content() must be use in loop.
syntax:
get_the_content( $more_link_text, $stripteaser )
where $more_link_text and $stripteaser are optional.
read about it
and get_the_title() will output title only when it is in loop, otherwise you have to provide post id to display title.
get_the_title($post_id)
Related
I have a page-header that is getting copied over to all of my blog posts that I want to remove completely. I am removing it visually via CSS, but SEO crawlers are still picking it up via the tag.
I am using a standard wordpress them augmented with Elementor. Here is a screenshot of the SEO report.
And here is a screenshot of the actual HTML code
Let me know if any of you have any additional questions! Thank you for your help!
You can make a conditional statement that just outputs the title of the post if on single blog posts, so something like this
<div class="container clr page-header-inner">
<?php
// Return if page header is disabled
if ( oceanwp_has_page_header_heading() ) { ?>
<!-- check to see if single blog posts -->
<?php if (is_single()) : ?>
<h1><?php echo get_the_title(); ?></h1>
<!-- otherwise show the existing title format -->
<?php else: ?>
<<?php echo esc_attr( $heading ); ?> class="page-header-title clr"<?php oceanwp_schema_markup( 'headline' ); ?>><?php echo wp_kses_post( oceanwp_title() ); ?></<?php echo esc_attr( $heading ); ?>>
<?php endif; ?>
<?php get_template_part( 'partials/page-header-subheading' ); ?>
<?php } ?>
<?php if ( function_exists( 'oceanwp_breadcrumb_trail' ) ) {
oceanwp_breadcrumb_trail();
} ?>
</div><!-- .page-header-inner -->
you would have to replace the existing code
I am developing a separate website and for showing the blogs i am using the worpress.I have used following code to display blogs.It shows the textual contents properly but for video it just shows the player bar and not click able.
I have also checked themes index.php there is no the_excerpt.
When i check preview of the post using wordpress admin it shows the video properly.
can anyone help me resolve this?
here is my code..
<?php
global $more;
$posts = get_posts('category=3&numberposts=10&order=ASC&orderby=post_title');
foreach ($posts as $post) : setup_postdata( $post ); ?>
<?php $more = 1; ?>
<?php the_date(); echo "<br />"; ?>
<span style="color:#1C1644;font-size:1.3em !important;font-weight: bold;">
<?php the_title(); ?>
</span>
<div id="lol"><?php the_content(); ?>
</div>
<hr>
<?php
endforeach;
?>
Please try this
<?php
global $more;
$posts = get_posts('category=3&numberposts=10&order=ASC&orderby=post_title');
foreach ($posts as $post) :
setup_postdata( $post ); ?>
<?php $more = 1; ?>
<?php the_date(); echo "<br />"; ?>
<span style="color:#1C1644;font-size:1.3em !important;font-weight: bold;">
<?php echo the_title(); ?>
</span>
<div id="lol">
<?php echo the_content(); ?>
</div>
<hr>
<?php
endforeach;
?>
All you need to do to embed something into a post or page is to post the URL to it into your content area. Make sure that the URL is on its own line and not hyper-linked (clickable when viewing the post).
For example:
http://www.youtube.com/watch?v=dQw4w9WgXcQ
WordPress will automatically turn that into a YouTube embed when the post is viewed.
You can also optionally wrap the URL in the [embed] shortcode. It will accomplish the same effect, but does not require the URL to be on its own line.
It also allows you to set a maximum (but not fixed) width and height, like so:
[embed width="123" height="456"]http://www.youtube.com/watch?v=dQw4w9WgXcQ[/embed]
If WordPress fails to embed your URL you will get a hyper-link to the URL.
Use wp custom fields. Add video_embed custom field your post and add code.
<?php echo get_post_meta($post->ID, 'video_embed', true); ?>
Edit:
if(get_post_meta($post->ID, 'video_embed', true)){
echo get_post_meta($post->ID, 'video_embed', true);
}
else
{
the_content();
}
I want to show latest ten post of my security category with date and post title and the post thumbnail.
To show the pic I have faced with problem. According to this article
http://www.wpbeginner.com/beginners-guide/how-to-add-featured-image-or-post-thumbnails-in-wordpress/
when we want to showing the thumbnail first of all we should have to copy the following code to the function.php file
add_theme_support( 'post-thumbnails' );
and using the
<?php the_post_thumbnail(); ?>
To show pic of the post, I use this code into the loop but it doesn’t work. my code is here:
<?php query_posts('securitysoft=CATEGORYNAME&showposts=10');
while ( have_posts() ) : the_post(); ?>
<br/>
<?php
php the_post_thumbnail();
?>
<br/>
<?php the_time(__('j/F/ Y','kubrick')) ?>
<br/>
<?php the_title();?>
<?php endwhile; ?>
The main problem is that the picture does not show. To prove this I am taking post Id of the post that has thumbnail(292) like this :
<?php if ( has_post_thumbnail(292))
{
echo "<script type='text/javascript'>alert('yes')</script>";
has_post_thumbnail(292);
}
else
{
echo "<script type='text/javascript'>alert('no')</script>";
has_post_thumbnail(292);
}
?>
note:292 is the post id
The result of above code is no.
I have replaced php the_post_thumbnail(); with each one of following code but does not work:
get_the_post_thumbnail($post->ID);
echo get_the_post_thumbnail($post->ID);
get_the_post_thumbnail($post_id, 'thumbnail');
echo get_the_post_thumbnail($post_id, 'thumbnail');
<?php echo get_the_post_thumbnail($post_id, 'thumbnail', array('class' => 'alignleft')); ?>
And this is my function.php :
<?php
add_theme_support( 'post-thumbnails' );
if ( function_exists('register_sidebar') )
register_sidebar();
?>
do you set the feature image!! remember if you don't set the feature image. the image won't display. because this command that you have used only take the thumbnail. to set the feature image go to the feature image panel and click on the Set featured image link.
Ok so I am having issues with linking to next and previous posts...
Here is my code:
<?php get_header(); ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
...
<div id="project-prev"> <?php previous_post_link('Prev'); ?> </div>
<div id="project-next"> <?php next_post_link('Next'); ?> </div>]
...
<?php endwhile; // end of the loop. ?>
<?php endif; ?>
<?php get_footer(); ?>
I have read places that next/prev posts requires a 'new WP_Query' query, but have had no such luck. There is no next/prev link rendered out on my site, using the above.
As always appreciate solutions and pointers.
Many thanks
Have you tried following (according to Wordpress codex)
<?php next_post_link('<strong>%link</strong>'); ?>
<?php previous_post_link('<strong>%link</strong>'); ?>
In your divs ... :) If you still encouter problems, then just try something like:
<?php echo get_previous_posts_link('Prev'); ?>
<?php echo get_next_posts_link('Next'); ?>
Should work.
EDIT:
<div id="project-prev"><?php previous_post_link('%link', 'PREV'); ?></div>
<div id="project-next"><?php next_post_link('%link', 'NEXT'); ?></div>
First try and get the next and previous posts.
<?php
$previous_post_url = get_permalink(get_adjacent_post(false, '', true));
$next_post_url = get_permalink(get_adjacent_post(false, '', false));
?>
And then create to <a> tags and echo out the URLs we set above.
<?php if ( $previous_post_url != get_the_permalink() ) : ?>
Previous Project
<?php endif; ?>
<?php if ( $next_post_url != get_the_permalink() ) : ?>
Next Project
<?php endif; ?>
One reason that could make these links not to show is having the posts set as draft. Only published posts will make the previous and next post links render.
I am using the shortcode in the loop inside template file
and also using the lightbox form plugin.
<?php query_posts('showposts=9&post_type=packages') ?>
<?php while (have_posts()) :the_post(); ?>
<?php echo the_post_thumbnail(); ?>
...
...
<?php echo do_shortcode("[formlightbox text='Book Now' title=the_title][contact-form-7 id='383' title='Booking Form'][/formlightbox]"); ?>
<?php endwhile; ?>
Please note that in the shorcode there is title=the_title and it is not appened to the anchor tag.
But when I use title='hello'or something else it gets appended to the anchor tag.
I want current post's title should get appened to the rendered anchor tag via shortcode.
please help me
Break the string and use the string concatenation operator to combine the function into your string.
<?php echo do_shortcode("[formlightbox text='Book Now' title='" . get_the_title() . "'][contact-form-7 id='383' title='Booking Form'][/formlightbox]"); ?>
Update
This should use the get_the_title() as opposed to the_title() which echos the title.