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.
Related
I'm working on a new Wordpress site and am trying to achieve something specific. I'd like to do a query_post and if there is only 1 post available, display that information in a specific div class, otherwise use a different class. Here is a simplified version of the code I am currently using. The one I will end up using, actually has additional query_posts within this:
<?php query_posts('post_type=events&showposts=-1'); ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<?php
$type = get_field('event_type');
if( $type && in_array('public', $type) ): ?>
<a href="<?php the_permalink(); ?>">
<div id="event" class="public secondary left">
<?php else: ?>
<a href="mailto:johnsmith#gmail.com?subject=<?php echo the_field('event_date'); ?> - <?php the_title(); ?> Event Inquiry">
<div id="event" class="private secondary left">
<?php endif; ?>
<?php else: ?>
<?php
$type = get_field('event_type');
if( $type && in_array('public', $type) ): ?>
<a href="<?php the_permalink(); ?>">
<div id="event" class="public secondary right">
<?php else: ?>
<a href="mailto:johnsmith#gmail.com?subject=<?php echo the_field('event_date'); ?> - <?php the_title(); ?> Event Inquiry">
<div id="event" class="private secondary right">
<?php endif; ?>
<?php endif; ?>
<?php wp_reset_query(); ?>
I hope this makes sense..
You can check the global query after query_posts() like this before you run through the posts and display them:
<?php query_posts( 'post_type=events&showposts=-1' );
global $wp_query;
$classes = array( 'secondary' );
if( $wp_query->post_count == 1 ) :
$classes[] = 'left';
else :
$classes[] = 'right';
endif; ?>
With the above, your code can be shortened to something like this:
<?php if ( have_posts() ) :
while ( have_posts() ) : the_post();
$type = get_field( 'event_type' );
if ( $type && in_array( 'public', $type ) ) :
$classes[] = 'public';
$action = get_permalink();
else :
$classes[] = 'private';
$action = 'mailto:johnsmith#gmail.com';
endif; ?>
<!-- Output HTML -->
<a href="<?php echo $action; ?>">
<div id="event" class="<?php echo join( ' ', $classes ); ?>">
<?php endwhile;
endif; ?>
I have the code to display the latest posts on my website, but I wonder if there is a way to make a list of the latest posts, displaying only one post per category. Let's say I have 7 categories, so only 7 posts will be displayed on the page. What should I do?
<?php if ( ! is_single() ) { ?>
<div class="post-container">
<?php } ?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<?php
//Post Title code
//Post Thumbnail code
//Post Content / Excerpt code
//Post Meta code
</article> <!-- /post -->
<?php if ( ! is_single() ) { ?>
</div>
<?php
<?php } ?>
It's very easy to add latest post from each category.
First of all get all the categories of blog by using below code:
$categories = get_categories();
Then use foreach ( $categories as $category ) {} to tell WordPress to run through each of these categories in turn and run the code inside the braces.
Now you need to define the arguments for your query. Inside the braces, add this:
$args = array(
'cat' => $category->term_id,
'post_type' => 'post',
'posts_per_page' => '1',
);
Next, insert your query, using the WP_Query class:
$query = new WP_Query( $args );
if ( $query->have_posts() ) { ?>
<section class="<?php echo $category->name; ?> listing">
<h2>Latest in <?php echo $category->name; ?>:</h2>
<?php while ( $query->have_posts() ) {
$query->the_post();
?>
<article id="post-<?php the_ID(); ?>" <?php post_class( 'category-listing' ); ?>>
<?php if ( has_post_thumbnail() ) { ?>
<a href="<?php the_permalink(); ?>">
<?php the_post_thumbnail( 'thumbnail' ); ?>
</a>
<?php } ?>
<h3 class="entry-title">
<a href="<?php the_permalink(); ?>">
<?php the_title(); ?>
</a>
</h3>
<?php the_excerpt( __( 'Continue Reading <span class="meta-nav">→</span>', 'twentyfourteen' ) ); ?>
</article>
<?php } // end while ?>
</section>
<?php } // end if
// Use reset to restore original query.
wp_reset_postdata();
This will display each category posts in your home page. Please try to use it and let me know if you have any issue.
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.
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 having hard time trying to use teasers post in my wordpress theme (based on 960gs), as you can see here http://img17.imageshack.us/img17/794/schermata20110420a15045.png what I got till now is one "featured" post and three teasers post with thumbnails that will probably be six (so it'll have seven posts displaied in the homepage). The problem is that to do so I have to assign a class "grid_2 alpha" to the teasers post and I don't know how to assign this class to just the first teaser on the left, lefting the other ones with no alpha or omega class and putting the omega class to just the last teaser post (the seventh).
If can help, here's the code I'm using for the loop:
<?php $firstClass = 'firstpost'; ?>
<?php /* Start loop */ ?>
<?php while (have_posts()) : the_post(); ?>
<?php if (function_exists('yoast_breadcrumb')) { if (is_page() && $post->post_parent) { yoast_breadcrumb('<p id="breadcrumbs">','</p>'); } } ?>
<div class="post <?php echo $firstClass; ?>">
<?php $firstClass = 'grid_2 alpha'; ?>
<img src="<?php echo get_post_meta($post->ID, "Thumbnail", true);?>" width="140" height="100" style="padding-bottom:20px;" />
<h1><?php the_title(); ?></h1>
<?php the_content(); ?>
<?php wp_link_pages(array('before' => '<nav id="page-nav"><p>' . __('Pages:', 'roots'), 'after' => '</p></nav>' )); ?>
</div>
<?php endwhile; // End the loop ?>
also I would like to know how I can add some text above the teaser section under the first featured post. Sorry for the too many questions and for my bad english, as you can understand I'm not a developer but I searched for one week and couldn't find anything helpful for my problems. Thanks in advance for any help, I really appreciate it.
<?php $count = 0; ?>
<?php /* Start loop */ ?>
<?php while (have_posts()) : the_post(); ?>
<?php $count++; ?>
<?php if ($count == 1):
$class = "firstpost';
elseif ($count == 2):
$class = "grid_2 alpha";
elseif ($count == $wp_query->post_count):
$class = "grid_2 omega";
else:
$class = "grid_2";
endif;
?>
<?php if (function_exists('yoast_breadcrumb')) { if (is_page() && $post->post_parent) { yoast_breadcrumb('<p id="breadcrumbs">','</p>'); } } ?>
<div class="post <?php echo $class; ?>">
<img src="<?php echo get_post_meta($post->ID, "Thumbnail", true);?>" style="padding-bottom:20px;" />
<h1><?php the_title(); ?></h1>
<?php the_content(); ?>
<?php wp_link_pages(array('before' => '<nav id="page-nav"><p>' . __('Pages:', 'roots'), 'after' => '</p></nav>' )); ?>
</div>
<?php endwhile; // End the loop ?>