I want to hide the featured image in the post page, but not on the home page.
I had a look at the other posts about this same problem, but they didn't work for me, so I will appreciate your help.
Here is my single.php
<div id="primary" class="full-width-page">
<main id="main" class="site-main" role="main">
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'content', 'single' ); ?>
<?php tesseract_post_nav(); ?>
<?php
// 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;
?>
<?php endwhile; // end of the loop. ?>
</main><!-- #main -->
</div><!-- #primary -->
Add this to your functions.php (prefer child-theme), and that is it. It works on any theme, and you don't need to touch the ugly HTML templates.
function wordpress_hide_feature_image( $html, $post_id, $post_image_id ) {
return is_single() ? '' : $html;
}
// add the filter
add_filter( 'post_thumbnail_html', 'wordpress_hide_feature_image', 10, 3);
References:
https://helloacm.com/how-to-hide-feature-image-of-posts-in-wordpress/
Please, write what theme you are using.
According to what you wrote you have to edit content-single.php.
Search for the line like this:
get_the_post_thumbnail( $post->ID, ... );
or
the_post_thumbnail();
And remove or comment it.
The code is in the template part. You will find the feature image function in the file named 'content-single'.
There are two ways to disable:
1. Find the code.
Remove or comment the function in your content-single template file:
<div class="thumbnail">
<?php
// Comment out this function:
echo get_the_post_thumbnail( $post_id, $size, $attr );
// or:
the_post_thumbnail();
// Or you can remove this <div> entirely
?>
</div>
2. CSS method.
Find the appropriate class of the image div and add a display none condition in your style sheet.
.thumbnail{display:none}
If you can share the site url I can answer more clearly.
How to remove featured image background from Tesseract Theme single posts:
1.- First of all make a copy from the original content-single.php file.
2.- Edit content-single.php with a plain text editor.
3.- If the original file is like this:
<?php
/**
* #package Tesseract
*/
?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<?php if ( has_post_thumbnail() && 'post' == get_post_type() ) {
$thumbnail = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'tesseract-large' ); ?>
<div class="entry-background" style="background-image: url(<?php echo esc_url( $thumbnail[0] ); ?>)">
<header class="entry-header">
<?php the_title( '<h1 class="entry-title">', '</h1>' ); ?>
</header><!-- .entry-header -->
</div><!-- .entry-background -->
<?php } else { ?>
<header class="entry-header">
<?php the_title( '<h1 class="entry-title">', '</h1>' ); ?>
</header><!-- .entry-header -->
<?php } ?>
<div class="entry-content">
<div class="entry-meta">
<?php tesseract_posted_on(); ?>
</div><!-- .entry-meta -->
<?php the_content(); ?>
<?php
wp_link_pages( array(
'before' => '<div class="page-links">' . __( 'Pages:', 'tesseract' ),
'after' => '</div>',
) );
?>
</div><!-- .entry-content -->
</article><!-- #post-## -->
( Source: github.com/Conutant/TESSERACT/blob/Master_Branch/content-single.php )
4.- To remove the featured image background, change it to this:
<?php
/**
* #package Tesseract
*/
?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<header class="entry-header">
<?php the_title( '<h1 class="entry-title">', '</h1>' ); ?>
</header><!-- .entry-header -->
<div class="entry-content">
<div class="entry-meta">
<?php tesseract_posted_on(); ?>
</div><!-- .entry-meta -->
<?php the_content(); ?>
<?php
wp_link_pages( array(
'before' => '<div class="page-links">' . __( 'Pages:', 'tesseract' ),
'after' => '</div>',
) );
?>
</div><!-- .entry-content -->
</article><!-- #post-## -->
5.- Remember that all changes will be overwritten when you update the theme to a new version. A good option to avoid this is to create a Child Theme, the recommended way of modifying an existing theme. More information can be found at: https://codex.wordpress.org/Child_Themes
6.- Test it and let me know if you have any problem.
Regards.
In your code there is one line
<?php get_template_part( 'content', 'single' ); ?>
which means it calls content.php file of your current theme. go to that file and comment following code
<?php if ( has_post_thumbnail() && ! post_password_required() && ! is_attachment() ) : ?> <div class="entry-thumbnail"> <?php the_post_thumbnail(); ?> </div> <?php endif; ?>
But note that it removes thumbnail everywhere when content.php file calls, so better idea is create custom single.php file. For that you need to copy in single.php file and rename with your post name.
for example if you use post for add your content then rename with single-post.php or if you use custom post type like news then rename with single-news.php.
After that open this file and remove this code
<?php get_template_part( 'content', 'single' ); ?>
from file and goto the content.php file and copy your require code which you want to display and paste in your new file.
Related
I would like to hide featured images from all posts. I tried Hide feautered image plug-in. Also some formulas from similar posts like:
.blog .entry-thumbnail { display: none; }
but it doesn't work.
My content single file is bellow:
<?php
/**
* #package Tesseract
*/
?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<?php $featImg_pos = get_theme_mod('tesseract_blog_featimg_pos');
if ( has_post_thumbnail() && ( !$featImg_pos || ( $featImg_pos == 'above' ) ) )
tesseract_output_featimg_blog(); ?>
<?php //if ( my_theme_show_page_header() ) : ?>
<header class="entry-header">
<?php the_title( '<div id="blogpost_title"><h1 class="entry-title">', '</h1></div>' ); ?>
<?php
$postDate = get_theme_mod('tesseract_blog_date');
if ( $postDate == 'showdate' ) { ?>
<span><i class="fa fa-calendar" aria-hidden="true"></i><?php the_time('F j, Y'); ?></span>
<?php } ?>
<?php
$postAuthor = get_theme_mod('tesseract_blog_author');
if ( $postAuthor == 'showauthor' ) { ?>
<span><i class="fa fa-user" aria-hidden="true"></i><?php the_author(); ?></span>
<?php } ?>
<?php
$mypostComment = get_theme_mod('tesseract_blog_comments');
if ( ( $mypostComment == 'showcomment' ) && ( comments_open() ) ) { ?>
<span><i class="fa fa-comments-o" aria-hidden="true"></i><?php //comments_number('(No Comments)', '(1 Comment)', '(% Comments)' );?><?php comments_popup_link(
'No comments exist', '1 comment', '% comments'); ?></span>
<?php }
?>
</header><!-- .entry-header -->
<?php //endif; ?>
<?php if ( has_post_thumbnail() && ( $featImg_pos == 'below' ) )
tesseract_output_featimg_blog(); ?>
<div class="entry-content">
<div class="entry-meta">
<?php tesseract_posted_on(); ?>
</div><!-- .entry-meta -->
<?php if ( has_post_thumbnail() && ( $featImg_pos == 'left' ) ) { ?>
<div class="myleft">
<?php tesseract_output_featimg_blog(); ?>
<?php the_content(); ?>
<?php the_tags()?>
</div>
<?php } elseif ( has_post_thumbnail() && ( $featImg_pos == 'right' ) ){ ?>
<div class="myright">
<?php tesseract_output_featimg_blog(); ?>
<?php the_content(); ?>
<?php the_tags()?>
</div>
<?php } else { ?>
<?php the_content(); ?>
<?php } ?>
<?php
wp_link_pages( array(
'before' => '<div class="page-links">' . __( 'Pages:', 'tesseract' ),
'after' => '</div>',
) );
?>
</div><!-- .entry-content -->
</article><!-- #post-## -->
It is quite complicated, so do you guys know how to solve this?
Try commenting out the lines that say tesseract_output_featimg_blog();, so this:
<?php tesseract_output_featimg_blog(); ?>
becomes this:
<?php /* tesseract_output_featimg_blog(); */ ?>
I see 4 occurrences, and it looks like they're related to different featured image positions in the theme.
As a side note, changing your theme files isn't recommended unless you're doing it within a child theme.
Some themes give their users an option to choose if they really want to use a featured image for their post. If you have just started with your blog/website I would rather suggest to search for one such wordpress theme.
Also, in agreement with #Jonathan I would also suggest NOT to play around with your theme files. I tried changing theme files a couple of days ago, for the same reason as you have, and ultimately ended up breaking my theme code. As a result, I was unable to login to my blog. So, better be careful.
I'm creating a home page that will pull in different posts to display them in a custom format. I can get most of the information I want but I haven't been able to to get the featured image for any of them. I set a featured image for all three posts and I'm using my own theme that's a child of the twentysixteen theme. I get has_post_thumbnail returning false on all of them even though I've uploaded a featured image for each post. I only have this on local right now but here's the code I'm using to get the posts:
<?php
global $post;
$myposts = get_posts('numberposts=3&category=1');
foreach($myposts as $post) :
setup_postdata( $post );?>
<div class="article-box">
<div class="article-box-image">
<?php if (has_post_thumbnail($post->ID)) { ?>
has one
<?php } else { ?>
not working
<?php } ?>
<img src="<?php the_post_thumbnail_url(); ?>">
</div>
<div class="article-box-title">
<?php the_title(); ?>
</div>
<div class="article-box-excerpt">
<?php the_excerpt(); ?>
</div>
<div class="article-box-edit">
<?php edit_post_link('Edit'); ?>
</div>
</div>
<?php endforeach; ?>
Use a wp query:
<?php
$args = array(
'cat' => '1',
'posts_per_page' => '3',
);
$query = new WP_Query( $args );
if ( $query->have_posts() ) : ?>
<?php while ( $query->have_posts() ) : $query->the_post(); ?>
<div class="article-box">
<div class="article-box-image">
<?php //check for thumbnail
if ( has_post_thumbnail() ) {
the_post_thumbnail();
}
else {
//Give up and start new life picking apples
} ?>
</div>
<div class="article-box-title">
<?php the_title(); ?>
</div>
<div class="article-box-excerpt">
<?php the_excerpt(); ?>
</div>
<div class="article-box-edit">
<?php edit_post_link('Edit'); ?>
</div>
</div>
<?php endwhile; ?>
<?php endif; ?>
<?php wp_reset_postdata(); ?>
And then double check that thumbnails are supported in your theme's functions.php
add_theme_support( 'post-thumbnails' );
I finally realized that the "preview" post parameters were the problem. I was viewing the page through preview page. I don't know why images won't work in preview mode but apparently it won't.
I have integrated a HTML Template into Wordpress theme. In, menu area there is a menu called Blog. On click of that menu I want to show all the posts. On clicking some particular posts title one should go to the single post`s page. On that page there should be comments shown which are being posted earlier by some one as well as the comment form through which one can comment on that post.
Below is my blog.php code
<?php
/*
Template Name: Blog
*/
?>
<?php get_header(); ?>
<div id="inner_contant">
<div id="all_post">
<?php
$myposts = get_posts('');
foreach($myposts as $post) :
setup_postdata($post);
?>
<h2><?php the_title(); ?></h2>
<div class="author">Posted by <?php the_author(); ?></div>
<div class="post_excerpt"><?php the_excerpt(); ?></div>
<?php endforeach; wp_reset_postdata(); ?>
</div>
</div>
<?php get_footer(); ?>
Below is my single.php code
<?php
/*
* The template for displaying all single posts and attachments
*/
?>
<?php get_header(); ?>
<div id="single_post_wrap">
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<h2><?php the_title(); ?></h2>
<div class="time_and_author"><?php the_time('F jS, Y') ?> by <?php the_author() ?></div>
<div class="post_content"><?php the_content(); ?></div>
<p>Posted in <?php the_category(', ') ?> | <?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?></p>
<?php endwhile; endif; ?>
<?php foreach (get_comments() as $comment): ?>
<div><?php echo $comment->comment_author; ?> said: "<?php echo $comment->comment_content; ?>".</div>
<?php endforeach; ?>
<?php comments_template(); ?>
</div>
</div>
<?php get_footer(); ?>
Below is my comments.php code
<?php $comment_args = array(
'comment_notes_after' => '',
'title_reply' => 'Have something to say?'
) ?>
<?php comment_form($comment_args); ?>
I want to add some styling to that comment form. I have tried every thing but not worked for me. Thanks in advance for those who will help me.
WordPress' comment_form function prints a form with id 'commentform'. So you can use CSS to style this form.
form#commentform {
// your styles.
}
form#commentform input {
// your styles for inputs
}
/* default class of submit button is 'submit'. For changing it: add a
* key=>value to comment_form args like
* 'class_submit' => 'your_submit_class'
*/
form#commentform .submit {
// your submit button styles.
}
Also, you can change ID of comment form like this:
<?php $comment_args = array(
'comment_notes_after' => '',
'title_reply' => 'Have something to say?',
'id_form' => 'myAwesomeCommentForm'
) ?>
<?php comment_form($comment_args); ?>
Below is my wordpress loop and i have tired to take-off the Page title but its not happning.
Please suggest me the correct loop.
<div class="single-full-width-container single-page-header-container">
<header class="container">
<?php the_title( '<h1 class="single-page-heading">', '</h1>' ); ?>
<ul class="single-page-breadcrumbs">
<?php
if(function_exists('bcn_display') && !is_front_page())
{
bcn_display();
}
?>
</ul>
</header>
</div>
<div class="container">
<div class="row">
<main role="main" class="shortcode-container span12">
<div class="row">
<div class="span12">
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'content', 'page' ); ?>
<?php endwhile; // end of the loop. ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php if ( has_post_thumbnail() && ! post_password_required() ) : ?>
<div class="entry-thumbnail">
<?php the_post_thumbnail(); ?>
</div>
<?php endif; ?>
<div class="entry-content">
<?php the_content(); ?>
<?php wp_link_pages( array( 'before' => '<div class="page-links"><span class="page-links-title">' . __( 'Pages:', 'twentythirteen' ) . '</span>', 'after' => '</div>', 'link_before' => '<span>', 'link_after' => '</span>' ) ); ?>
</div>
<!-- .entry-content -->
<?php endwhile; ?>
</div>
</div>
</main>
</div>
I have tried with other loop without the "title" tag but its still coming at top.
<?php
if ( have_posts() ) {
while ( have_posts() ) {
the_post();
//
// Post Content here
//
} // end while
} // end if
?>
Remove the line
<?php the_title( '<h1 class="single-page-heading">', '</h1>' ); ?>
I think you're not editing the proper file.
There is a line in your file:
<?php get_template_part( 'content', 'page' ); ?>
This part is intended to import the content-page.php file as far as I know. Maybe this file puts the title on the top of the article. Try to edit that file if you find anything like that. If there is no content-page.php it falls back to import content.php.
(For more details check this: http://codex.wordpress.org/Function_Reference/get_template_part )
If I'm right the part of the file you cited above makes no effect after the second appearance of this line:
<?php while ( have_posts() ) : the_post(); ?>
Because the first appearance looped through the whole collection of the posts so the have_posts() function returns false after that. So the whole section until <?php endwhile; ?> (lines 22-33) is always skipped.
I hope I was right and could help you with your task :)
I'm currently working on integrating wordpress with my website, but I'm hitting a wall here.
I need the initial blog page(basically just the index.php of WP) to pick up the <!--more--> quicktags, but I can't seem to get it to work.
I've followed the WP Codex, but that didn't help me at all.
So here's part of the template file: content.php
<?php if ( is_search() ) : // Only display Excerpts for Search ?>
<div class="entry-summary">
<?php
if ( has_post_thumbnail() ) {
the_post_thumbnail('thumbnail');
}
the_excerpt();
?>
</div><!-- .entry-summary -->
<?php else : ?>
<div class="entry-content">
<div class="bthumb2">
<?php
if ( has_post_thumbnail() ) {
the_post_thumbnail(array(220, 130));
}
?>
</div>
<?php
the_content("READ MORE");
?>
<?php
wp_link_pages( array(
'before' => '<div class="page-links">' . __( 'Pages:', 'tinfoilhats' ),
'after' => '</div>',
) );
?>
</div><!-- .entry-content -->
<?php endif; ?>
But it just keeps displaying the <!--more--> tag in the posts once I load the page.
I've tried it with the global $more thing, but that didn't work for me.
<?php while ( have_posts() ) : the_post(); ?>
<?php
global $more;
$more = 0;
get_template_part( 'content', get_post_format() );
?>
<?php endwhile; ?>
So what am I doing wrong?
Your global $more example looks good, and almost follows the recommendation on the documentation page applicable (the global $more line itself is supposed to be outside "the loop" - before while ( have_posts() ) - leaving the next line where it is.)
However, I couldn't get this to work on my own blog (using a a child theme of Coraline) until I moved both lines to before "the loop". Starting with your code, I'd suggest something like this:
<?php
global $more;
$more = 0;
?>
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'content', get_post_format() ); ?>
<?php endwhile; ?>