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 :)
Related
I am a new of wordpress. I have a problem with pagination when I click to the next post it shows "not found". I installed the plugin wp pagenavi, and I put code in my blog post . It shows the pagination, but I have a problem with the link to the next post. Example when I click to the next post it is show
Something went Wrong!
404
-->
You can see at: http://westecmedia.com/events/
And this is my code in event-page.php:
<div id="content-events">
<div id="head-event"><h3>EVENTS</h3></div>
<div id="main-event">
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<?php the_content(); ?>
<?php endwhile; else: endif; ?>
<?php query_posts('category_name='.get_the_title().'&post_status=publish,future');?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<div id="part-event">
<div id="entry-thumbnail">
<?php the_post_thumbnail(); ?>
</div>
<div id="event-dess">
<h2><?php the_title(); ?></h2>
<p>
<?php
$content = get_the_content();
$content = strip_tags($content);
echo substr($content, 0, 300);
?>
</p>
<div id="read-more">Read More</div>
</div>
</div>
<div id="line-bottom"></div>
<?php endwhile; else: endif; ?>
<?php wp_pagenavi(); ?>
</div>
</div>
<?php get_footer(); ?>
Help me please ?
Maybe you missed the object here. You can try the code below:
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array(
'posts_per_page' => get_option('posts_per_page'),
'paged' => $paged,
'category_name'=>get_the_title(),
'post_status'=> array('publish', 'future')
);
query_posts($args);
instead:
<?php query_posts('category_name='.get_the_title().'&post_status=publish,future');?>
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.
I have to add some simple HTML to the homepage of a client's WordPress website. At first, I added the code to the header.php and everything looked and worked how it should; but, then I realised that it was showing on every page when I just need it on the home page.
So, I tried adding the same HTML after the get_header in the homepage.php and then in the index.php but nothing shows at all when I add the code to these pages.
No matter where I put the HTML in homepage.php or index.php it will not show. I'm new to WordPress as you have no doubt gathered.
Do I need to make a template or use some code to introduce the HTML in either of these two pages? Why does it show in the header.php?
I tried using with no joy:
if ( is_home() ) {
The home page code is here if it helps:
<?php
/**
Template Name: Homepage
*
*/
get_header(); ?>
<?php $general_options = get_option( 'meanthemes_theme_general_options' ); ?>
<?php $content_options = get_option ( 'meanthemes_theme_content_options' ); ?>
<?php if( isset( $general_options[ 'hide_slider' ] ) ) {
// do nothing
} else {
?>
<section class="hero flexslider">
<article class="wrapper">
<div class="flex-container"></div>
<ul class="slides">
<?php
$bannerPortfolio = $general_options[ 'swap_slider' ];
if(!$bannerPortfolio) {
query_posts( array ( 'posts_per_page' => 3 ) );
while ( have_posts() ) : the_post();
?>
<li>
<h2>
<?php the_title(); ?>
</h2>
<div>
<?php echo excerpt_clip(get_the_excerpt(), '28'); ?> <?php _e('[...]','meanthemes'); ?>
</div>
<time class="time" datetime="<?php the_time('Y-m-d', '', ''); ?>"><?php the_time('jS M Y') ?></time>
</li>
<?php endwhile; wp_reset_query(); ?>
<?php
} else {
?>
<?php
query_posts( array( 'post_type' => 'portfolio', 'order' => 'desc', 'posts_per_page' => '3' ) );
?>
<?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
<li>
<hgroup>
<h2>
<?php the_title(); ?>
</h2>
<div>
<?php echo excerpt_clip(get_the_excerpt(), '48'); ?> <?php _e('[...]','meanthemes'); ?></div>
</hgroup>
</li>
<?php endwhile; ?>
<?php } ?>
</ul>
</article><!-- / article.wrapper -->
</section>
<script>
jQuery(window).load(function() {
jQuery('.flexslider').flexslider({
animation: "fade", // animation type fade or slide
slideshowSpeed: <?php echo sanitize_text_field( $general_options ['slider_timer'] ); ?>, // sections between transitions
directionNav: true, // show previous and back
controlNav: false,
controlsContainer: '.flex-container'
});
});
</script>
<?php } ?>
<?php if( $general_options[ 'show_portfolio' ] ) { ?>
<section class="wrapper portfolio">
<article>
<hgroup>
<h2><?php echo balanceTags( $content_options['we_do'] ); ?></h2>
</hgroup>
<div><?php echo balanceTags( $content_options['we_do_summary'] ); ?></div>
</article>
<?php
query_posts( array( 'post_type' => 'portfolio', 'posts_per_page' => '4', 'orderby' => 'date', 'order' => 'desc' ) );
?>
<?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
<aside>
<?php the_post_thumbnail('portfolio-thumb'); ?>
<hgroup>
<h3><?php the_title(); ?></h3>
</hgroup>
<div><?php echo excerpt_clip(get_the_excerpt(), '14'); ?><?php _e('[...]','meanthemes'); ?></div>
</aside>
<?php endwhile; wp_reset_query(); ?>
</section>
<?php } ?>
<script>
jQuery(document).ready(function() {
jQuery('body').addClass("home");
});
</script>
<?php get_footer(); ?>
Howlin's example should work. Another solution is to create a front-page.php in the theme-directory, copy the content from the page.php to it, and add your specific HTML-Code for the homepage (frontpage).
Visit http://codex.wordpress.org/Template_Hierarchy to understand which template is invoked in which case.
Visit http://codex.wordpress.org/Conditional_Tags for Conditional Tags, which you can use e.g. in theheader.php
You might need to try is_front_page instead.
if(is_front_page()){
is_home works if you have blog posts displaying on the homepage and is_front_page if the homepage is set as a static page.
i have custom post type events. i want to display content from single post and using single-events.php .
The code in single-events.php is
<?php get_header(); ?>
<?php $args = array( 'post_type' => 'events',
);
$loop = new WP_Query( $args );
if($loop->have_posts()):while ( $loop->have_posts() ) : $loop->the_post(); ?>
<?php the_content( ); ?>
<?php endwhile;endif; ?>
<?php get_footer(); ?>
But its displaying the content from all of the posts of custom type- 'events': how do i display the post from just single post
The events post object should already be in $wp_query - you don't need to reinitialise it. Just process it with the standard WordPress loop. Something like (untested):
<?php get_header();
if(have_posts()):while ( have_posts() ) : the_post();
the_content( );
endwhile;endif;
get_footer(); ?>
List and single event for same file call.
see the step:
you can change structure for single event so go hear
<?php
/**
* Template Name: Event page
*/
get_header(); ?>
<div id="main-content" class="main-content">
<div id="primary" class="content-area">
<div id="content" class="site-content" role="main">
<div class="page_content">
<div class="content_wrapper">
<?php
while ( have_posts() ) : the_post();
get_template_part( 'content', 'page' );
endwhile;
?>
</div>
</div>
</div><!-- #content -->
</div><!-- #primary -->
</div><!-- #main-content -->
<?php
get_footer();
if(get_post_type()=='tribe_events' && is_single() ) {
while ( have_posts() ) : the_post();
get_template_part( 'content', get_post_format() );
endwhile;
} else {
//for list code
}
First time creating/implementing custom post types in Thesis, not first time using custom post types.
I used the Reed Write plugin to create the custom post types. The site is using Thesis 1.8.5.
On the following page (http://www.snyderleadership.com/press-releases/) I have the main content getting dropped in with the contents of the custom post type after it.
I used the custom_functions.php file to create a custom page template and call the db for the contents of the custom post type. Here is my code:
/* CUSTOM PRESS RELEASE TEMPLATE - ADDED by BRETT ATKIN */
function press_releases_page() {
if (is_page('press-releases') || is_page('583')) { ?>
<div id="content">
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<div class="post_box">
<div class="headline_area"><h1><?php the_title(); ?></h1></div>
<div class="format_text">
<?php the_content(); ?>
<?php endwhile; ?>
<?php endif ?>
<?php
$original_query = $wp_query;
$wp_query = null;
$args = array (
'post_type' => 'press-release',
'post_status' => 'publish',
'posts_per_page' => -1,
'orderby' => 'date',
'order' => 'DESC'
);
$wp_query = new WP_Query($args);
?>
<div id="press-releases">
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<div id="press-wrapper">
<div id="press-image">
<?php echo wp_get_attachment_image(get_post_meta($post->ID, 'release_image', true)); ?>
</div><!-- end press-image div -->
<div id="press-information">
<p class="press-date"><?php echo get_post_meta($post->ID, 'release_date', true); ?></p>
<p class="press-link"><?php echo get_post_meta($post->ID, 'release_title', true); ?></p>
<p class="press-author"><?php echo get_post_meta($post->ID, 'release_author', true); ?></p>
</div><!-- end press-information div -->
<div style="clear:both;"></div>
</div><!-- end press-wrapper div -->
<?php endwhile; endif; wp_reset_postdata(); ?>
</div><!-- end press-releases div -->
</div>
</div>
</div><!-- end content -->
<?php echo thesis_sidebars(); ?>
<?php } }
add_action('thesis_hook_custom_template', 'press_releases_page');
It seems like everything is working correctly, just not pulling in the data for the custom post type.
Having done this on other sites (using custom themes), I'm not sure if I did something wrong here or if it is a Thesis issue.
Any help would be great.
Thanks
Brett
Here is the final working code. Thanks to the help from of a local WP Guru friend and maiorano84. We didn't figure out the cause, but we did fine a solution.
function press_releases_page() {
if (is_page('press-releases') || is_page('583')) { ?>
<div id="content">
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<div class="post_box">
<div class="headline_area"><h1><?php the_title(); ?></h1></div>
<div class="format_text">
<?php the_content(); ?>
<?php endwhile; ?>
<?php endif ?>
<?php
$original_query = $wp_query;
$wp_query = null;
$args = array (
'post_type' => 'press-release',
'post_status' => 'publish',
'posts_per_page' => -1,
'orderby' => 'date',
'order' => 'DESC'
);
$wp_query = new WP_Query($args);
?>
<div id="press-releases">
<?php if ( $wp_query->have_posts() ) : while ( $wp_query->have_posts() ) : $wp_query->the_post(); ?>
<?php $results = get_post_custom(); ?>
<div id="press-wrapper">
<div id="press-image"><?php echo wp_get_attachment_image($results['release_image'][0] ); ?></div><!-- end press-image div -->
<div id="press-information">
<p class="press-date"><?php echo $results['release_date'][0] ?></p>
<p class="press-link"><?php echo $results['release_title'][0] ?></p>
<p class="press-author"><?php echo $results['release_author'][0] ?></p>
</div><!-- end press-information div -->
<div style="clear:both;"></div>
</div><!-- end press-wrapper div -->
<?php endwhile; endif; wp_reset_query(); wp_reset_postdata(); ?>
</div><!-- end press-releases div -->
</div>
</div>
</div><!-- end content -->
<?php echo thesis_sidebars(); ?>
<?php } }
remove_action('thesis_hook_custom_template', 'thesis_custom_template_sample');
add_action('thesis_hook_custom_template', 'press_releases_page');
Try changing this:
<div id="press-releases">
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<div id="press-wrapper">
To this:
<div id="press-releases">
<?php if ( $wp_query->have_posts() ) : while ( $wp_query->have_posts() ) : $wp_query->the_post(); ?>
<div id="press-wrapper">
UPDATE:
The only other thing I can see is that you're not resetting your post data, and that the $wp_query variable is actually a Wordpress Global. Try using the reset functions and changing your WP_Query instance name like this:
<?php
wp_reset_query();
wp_reset_postdata();
$args = array (
'post_type' => 'press-release',
'post_status' => 'publish',
'posts_per_page' => -1,
'orderby' => 'date',
'order' => 'DESC'
);
$query = new WP_Query($args);
?>
<div id="press-releases">
<?php if ( $query->have_posts() ) : while ( $query->have_posts() ) : $query->the_post(); ?>
UPDATE 2:
Now that you have your wrappers being written to your document, you need to normalize your information. Try to avoid using Metadata instead of normal post attributes. I imagine your metadata 'release_image' is a link to an image somewhere on your server:
<?php if ( $query->have_posts() ) : while ( $query->have_posts() ) : $query->the_post();
?>
<div id="press-wrapper">
<div id="press-image">
<img src="<?php echo get_post_meta(get_the_ID(), 'release_image', true); ?>" />
</div><!-- end press-image div -->
<div id="press-information">
<p class="press-date"><?php echo the_date(); ?></p>
<p class="press-link"><?php the_title(); ?></p>
<p class="press-author"><?php the_author(); ?></p>
</div><!-- end press-information div -->
<div style="clear:both;"></div>
</div><!-- end press-wrapper div -->
<?php endwhile; endif; wp_reset_postdata(); ?>