I'm working on making fixes to someones wordpress site, and i encountered this strange code in the loop.php and in a template file for a specific page. My goal is to change this to display the featured image in the header.I did some research into how to output the featured image using the get_thumbnail syntax, I don't normally do much in the back end / FTP of wordpress so thank you for your help and patience.
<?php
/**
* #package WordPress
* #subpackage WP-Skeleton
*/
?>
</div>
<div id="primary">
<div id="content">
**<?php the_post(); ?>
<?php $thumb = wp_get_attachment_image_src( get_post_thumbnail_id( get_the_ID('full') ), 'page-header' );
$url = $thumb['0'];?>
<div id="page-header" style="background-image:url('<?php echo $url; ?>');">**
</div>
<div style="clear"></div>
<div class="container">
<section class="sixteen columns alpha">
<header class="entry-header">
<h2 class="entry-title">Events</h2>
</header>
<div class="entry-content ">
<?php while ( have_posts() ) : the_post(); ?> <!-- the Loop -->
<article id="post-<?php the_ID(); ?>" class="event">
<div class="title">
<?php the_title('<h3>', '</h3>'); ?> <!--Post titles-->
</div>
<div class="event-img"><?php the_post_thumbnail('event-img'); ?></div>
<?php the_content("Continue reading " . the_title('', '', false)); ?> <!--The Content-->
</article>
<?php endwhile; ?><!-- End the Loop -->
</div>
</section>
<div>
</div> <!-- End two-thirds column -->
</div><!-- End Content -->
</diV>
If you want to display the featured image inside the header, use the below code in it.
<?php
if(have_posts()) :
while (have_posts()) : the_post();
the_post_thumbnail();
endwhile;
endif;
?>
Related
On my list of posts page, I would like to display 3 posts on each row. (Desktop view only)
With the following code, each post is taking up the entire width of the screen with each post starting on a new line. How can I work around this?
Here is the code in my index.php which initially targets the loop.
<section id="portfolio" class="wow fadeIn hide" data-wow-duration="2s">
<div class="container">
<div class="row">
<?php
endif;
/* Start the Loop */
while ( have_posts() ) :
the_post();
get_template_part( 'template-parts/content', "grid" );
endwhile;
else :
endif;
?>
</div>
</div>
</section>
And here is the code in my content-grid.php which displays the content of the loop.
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<div class="col-lg-4 col-md-12 col-sm-12"> <!-- Start of featured project column --->
<a href="<?php the_permalink(); ?>">
<div class="img-container thumbnail">
<?php if ( has_post_thumbnail() ) the_post_thumbnail(); ?>
<div class="hover-block">
<h3 class="project-name"><?php the_title(); ?></h3>
</div>
</div>
</a>
</div> <!-- End of featured project column --->
</article><!-- #post-<?php the_ID(); ?> -->
I have been working on a custom archive page but I have run into some trouble. The pagination is shifting down into the footer area.
I have gone through my code several times and I cannot work out why this is happening. If I remove the loop, the template works correctly.
With the loop in place, the pagination shifts down to the footer and takes any coding below it (in the archive page) with it.
The archive page coding is:
<?php get_header(); ?>
<main role="main">
<section class="commissions">
<div class="commissions-section-one">
<h1>Commissions</h1>
<?php if(!function_exists('dynamic_sidebar') || !dynamic_sidebar('commissions-intro')) ?>
</div>
<?php get_template_part('single-commissions'); ?>
<?php get_template_part('pagination'); ?>
</section><!-- /section -->
</main><!--/ Main -->
<?php get_footer(); ?>
The custom loop code is:
<?php if (have_posts()): while (have_posts()) : the_post(); ?>
<div class="commission-wrapper">
<div class="commission-inner cf">
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<div class="commission-content-wrapper">
<div class="commission-content-inner">
<img src="<?php the_field('commissions-company-logo'); ?>" />
<h2 class="company-author"><?php the_title(); ?></h2>
<p class="company-location"><?php the_field('commissions-company-location'); ?></p>
<p class="company-description"><?php the_field('commissions-company-description'); ?></p>
<p class="company-date"><?php the_field('commissions-company-date'); ?></p>
<?php echo do_shortcode("[indeed-social-media sm_list='fb,tw,goo,li' sm_template='ism_template_10' sm_list_align='horizontal' sm_display_counts='false' sm_display_full_name='false ]");?>
</div><!--/ Commission Content Inner -->
</div><!--/ Commission Content Wrapper -->
</article><!--/ Article -->
<div class="commission-images">
<div class="row first cf">
<div class="left-column" style="background-image:url(<?php the_field('commissions-image-one'); ?>);"></div>
<div class="right-column" style="background-image:url(<?php the_field('commissions-image-two'); ?>);"></div>
</div><!--/ Row -->
<div class="row cf">
<div class="left-column" style="background-image:url(<?php the_field('commissions-image-three'); ?>);"></div>
<div class="right-column" style="background-image:url(<?php the_field('commissions-image-four'); ?>);"></div>
</div><!--/ Row -->
</div><!--/ Commission Images -->
</div><!--/ Commission Inner -->
</div><!--/ Commission Wrapper -->
<?php endwhile; ?>
<?php else: ?>
<!-- article -->
<article>
<h1><?php _e( 'Sorry, nothing to display.', 'html5blank' ); ?></h1>
</article>
<!-- /article -->
<?php endif; ?>
<?php get_footer(); ?>
I am using the HTML 5 blank theme and haven't added anything additional in regards to pagination.
I'm not sure what you're doing with this line...
<?php if(!function_exists('dynamic_sidebar') || !dynamic_sidebar('commissions-intro')) ?>
...since you're not outputting anything. I'd either get rid of it, or fix it so that it's a valid conditional (with an endif;).
It also looks like you're calling get_footer() twice...
I would like some help if possible in the following question:
I use in my Genesis theme a bootstrap grid, and would like to display the search results using this grid.
I created a search.php with the following code:
<?php
/**
* Search Results Template File
*/
get_header(); ?>
<header>
<h1>Search Results: "<?php echo get_search_query(); ?>"</h1>
<br>
</header>
<?php if ( have_posts() ) : // results found?>
<?php while ( have_posts() ) : the_post(); ?>
<div class="container-fluid">
<div class="row">
<div class="col-md-3 col-sm-6 col-xs-12">
<div class="gr-infos-container-cliente">
<div class="gr-promo-do-cliente"><?php the_field('tipo_de_promo');?></div>
<div class="gr-img-cliente"><img src="<?php echo get_field('foto_cliente_miniatura');?>" alt="" class="img-responsive center-block"></div>
<div class="gr-nome-cliente"><?php the_title();?></div>
<div class="gr-tagline-cliente"><?php the_field('tagline_do_anunciante');?></div>
<div class="gr-bairro-do-cliente"><i class="cliente fa fa-map-marker"></i><?php the_field('bairro_do_cliente');?></div>
</div>
</div>
</div> <!-- Row -->
</div> <!-- Container -->
<?php endwhile; ?>
<?php else : // no results?>
<article>
<h1>No Results Found.</h1>
</article>
<?php endif; ?>
<?php get_footer(); ?>
genesis();
But in the search result, the content is aligned one on top of another and not in the selected grid.
Any tips you can give me?
I am very grateful for any help!
This is due to that your 'row' div is inside the while loop, causing it to generate multiple 'row' div instead of one.
To fix this, you'll need to place the while loop inside the 'row' div.
Try the code bellow
<?php
/**
* Search Results Template File
*/
get_header(); ?>
<header>
<h1>Search Results: "<?php echo get_search_query(); ?>"</h1>
<br>
</header>
<?php if ( have_posts() ) : // results found?>
<div class="container-fluid">
<div class="row">
<?php while ( have_posts() ) : the_post(); ?>
<div class="col-md-3 col-sm-6 col-xs-12">
<div class="gr-infos-container-cliente">
<div class="gr-promo-do-cliente"><?php the_field('tipo_de_promo');?></div>
<div class="gr-img-cliente"><img src="<?php echo get_field('foto_cliente_miniatura');?>" alt="" class="img-responsive center-block"></div>
<div class="gr-nome-cliente"><?php the_title();?></div>
<div class="gr-tagline-cliente"><?php the_field('tagline_do_anunciante');?></div>
<div class="gr-bairro-do-cliente"><i class="cliente fa fa-map-marker"></i><?php the_field('bairro_do_cliente');?></div>
</div>
</div>
<?php endwhile; ?>
</div> <!-- Row -->
</div> <!-- Container -->
<?php else : // no results?>
<article>
<h1>No Results Found.</h1>
</article>
<?php endif; ?>
<?php get_footer(); ?>
genesis();
I created custom theme with WordPress and bootstrap and everything works fine except previous and next link in singe.php.
Here is my code:
<?php get_header(); ?>
<article>
<div class="container single-project">
<?php if (have_posts()) : while (have_posts()) : the_post();?>
<div class="row">
<div class=" col-md-4 col-lg-4 pull-right">
<header class="entry-header">
<h1 id="post-<?php the_ID(); ?>"><?php the_title();?></h1>
<hr>
</header><!-- .entry-header -->
</div>
<div class=" hidden-md hidden-lg"><hr></div>
<div class="col-md-4 col-lg-4"><?php the_content(); ?></div>
<?php previous_posts_link() ?>
<?php next_posts_link() ?>
</div> <!-- end of row -->
</div> <!-- end of container -->
<?php endwhile; endif; ?>
</article>
<?php get_footer(); ?>
Thanks in advance.
You have to move
<?php previous_posts_link() ?>
<?php next_posts_link() ?>
after
</article>
preferably inside some div so you can style it, like
<div class="navi">
<?php previous_posts_link() ?>
<?php next_posts_link() ?>
</div>
Found solution:
<?php previous_post('« « %', 'Previous Post', 'yes'); ?> |
<?php next_post('% » » ', 'Next Post', 'yes'); ?>
http://wpsites.net/web-design/previous-next-single-post-navigation-links-wordpress/
I'm actually trying to display the post thumbnail inside the loop just before the content by using the_post_thumbnail(); function.
It works like a charm in anywhere in my page before I call the function
<?php get_sidebar(); ?>
After that impossible to show the post thumbnail.
I've tried with
<?php the_post_thumbnail(); ?>
and also
<?php echo get_the_post_thumbnail(); ?> but nothing happens.
Here is my whole code :
<?php
/**
* The Template for displaying all single posts
*
* #package WordPress
*/
get_header(); ?>
<div id="pageHeader" >
<div id="pageHeader-inner"> <span class="shadow"></span><img src="<?php bloginfo('template_url'); ?>/images/header_01.jpg" /></div>
</div>
<div class="container" id="pageTitle">
<h1><?php the_title(); ?></h1>
</div>
<!--Begin of content-->
<div class="grey-bg">
<div class="container">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div class="row">
<div class="col-sm-3 sidebar">
<!-- Sub Nav -->
<?php if ( is_page() ) { ?>
<?php
if($post->post_parent)
$children = wp_list_pages('title_li=&child_of='.$post->post_parent.'&echo=0'); else
$children = wp_list_pages('title_li=&child_of='.$post->ID.'&echo=0');
if ($children) { ?>
<div class="sidebar-module sub-menu">
<ul>
<?php echo $children; ?>
</ul>
</div>
<?php } } ?>
<!--Works perfectly till here -->
<?php get_sidebar(); ?>
<!--Broken till here-->
</div> <!-- /.sidebar -->
<div class="col-sm-9">
<div class="content-main">
<div class="content white-bg left-stroke <?php echo $post->post_name; ?>">
<?php if ( has_post_thumbnail() ) the_post_thumbnail(); ?>
<?php the_content(); ?>
<?php endwhile; ?>
<?php else : ?>
<div <?php post_class(); ?> id="post-<?php the_ID(); ?>">
<h1>Not Found</h1>
</div>
<?php endif; ?>
</div> <!-- /.content -->
</div><!-- /.content-main -->
</div>
</div>
<!-- /.row -->
</div>
<!-- /.container -->
</div>
<?php get_footer(); ?>
Thank's a lot for your responses.
You are trying to use function the_post_thumbnail() outside WordPress loop. To use this function outside loop you have to specify "post ID". Documentation for this function http://codex.wordpress.org/Function_Reference/get_the_post_thumbnail
For example to get thumbnail for post ID 4 you have to use function with parameter 4 like the_post_thumbnail(4) or store ID in variable.