How to insert "Author" code in Wordpress Required theme? - php

Been trying to insert "By Author" by <?php the_author() ?> code on a Wordpress theme(Required by 8Bit). Request to help. Need to insert after the post/page title and before date.
The code is as follows:
<header>
<?php if ( 0 < strlen( get_the_title() ) ) { ?>
<h1 class="entry-title">
<a href="<?php the_permalink(); ?>">
<?php the_title(); ?>
</a>
</h1><!-- /.entry-title -->
<?php } // end if ?>
<div class="post-meta">
<span class="post-date">
<?php if ( 0 < strlen( get_the_title() ) ) { ?>
<?php the_time( get_option( 'date_format' ) ); ?>
<?php } else { ?>
<a href="<?php the_permalink(); ?>">
<?php the_time( get_option( 'date_format' ));?>
</a>
<?php } // end if/else ?>
</span><!-- /.post-date -->
<?php _e( ' | ', 'required' ); ?>
<span class="comment-link">
<?php
comments_popup_link( 'Comment', '1 comment', '% comments',
'comments-link', '');
?>
</span><!-- /.comment-link -->
<?php edit_post_link( '- edit ', '<span>', '</span>'); ?>
</div><!-- /.post-meta -->
</header>
Thanks :)
This is the loop code:
<?php
if ( have_posts() ) {
while ( have_posts() ) {
the_post();
get_template_part( 'content', get_post_format() );
} // end while

Here's an example, between the title and date:
<header>
<?php if ( 0 < strlen( get_the_title() ) ) { ?>
<h1 class="entry-title">
<a href="<?php the_permalink(); ?>">
<?php the_title(); ?>
</a>
</h1><!-- /.entry-title -->
<?php } // end if ?>
<div class="post-meta">
<?php the_author(); ?>
<span class="post-date">
<?php if ( 0 < strlen( get_the_title() ) ) { ?>
<?php the_time( get_option( 'date_format' ) ); ?>
<?php } else { ?>
<a href="<?php the_permalink(); ?>">
<?php the_time( get_option( 'date_format' ));?>
</a>
<?php } // end if/else ?>
</span><!-- /.post-date -->
<?php _e( ' | ', 'required' ); ?>
<span class="comment-link">
<?php
comments_popup_link( 'Comment', '1 comment', '% comments',
'comments-link', '');
?>
</span><!-- /.comment-link -->
<?php edit_post_link( '- edit ', '<span>', '</span>'); ?>
</div><!-- /.post-meta -->
</header>

Related

Add pagination to this Wordpress Home

I Guys! I'm working on a pagination for this theme homepage. The original code is:
<?php
/**
Blog
**/
$display_count = get_theme_mod('wpex_home_blog_count', '30');
$wpex_query = new WP_Query(
array(
'post_type' => 'post',
'posts_per_page' => $display_count,
'no_found_rows' => true,
)
);
if ( $wpex_query->posts && '0' != $display_count ) { ?>
<div id="homepage-blog" class="clr">
<h2 class="heading"><span><?php _e( 'From The Blog', 'wpex' ); ?></span></h2>
<?php $wpex_count=0; ?>
<?php foreach( $wpex_query->posts as $post ) : setup_postdata( $post ); ?>
<?php $wpex_count++; ?>
<article class="recent-blog-entry clr col span_1_of_3 col-<?php echo $wpex_count; ?>">
<?php
// Display post thumbnail
if ( has_post_thumbnail() ) { ?>
<div class="recent-blog-entry-thumbnail">
<a href="<?php the_permalink(); ?>" title="<?php echo esc_attr( the_title_attribute( 'echo=0' ) ); ?>">
<img src="<?php echo wpex_get_featured_img_url(); ?>" alt="<?php echo esc_attr( the_title_attribute( 'echo=0' ) ); ?>" />
</a>
</div><!-- .recent-blog-entry-thumbnail -->
<?php } ?>
<header>
<h3 class="recent-blog-entry-title"><?php the_title(); ?></h3>
<?php
// Display post meta details
wpex_post_meta() ;?>
</header>
<div class="recent-blog-entry-content entry clr">
<?php wpex_excerpt( 18, false ); ?>
</div><!-- .recent-blog-entry-content -->
</article><!-- .recent-blog -->
<?php if ( $wpex_count == '3' ) { ?>
<?php $wpex_count=0; ?>
<?php } ?>
<?php endforeach; ?>
</div><!-- #homepage-portfolio -->
<?php } ?>
What I did is, I changed it to
<div id="homepage-blog" class="clr">
<h2 class="heading"><span><?php _e( 'From The Blog', 'wpex' ); ?></span></h2>
<?php $wpex_count=0; ?>
<?php
$temp = $wp_query; $wp_query= null;
$wp_query = new WP_Query(); $wp_query->query('showposts=4' . '&paged='.$paged);
while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
<?php $wpex_count++; ?>
<article class="recent-blog-entry clr col span_1_of_3 col-<?php echo $wpex_count; ?>">
<?php
// Display post thumbnail
if ( has_post_thumbnail() ) { ?>
<div class="recent-blog-entry-thumbnail">
<a href="<?php the_permalink(); ?>" title="<?php echo esc_attr( the_title_attribute( 'echo=0' ) ); ?>">
<img src="<?php echo wpex_get_featured_img_url(); ?>" alt="<?php echo esc_attr( the_title_attribute( 'echo=0' ) ); ?>" />
</a>
</div><!-- .recent-blog-entry-thumbnail -->
<?php } ?>
<header>
<h3 class="recent-blog-entry-title"><?php the_title(); ?></h3>
<ul class="post-meta clr">
<li class="meta-date">
<?php _e('Posted on','wpex'); ?>
<span class="meta-date-text"><?php echo get_the_date(); ?></span>
</li>
</ul>
</header>
<div class="recent-blog-entry-content entry clr">
<?php wpex_excerpt( 18, false ); ?>
</div><!-- .recent-blog-entry-content -->
</article><!-- .recent-blog -->
<?php if ( $wpex_count == '3' ) { ?>
<?php $wpex_count=0; ?>
<?php } ?>
<?php endwhile; ?>
</div>
<?php wp_pagenavi();?>
<?php wp_reset_postdata(); ?>
</article>
This seems to work on the first page, but when i go to page 2, it gives an copy after copy after copy of the whole page, like an infinate page one. That's not how it should work.
Any ideas what goes wrong here? Does this make any sense to you?
EDIT:
I tried the following. Right now the first page looks good, but when i press the second page on the pagination, it outputs the same as the first.
<?php
$args = array(
'paged' => (get_query_var('paged') ? get_query_var('paged') : 1),
'posts_per_page' => 4
);
query_posts($args);
?>
<div id="homepage-blog" class="clr">
<h2 class="heading"><span><?php _e( 'From The Blog', 'wpex' ); ?></span></h2>
<?php $wpex_count=0; ?>
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<?php $wpex_count++; ?>
<article class="recent-blog-entry clr col span_1_of_3 col-<?php echo $wpex_count; ?>">
<?php
// Display post thumbnail
if ( has_post_thumbnail() ) { ?>
<div class="recent-blog-entry-thumbnail">
<a href="<?php the_permalink(); ?>" title="<?php echo esc_attr( the_title_attribute( 'echo=0' ) ); ?>">
<img src="<?php echo wpex_get_featured_img_url(); ?>" alt="<?php echo esc_attr( the_title_attribute( 'echo=0' ) ); ?>" />
</a>
</div><!-- .recent-blog-entry-thumbnail -->
<?php } ?>
<header>
<h3 class="recent-blog-entry-title"><?php the_title(); ?></h3>
<ul class="post-meta clr">
<li class="meta-date"><?php _e('Posted on','wpex'); ?> <span class="meta-date-text"><?php echo get_the_date(); ?></span> </li>
</ul>
</header>
<div class="recent-blog-entry-content entry clr">
<?php wpex_excerpt( 18, false ); ?>
</div><!-- .recent-blog-entry-content -->
</article><!-- .recent-blog -->
<?php if ( $wpex_count == '3' ) { ?>
<?php $wpex_count=0; ?>
<?php } ?>
<?php endwhile; ?>
<?php wp_pagenavi();?>
</div><!-- #homepage-portfolio -->
<?php endif; ?>
<?php wp_reset_query(); ?>
</article><!-- #post -->
<?php endwhile; ?>
Whole original code:
<div id="primary" class="content-area clr">
<div id="content" class="site-content" role="main">
<?php while ( have_posts() ) : the_post(); ?>
<article class="homepage-wrap clr">
<?php
/**
Post Content
**/ ?>
<?php if ( get_the_content() !== '' ) { ?>
<div id="homepage-content" class="entry clr">
<?php the_content(); ?>
</div><!-- .entry-content -->
<?php } ?>
<?php
/**
Features
**/
$wpex_query = new WP_Query(
array(
'order' => 'ASC',
'orderby' => 'menu_order',
'post_type' => 'features',
'posts_per_page' => '-1',
'no_found_rows' => true,
)
);
if ( $wpex_query->posts ) { ?>
<div id="homepage-features" class="clr">
<?php $wpex_count=0; ?>
<?php foreach( $wpex_query->posts as $post ) : setup_postdata( $post ); ?>
<?php $wpex_count++; ?>
<?php get_template_part( 'content-features', get_post_format() ); ?>
<?php if ( $wpex_count == '4' ) { ?>
<?php $wpex_count=0; ?>
<?php } ?>
<?php endforeach; ?>
</div><!-- #homepage-features -->
<?php } ?>
<?php wp_reset_postdata(); ?>
<?php
/**
Portfolio
**/
$display_count = get_theme_mod('wpex_home_portfolio_count', '8');
$wpex_query = new WP_Query(
array(
'post_type' => 'portfolio',
'posts_per_page' => $display_count,
'no_found_rows' => true,
'tax_query' => wpex_home_portfolio_taxonomy(),
)
);
if ( $wpex_query->posts && '0' != $display_count ) { ?>
<div id="homepage-portfolio" class="clr">
<h2 class="heading"><span><?php _e( 'Recent Work', 'wpex' ); ?></span></h2>
<?php $wpex_count=0; ?>
<?php foreach( $wpex_query->posts as $post ) : setup_postdata( $post ); ?>
<?php $wpex_count++; ?>
<?php get_template_part( 'content-portfolio', get_post_format() ); ?>
<?php if ( $wpex_count == '4' ) { ?>
<?php $wpex_count=0; ?>
<?php } ?>
<?php endforeach; ?>
</div><!-- #homepage-portfolio -->
<?php } ?>
<?php wp_reset_postdata(); ?>
<?php
/**
Blog
**/
$display_count = get_theme_mod('wpex_home_blog_count', '30');
$wpex_query = new WP_Query(
array(
'post_type' => 'post',
'posts_per_page' => $display_count,
'no_found_rows' => true,
)
);
if ( $wpex_query->posts && '0' != $display_count ) { ?>
<div id="homepage-blog" class="clr">
<h2 class="heading"><span><?php _e( 'From The Blog', 'wpex' ); ?></span></h2>
<?php $wpex_count=0; ?>
<?php foreach( $wpex_query->posts as $post ) : setup_postdata( $post ); ?>
<?php $wpex_count++; ?>
<article class="recent-blog-entry clr col span_1_of_3 col-<?php echo $wpex_count; ?>">
<?php
// Display post thumbnail
if ( has_post_thumbnail() ) { ?>
<div class="recent-blog-entry-thumbnail">
<a href="<?php the_permalink(); ?>" title="<?php echo esc_attr( the_title_attribute( 'echo=0' ) ); ?>">
<img src="<?php echo wpex_get_featured_img_url(); ?>" alt="<?php echo esc_attr( the_title_attribute( 'echo=0' ) ); ?>" />
</a>
</div><!-- .recent-blog-entry-thumbnail -->
<?php } ?>
<header>
<h3 class="recent-blog-entry-title"><?php the_title(); ?></h3>
<?php
// Display post meta details
wpex_post_meta() ;?>
</header>
<div class="recent-blog-entry-content entry clr">
<?php wpex_excerpt( 18, false ); ?>
</div><!-- .recent-blog-entry-content -->
</article><!-- .recent-blog -->
<?php if ( $wpex_count == '3' ) { ?>
<?php $wpex_count=0; ?>
<?php } ?>
<?php endforeach; ?>
</div><!-- #homepage-portfolio -->
<?php } ?>
<?php wp_reset_postdata(); ?>
</article><!-- #post -->
<?php comments_template(); ?>
<?php endwhile; ?>
</div><!-- #content -->
</div><!-- #primary -->
Try declaring $paged outside, and call this in the query_posts
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array(
'posts_per_page' => 4
);
query_posts($args . '&paged=' . $paged);
I might have found an answer for this myself, apparently it's different when you use pagination on the frontpage. I used this and it seems to be working!:
if( is_front_page() ){
$paged = (get_query_var('page')) ? get_query_var('page') : 1;
} else {
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
}

Wordpress Blog page only showing one post

Im having an issue with a theme i've been customizing. My blog post only shows ( 1 ) post and i cant seem to fix the issue in Admin > Reading > Blog pages show at most. The Value only stays at "1" even after save. The code i have here is in the Loop.php
<?php ?>
<article class="primary-content">
<?php $firstClass='first-post' ; ?>
<?php /* If there are no posts to display, such as an empty archive page */ ?>
<?php if ( ! have_posts() ) : ?>
<article role="main" class="the-content">
<h1><?php _e( '404 - I'm sorry but the page can't be found' ); ?></h1>
<p>Please try searching again or head back to the homepage.</p>
</article>
<?php endif; ?>
<?php ?>
<?php if (is_home()): ?>
<h1>
<?php if ( is_day() ) : ?><?php printf( __( '<span>Daily Archive</span> %s' ), get_the_date() ); ?>
<?php elseif ( is_month() ) : ?><?php printf( __( '<span>Monthly Archive</span> %s' ), get_the_date('F Y') ); ?>
<?php elseif ( is_year() ) : ?><?php printf( __( '<span>Yearly Archive</span> %s' ), get_the_date('Y') ); ?>
<?php elseif ( is_category() ) : ?><?php echo single_cat_title(); ?>
<?php elseif ( is_search() ) : ?><?php printf( __( 'Search Results for: %s' ), '<span>' . get_search_query() . '</span>' ); ?>
<?php elseif ( is_home() ) : ?>Blog<?php else : ?>
<?php endif; ?>
</h1>
<?php endif; ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php /* How to display standard posts and search results */ ?>
<article class="article-archive <?php echo $firstClass; ?>" id="post-<?php the_ID(); ?>">
<?php $firstClass="" ; ?>
<?php ?>
<?php if (is_front_page()) { ?>
<div class="home-summary">
<?php } else { ?>
<div class="entry-summary">
<?php } ?>
<a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( '%s' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark">
<?php the_post_thumbnail( 'flozo-thumb');?>
</a>
<?php if (is_front_page()) { ?>
<h1><?php the_title(); ?></h1>
<?php } else { ?>
<h2><?php the_title(); ?></h2>
<?php } ?>
<?php the_excerpt(); ?>
<?php if ( is_home() ) : ?>
<p class="entry-meta">
<time datetime="<?php the_time('l, F jS, Y') ?>" pubdate>
<?php the_time( 'l jS F Y') ?>
</time>
</p>
<?php endif; ?>
</div>
</article>
<?php /*?>
<?php comments_template( '', true ); ?>
<?php */?>
<?php endwhile; // End the loop. Whew. ?>
<?php /* Display navigation to next/previous pages when applicable */ ?>
<?php if ( $wp_query->max_num_pages > 1 ) : ?>
<div class="navigation">
<div class="nav-previous">
<?php next_posts_link( __( 'Older posts' ) ); ?>
</div>
<div class="nav-next">
<?php previous_posts_link( __( 'Newer posts' ) ); ?>
</div>
</div>
<!-- #nav-below -->
<?php endif; ?>
</article>
Any and all help with be greatly appreciated! Sorry if this was posted already.
L

Wordpress getting first post

I am trying to change the class if $firstPost = 0but i'm not sure 100% about the while loop etc as I have an idea I don't need it
PHP/HTML
<?php
$getPosts = new wp_query(array('showposts' => 5, 'orderby' => 1));
if($getPosts->have_posts()):
$firstPost = 0;
while($getPosts->have_posts()):
$getPosts->the_post();
$cssClass = '';
if($firstPost == 0)
{
$cssClass = array('article','first-post');
}else{
$cssClass = array('article');
}
?>
<article <?php post_class($cssClass); ?> id="post-<?php the_ID(); ?>" itemscope itemtype="http://schema.org/Article">
<?php if ( is_front_page() && is_home() ): ?>
<div class="post-thumbnail">
<?php if ( get_the_post_thumbnail($post_id) != '' ) { ?>
<?php the_post_thumbnail(); ?>
<?php } else { ?>
<img src="<?php echo catch_that_image(); ?>" alt="" />
<?php } ?>
</div>
<article class="post-content">
<header class="post-header">
<div class="post-category"><?php the_category( ', ' ) ?></div>
<h2 class="post-title" itemprop="name"><?php the_title(); ?></h2>
<div class="post-date"><?php echo get_the_date( 'F j, Y' ) ?>.</div>
<div class="post-comment"><?php comments_popup_link( __( '0 comments','adelle-theme' ), __( '1 Comment','adelle-theme' ), __( '% Comments','adelle-theme' ) ); ?></div>
</header>
<?php the_excerpt(); ?>
<footer class="post-footer"></footer><!-- .post-footer -->
</article><!-- .post-content -->
<?php endif; ?>
</article><!-- .article -->
It's better to use a boolean value for $firstPost. For example:
<?php
$getPosts = new WP_Query(array('showposts' => 5, 'orderby' => 1));
if($getPosts->have_posts()):
$firstPost = true;
while($getPosts->have_posts()):
$getPosts->the_post();
$cssClass = '';
if($firstPost)
{
$cssClass = array('article','first-post');
}else{
$cssClass = array('article');
}
?>
<article <?php post_class($cssClass); ?> id="post-<?php the_ID(); ?>" itemscope itemtype="http://schema.org/Article">
<?php if ( is_front_page() && is_home() ): ?>
<div class="post-thumbnail">
<?php if ( get_the_post_thumbnail($post_id) != '' ) { ?>
<?php the_post_thumbnail(); ?>
<?php } else { ?>
<img src="<?php echo catch_that_image(); ?>" alt="" />
<?php } ?>
</div>
<article class="post-content">
<header class="post-header">
<div class="post-category"><?php the_category( ', ' ) ?></div>
<h2 class="post-title" itemprop="name"><?php the_title(); ?></h2>
<div class="post-date"><?php echo get_the_date( 'F j, Y' ) ?>.</div>
<div class="post-comment"><?php comments_popup_link( __( '0 comments','adelle-theme' ), __( '1 Comment','adelle-theme' ), __( '% Comments','adelle-theme' ) ); ?></div>
</header>
<?php the_excerpt(); ?>
<footer class="post-footer"></footer><!-- .post-footer -->
</article><!-- .post-content -->
<?php endif; ?>
</article><!-- .article -->
<?php
$firstPost = false;
endwhile;
endif;
?>

Recent posts from wordpress gallery

I want to display recent images from wordpress gallery in the format like:
<div class="portfolio-item">
<div class="portfolio-overlay">
<img src="img/zoom.png" width="58" height="58" alt="" title="">
</div><!-- .portfolio-overlay-->
<img class="pi-img" src="HERE LINK ON IMAGE" alt="" title="">
</div><!-- .portfolio-item-->
How i should build my loop?
Thank You
If you sort the query results
"SELECT * FROM gallery ORDER BY date ASC LIMIT ?"
// where ? is the number of rows you want to return
you can just do a simple foreach loop:
foreach ($galleryPic as &$pic) {
//your code
}
First of all you should use thumbs for posts (read more about post's thumbs). Than in your category template use this loop:
<?php if ( have_posts() ) : ?>
<?php while ( have_posts() ) : the_post(); ?>
<article class="post">
<header>
<h2><?php the_title(); ?></h2>
<span class="date"><time datetime="<?php the_time('Y-m-d'); ?>"><?php the_time('j F Y'); ?> <?php _e('в');?> <?php the_time('G:i'); ?></time></span>
<span class="author"><?php _e( 'Author:', 'nikita-sp' ); ?> <?php the_author(); ?></span>
<span class="category"><?php _e( 'in category', 'nikita-sp' ); ?> <?php the_category(', '); ?></span>
<span class="comments"><?php comments_popup_link( __( '0 comments', 'nikita-sp' ), __( '1 comment', 'nikita-sp' ), __( '% comments', 'nikita-sp' )); ?></span>
<?php edit_post_link( "Edit", '<span class="edit">', '</span>'); ?>
</header>
<?php the_content('read more...'); ?>
</article>
<?php endwhile; ?>
<?php wp_pagenavi(); ?>
<?php else : ?>
<article>
<h2><?php printf( __( 'SEARCH RESULT for: %s' ), '<span>' . esc_html( get_search_query() ) . '</span>' ); ?></h2>
<p class="center"><?php _e( 'Sorry, nothing was found', 'nikita_sp' ); ?></p>
<?php get_search_form(); ?>
</article>
<?php endif; ?>
Also use thumb output where y want.
<?php if ( has_post_thumbnail()) : ?>
<?php the_post_thumbnail(); ?>
<?php endif; ?>

Only show specific category in wordpress loop?

How Can I only show a specific category in my wordpress index page? Below is my theme code...
Also, when looking at the URL for my category (how I usually get the ID) it seems a strange format..
http://oil.wpengine.com/wp-admin/edit-tags.php?action=edit&taxonomy=category&tag_ID=1179&post_type=post
<?php query_posts( array ( 'Event_News' => 'event-news' ) ); ?>
<?php if (have_posts()) : ?>
<ul class="posts">
<li id="post-<?php the_ID(); ?>">
<?php
get_the_image( array( 'size' => 'loop-main', 'width' => 160, 'height' => 120, 'before' => '<div class="cover">', 'after' => '</div>' ) );
?>
<div class="postcontent">
<h2><?php the_title(); ?></h2>
<div class="postmetadata">
<ul>
<?php if (option::get('display_date') == 'on') { ?><li class="calendar"><time datetime="<?php the_time("Y-m-d"); ?>" pubdate><?php the_time("j F Y"); ?></time></li><?php } ?>
<?php if (option::get('display_author') == 'on') { ?><li class="author"><?php _e('By', 'wpzoom');?> <?php the_author_posts_link(); ?></li><?php } ?>
<?php if (option::get('display_category') == 'on') { ?><li class="category"><?php the_category(', '); ?></li><?php } ?>
<?php if (option::get('display_comments') == 'on') { ?><li class="comments"><?php comments_popup_link( __('0 comments', 'wpzoom'), __('1 comment', 'wpzoom'), __('% comments', 'wpzoom'), '', ''); ?></li><?php } ?>
</ul>
</div><!-- end .postmetadata -->
<?php the_excerpt(); ?>
<p class="more"><?php _e('continue reading »', 'wpzoom');?> <?php edit_post_link( __('Edit this post', 'wpzoom'), ' | ', ''); ?></p>
</div><!-- end .postcontent -->
<div class="cleaner"> </div>
<div class="sep"> </div>
</li><!-- end #post-<?php the_ID(); ?> -->
<?php endwhile; // ?>
</ul>
<div class="cleaner"> </div>
<?php else : ?>
<p class="title"><?php _e('There are no posts in this category', 'wpzoom');?></p>
<?php endif; ?>
<?php get_template_part( 'pagination'); ?>
</div><!-- end .box -->
You can do query_post just before the loop
query_posts( array ( 'category_name' => 'my-category-slug' ) );
If you want posts from more than one category then you can use
query_posts('cat=8,4,3');
8,4,3 are the id for the 3 categories
and after the loop use
wp_reset_query();
For more details view this link
http://codex.wordpress.org/Function_Reference/query_posts#All_Posts_in_a_Category

Categories