My client wants to have his news page with 3 columns and 3 posts on the page.
Each column has a title name, date, the excerpt and read more function.
Like this: http://rikvandoorn.nl/nieuws_pagina.jpg
Cause my PHP knowledge isn't that good, i was looking for some tutorials to create the 3 column page. But al those tutorials are outdated, in lack of information or they don't seem to work that well.
And the "leave a reply" can be moved to the single.php.
So i hope some of you can provide me some help.
This is my current content.php
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<div class="aside">
<h1 class="entry-title"><?php the_title(); ?></h1>
<div class="entry-content">
<?php the_content( __( 'Continue reading <span class="meta-nav">→</span>', 'twentytwelve' ) ); ?>
</div><!-- .entry-content -->
</div><!-- .aside -->
<footer class="entry-meta">
<?php echo get_the_date(); ?>
<?php if ( comments_open() ) : ?>
<div class="comments-link">
<?php comments_popup_link( '<span class="leave-reply">' . __( 'Leave a reply', 'twentytwelve' ) . '</span>', __( '1 Reply', 'twentytwelve' ), __( '% Replies', 'twentytwelve' ) ); ?>
</div><!-- .comments-link -->
<?php endif; // comments_open() ?>
<?php edit_post_link( __( 'Edit', 'twentytwelve' ), '<span class="edit-link">', '</span>' ); ?>
</footer><!-- .entry-meta -->
</article><!-- #post -->
Set up the wordpress loop
<?php if ( have_posts() ) : while ( have_posts() ) : the_post();?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<div class="aside">
<h1 class="entry-title"><?php the_title(); ?></h1>
<div class="entry-content">
<?php the_content( __( 'Continue reading <span class="meta-nav">→</span>', 'twentytwelve' ) ); ?>
</div><!-- .entry-content -->
</div><!-- .aside -->
<?php edit_post_link( __( 'Edit', 'twentytwelve' ), '<span class="edit-link">', '</span>' ); ?>
</article><!-- #post -->
<?php endwhile; endif; wp_reset_query(); ?>
and then in the admin go to Settings > General > Reading - select 3 in 'Blog pages show at most'
Related
i have a problem with my wordpress theme. It works, but when i would like to turn the comments off, it doesn't show me the excerpt.
The first picture shows how it look like when comments are allowed, the second picture shows it when comments are not allowed.
Comments allowed
Comments off
Here is the code snippet from content.php page:
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<header class="entry-header">
<div class="entry-header-title">
<?php if ( is_single() ) : ?>
<h1 class="entry-title"><?php the_title(); ?></h1>
<?php else : ?>
<h1 class="entry-title">
<?php the_title(); ?>
</h1>
<?php endif; // is_single() ?>
<span class="entry-meta-date">
<?php twentythirteen_entry_date(); ?>
<span>|</span>
<?php if ( comments_open() && ! is_single() ) : ?>
<span class="entry-comments" >
<?php comments_popup_link( '<span class="leave-reply">' . __( 'Leave a Reply', 'twentythirteen' ) . '</span>', __( '1 Comment', 'twentythirteen' ), __( '% Comments', 'twentythirteen' ) ); ?>
</span><!-- .entry-comments -->
</span><!-- .entry-meta -->
<?php if ( has_post_thumbnail() && ! post_password_required() ) : ?>
<div class="entry-thumbnail">
<?php the_post_thumbnail(); ?>
</div>
<?php endif; ?>
</div>
</header><!-- .entry-header -->
<?php if ( is_search() ) : // Only display Excerpts for Search ?>
<div class="entry-summary">
<?php the_excerpt(); ?>
</div><!-- .entry-summary -->
<?php else : ?>
<div class="entry-content">
<?php the_content( __( 'Continue reading <span class="meta-nav">→</span>', 'twentythirteen' ) ); ?>
<?php wp_link_pages( array( 'before' => '<div class="page-links"><div class="page-links-title">' . __( 'Pages:', 'twentythirteen' ) . '</div>', 'after' => '</div>', 'link_before' => '<div>', 'link_after' => '</div>' ) ); ?>
</div><!-- .entry-content -->
<?php endif; ?>
<footer class="entry-meta">
<?php endif; // comments_open() ?>
<div class="entry-labels">
<?php twentythirteen_entry_meta(); ?>
</div>
<div class="entry-share">
<?php if( function_exists('ADDTOANY_SHARE_SAVE_KIT') ) { ADDTOANY_SHARE_SAVE_KIT(); } ?>
</div>
<div class=".post-spacer">
</div>
</footer><!-- .entry-meta -->
</article><!-- #post -->
<div class="linkwithin_div"></div>
You accidentally deleted an <?php endif;?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<header class="entry-header">
<div class="entry-header-title">
<?php if ( is_single() ) : ?>
<h1 class="entry-title"><?php the_title(); ?></h1>
<?php else : ?>
<h1 class="entry-title">
<?php the_title(); ?>
</h1>
<?php endif; // is_single() ?>
<span class="entry-meta-date">
<?php twentythirteen_entry_date(); ?>
<span>|</span>
<?php if ( comments_open() && ! is_single() ) : ?>
<span class="entry-comments" >
<?php comments_popup_link( '<span class="leave-reply">' . __( 'Leave a Reply', 'twentythirteen' ) . '</span>', __( '1 Comment', 'twentythirteen' ), __( '% Comments', 'twentythirteen' ) ); ?>
</span><!-- .entry-comments -->
</span><!-- .entry-meta -->
//THIS ONE
<?php endif; // comments_open() ?>
<?php if ( has_post_thumbnail() && ! post_password_required() ) : ?>
<div class="entry-thumbnail">
<?php the_post_thumbnail(); ?>
</div>
<?php endif; ?>
</div>
</header><!-- .entry-header -->
<?php if ( is_search() ) : // Only display Excerpts for Search ?>
<div class="entry-summary">
<?php the_excerpt(); ?>
</div><!-- .entry-summary -->
<?php else : ?>
<div class="entry-content">
<?php the_content( __( 'Continue reading <span class="meta-nav">→</span>', 'twentythirteen' ) ); ?>
<?php wp_link_pages( array( 'before' => '<div class="page-links"><div class="page-links-title">' . __( 'Pages:', 'twentythirteen' ) . '</div>', 'after' => '</div>', 'link_before' => '<div>', 'link_after' => '</div>' ) ); ?>
</div><!-- .entry-content -->
<?php endif; ?>
<footer class="entry-meta">
<div class="entry-labels">
<?php twentythirteen_entry_meta(); ?>
</div>
<div class="entry-share">
<?php if( function_exists('ADDTOANY_SHARE_SAVE_KIT') ) { ADDTOANY_SHARE_SAVE_KIT(); } ?>
</div>
<div class=".post-spacer">
</div>
I have a custom post type (called 'discount') that I am trying to display in the twentythirteen theme. I created a custom page file called discount-page.php to create my own template for this post type. I'm not sure where I need to place the wp_query code, however. Here's what the default page.php looks like, with an addition of the new template name:
<div id="primary" class="content-area">
<div id="content" class="site-content" role="main">
<?php /* The loop */ ?>
<?php while ( have_posts() ) : the_post(); ?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<header class="entry-header">
<?php if ( has_post_thumbnail() && ! post_password_required() ) : ?>
<div class="entry-thumbnail">
<?php the_post_thumbnail(); ?>
</div>
<?php endif; ?>
<h1 class="entry-title"><?php the_title(); ?></h1>
</header><!-- .entry-header -->
<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 -->
<footer class="entry-meta">
<?php edit_post_link( __( 'Edit', 'twentythirteen' ), '<span class="edit-link">', '</span>' ); ?>
</footer><!-- .entry-meta -->
</article><!-- #post -->
<?php comments_template(); ?>
<?php endwhile; ?>
</div><!-- #content -->
</div><!-- #primary -->
Now, I'm fairly sure that in order for my posts to actually show their content, I need to add this block of code to the discount-page.php:
<?php
$query = new WP_Query( array('post_type' => 'discount', 'posts_per_page' => 5 ) );
while ( $query->have_posts() ) : $query->the_post(); ?>
// Your code e.g. "the_content();"
<?php endif; wp_reset_postdata(); ?>
<?php endwhile; ?>
I just have no idea where to add it? It seems to break the page no matter where I add it.
You just have to change a couple of lines of code for it to work.
<div id="primary" class="content-area">
<div id="content" class="site-content" role="main">
<?php /* The loop */ ?>
<?php
$query = new WP_Query( array('post_type' => 'discount', 'posts_per_page' => 5 ) );
while ( $query->have_posts() ) : $query->the_post(); ?> ?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<header class="entry-header">
<?php if ( has_post_thumbnail() && ! post_password_required() ) : ?>
<div class="entry-thumbnail">
<?php the_post_thumbnail(); ?>
</div>
<?php endif; ?>
<h1 class="entry-title"><?php the_title(); ?></h1>
</header><!-- .entry-header -->
<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 -->
<footer class="entry-meta">
<?php edit_post_link( __( 'Edit', 'twentythirteen' ), '<span class="edit-link">', '</span>' ); ?>
</footer><!-- .entry-meta -->
</article><!-- #post -->
<?php comments_template(); ?>
<?php endwhile; wp_reset_postdata(); ?>
</div><!-- #content -->
</div><!-- #primary -->
If you want the super simple version of it removing everything else. Try this:
<div id="primary" class="content-area">
<div id="content" class="site-content" role="main">
<?php
$query = new WP_Query( array('post_type' => 'discount', 'posts_per_page' => 5 ) );
while ( $query->have_posts() ) : $query->the_post();
?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<div class="entry-content">
<?php the_content(); ?>
</div>
</article>
<?php endwhile; wp_reset_postdata(); ?>
</div>
</div>
Can someone advise where to comment out the page title in Coraline theme? I've tried different things and it does not work. Here's my page.php
<div id="content-container">
<div id="content" role="main">
<?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<?php if ( is_front_page() ) { ?>
<h2 class="entry-title"><?php the_title(); ?></h2>
<?php } else { ?>
<h1 class="entry-title"><?php the_title(); ?></h1>
<?php } ?>
<div class="entry-content">
<?php the_content(); ?>
<?php wp_link_pages( array( 'before' => '<div class="page-link">' . __( 'Pages:', 'coraline' ), 'after' => '</div>' ) ); ?>
<?php edit_post_link( __( 'Edit', 'coraline' ), '<span class="edit-link">', '</span>' ); ?>
</div> <!-- .entry-content
</div> <!-- #post-## -->
<?php comments_template( '', true ); ?>
<?php endwhile; ?>
</div><!-- #content -->
</div><!-- #content-container -->
I would assume it would be this line:
<h1 class="entry-title"><?php the_title(); ?></h1>
To comment out, replace with:
<!--<h1 class="entry-title"><?php the_title(); ?></h1>-->
You can also just leave the Title box empty when creating a new page in the admin panel.
I am using wordpress and twenty twelve child as my theme.
I made a website for funny pictures, and basically what I want is the image inside every page to act like a link to a next image. Heres some example sites with this feature: DailyHaHa and Meme-lol.com You see if you click the image, it will take you to next image page. I'm working on local machine so I can't give link to my website. Here is my content.php:
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<?php if ( is_sticky() && is_home() && ! is_paged() ) : ?>
<div class="featured-post">
<?php _e( 'Featured post', 'twentytwelve' ); ?>
</div>
<?php endif; ?>
<div class="entry-header">
<?php the_post_thumbnail(); ?>
<?php if ( is_single() ) : ?>
<div class="post-header">
<div class="entry-title">
<?php the_title(); ?>
</div>
<span class="inline-div">
<span class="entry-bar"><li><?php echo "Added "; wp_days_ago(); ?></li> </span>
<li><?php comments_popup_link( '<span class="leave-reply">' . __( 'Be first to comment', 'twentytwelve' ) . '</span>', __( '1 comment', 'twentytwelve' ), __( '% comments', 'twentytwelve' ) ); ?></li>
<!-- .comments-link -->
<span class="edit"><li><?php edit_post_link( __( 'Edit', 'twentytwelve' ), '<span class="edit-link">', '</span>' ); ?></li></span>
</span>
<?php else : ?>
<div class="entry-title">
<?php the_title(); ?>
</div>
<span class="inline-div">
<span class="entry-bar"><li><?php echo "Added "; wp_days_ago(); ?></li> </span>
<li><?php comments_popup_link( '<span class="leave-reply">' . __( 'Be first to comment', 'twentytwelve' ) . '</span>', __( '1 comment', 'twentytwelve' ), __( '% comments', 'twentytwelve' ) ); ?></li>
<!-- .comments-link -->
<span class="edit"><li><?php edit_post_link( __( 'Edit', 'twentytwelve' ), '<span class="edit-link">', '</span>' ); ?></li></span>
</span>
<?php endif; // is_single() ?>
</div><!-- .entry-header -->
<?php if ( is_search() ) : // Only display Excerpts for Search ?>
<div class="entry-summary">
<?php the_excerpt(); ?>
</div><!-- .entry-summary -->
<?php else : ?>
<div class="entry-content">
<?php the_content( __( 'Continue reading <span class="meta-nav">→</span>', 'twentytwelve' ) ); ?>
<?php wp_link_pages( array( 'before' => '<div class="page-links">' . __( 'Pages:', 'twentytwelve' ), 'after' => '</div>' ) ); ?>
</div><!-- .entry-content -->
<?php endif; ?>
<div class="share-buttons">
<a class="facebook-button" target="_blank" onclick="return !window.open(this.href, 'Facebook', 'width=640,height=300')" href="http://www.facebook.com/sharer/sharer.php?u=<?php the_permalink(); ?>"><img src="/images/share.png" /></a>
<a class="tweet-button" target="_blank" href="http://twitter.com/share"><img src="/images/tweet.png" /></a>
</div>
<div class="nav2">
<span class="previous-button">
<?php next_post_link( '%link', '<img src="/images/prev.png" alt="Previous"/>' ); ?>
</span>
<span class="random-post">
<?php $randomPost = $wpdb->get_var("SELECT guid FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' ORDER BY rand() LIMIT 1");
echo '<img src="/images/random.png" alt="Random"/>'; ?>
</span>
<span class="next-button">
<?php previous_post_link( '%link', '<img src="/images/Next.png" alt="Next"/>' ); ?>
</div>
<br />
</span>
</article><!-- #post -->
You need to get the featured image of the post first.
<?php // Display the thumbnail of the previous post ?>
<span class="previous-button"> <?php
$prevPost = get_previous_post();
$prevthumbnail = get_the_post_thumbnail($prevPost->ID); ?>
<?php previous_post_link('%link', $prevthumbnail); ?>
</span>
<?php // Display the thumbnail of the next post ?>
<span class="next-button"> <?php
$nextPost = get_next_post();
$nextthumbnail = get_the_post_thumbnail($nextPost->ID); ?>
<?php next_post_link('%link', $nextthumbnail); ?>
</span>
<div class="content" style="min-height:1022px;">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div class="singlepost">
<h1 class="page-title"><?php the_title(); ?> </h1>
<div class="post_info">
<p><?php the_time('Y年n月j日') ?>
<span>/ </span>
<?php comments_popup_link('0 comment', '1 comment', '% comments', '', 'closed'); ?>
<span>/ </span>
<?php the_category(', ') ?>
</p>
</div>
<div class="post1">
<div class="post1text">
<!-- Post Content -->
<?php the_content(); ?>
</div>
</div>
<p class="clearfix" style="margin-left:20px;"><?php previous_posts_link('<< TheNewer', 0); ?> <span class="float right"><?php next_posts_link('ThePast >>', 0); ?></span></p>
</div>
<?php endwhile; else : ?>
<?php endif; ?>
<div class="cleared"></div>
</div>
Above code is my single.php which display the content, but it's display every page the same content, so, what's wrong with it? is the loop? Thanks very much~
It's so easy once you understand the basic template selection hierarchy, which should get you started.
http://codex.wordpress.org/Template_Hierarchy
You can also create page templates, it's really very simple and useful.
http://codex.wordpress.org/Pages#Creating_your_own_Page_Templates
And finally once you have got all that working, you can start doing some really clever stuff with conditional tags.
http://codex.wordpress.org/Conditional_Tags
Instead of your code try this simple code in single.php
<div class="content" style="min-height:1022px;">
<?php while ( have_posts() ) : the_post(); ?>
<nav id="nav-single">
<h3 class="assistive-text"><?php _e( 'Post navigation', 'twentyeleven' ); ?></h3>
<span class="nav-previous"><?php previous_post_link( '%link', __( '<span class="meta-nav">←</span> Previous', 'twentyeleven' ) ); ?></span>
<span class="nav-next"><?php next_post_link( '%link', __( 'Next <span class="meta-nav">→</span>', 'twentyeleven' ) ); ?></span>
</nav><!-- #nav-single -->
<?php get_template_part( 'content', 'single' ); ?>
<?php comments_template( '', true ); ?>
<?php endwhile; // end of the loop. ?>
</div>