showing the ten post thumbnail - wordpress

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.

Related

Remove Page Header from Blog Posts

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

wordpress the_content not showing video

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();
}

WordPress, custom single page content

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)

WordPress - Display Custom Field on Post - Pull Post Title and URL

Okay, I have the code pulling the custom fields URL and title of the url. Now I can't seem to get it to show the second featured blog. Here is the working code.
<?php $related = get_post_meta($post->ID, "Featured-Blog", $single=true);
$related=explode(',',$related);
$args = array_merge( array('post__in' => $related, $wp_query->query ) );
query_posts($args);
if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<div id="<?php the_ID(); ?>">
<p class="caption"><?php the_title(); ?></p>
</div>
<?php endwhile; else: ?>
<p>no related</p>
<?php endif; wp_reset_query();?>
This code example here produces two results, which is almost what I want. Which is caused by the foreach I believe. I do not want to use the code below, but I need to find a way to add the foreach I think to get it to list all of the featured-blogs if I have more than one.
<?php
$custom_fields = get_post_custom($post_id); //Current post id
$my_custom_field = $custom_fields['Featured-Blog']; //key name
foreach ( $my_custom_field as $key => $url )
echo $key ="<a href='".$url."'>TEST</a><br /><br /><br/>";
?>
Here is a screenshot showing my Custom Fields if it helps at all, and the results they are showing on the site. screenshot
Example 1: You are using the actual word 'TITLE' for the link use <?php the_title() ?> instead
Example 2: You are not building link at all. Your href attribute is empty. Cut echo $featured_blog1 and paste it to href attribute to end up like so:
Example 3: Same as 2
Also you can delete dose instructions or put them inside <?php ?> code so they are not visible to viewers.
Hope this helps.
If you need more info just ask. ;)

How can I display only the thumbnail and title of a post in WordPress?

How can I display only the thumbnail and title of a post in WordPress like here: http://themes.premiumpixels.com/?theme=artiste
P.S. I'm not advertising anything, I just posted a question because I have no idea how to do something like that.
// From your loop just remove the_content() or the_excerpt() call
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<!-- do stuff ... -->
if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.
the_post_thumbnail();
}
post_title();// to display the post title
<?php endwhile; ?>
<?php endif; ?>
You need to do this for the image:
http://www.wpbeginner.com/wp-themes/how-to-add-post-thumbnails-in-wordpress/
And you need to do this for the little text:
Add this in function.php:
add_post_type_support( 'page', 'excerpt' );
then add this below your post_thumbnail in your template as the link demonstrate you:
<?php the_exceprt(); ?>

Resources