The author doesn't show in single.php - php

I am in the process of creating a theme and I can't get the author to be displayed on the single.php page. It's displayed lower on the site but doesn't seem to show in the first call under the headline.
<header class="intro-header" style="background-image: url('http://i.imgur.com/ZyZMhQv.jpg')">
<div class="container">
<div class="row">
<div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
<div class="site-heading">
<h1><?php the_title(); ?></h1>
<hr class="small">
<span class="subheading">Posted by <?php the_author(); ?> on <?php the_time('F jS, Y'); ?></span>
<div id="avatar" class="row text-center"><?php echo get_avatar( $post->post_author, 92 ); ?> </div>
</div>
</div>
</div>
</div>
</header>
The second time it's called within the loop it works fine.
<div class="row">
<div class="col-md-6 col-md-offset-3">
<div class="panel panel-default panel-body">
<?php while(have_posts()) : the_post(); ?>
<p> Posted by <?php the_author(); ?> on <?php the_time('F jS, Y'); ?> </p>
<p> <?php the_content(''); ?> </p>
<?php endwhile; wp_reset_query(); ?>
</div>
</div>
Why doesn't it show up the first time it's called?

as per the codex - it must be within the loop.

Related

Bootstrap columns and Wordpress Posts

So I'm converting bootstrap site to Wordpress and post cards don't want to stack horizontally... I know there should be foreach loop which will loop through posts but I don't know how to set it up...
<?php while(have_posts()) {
the_post();
?>
<section id="blog" class="py-3">
<div class="container">
<div class="row">
<div class="col-md-4">
<div class="card-columns">
<div class="card">
<img src="<?php the_post_thumbnail_url('medium')?>" alt="" class="img-fluid card-img-top">
<div class="card-body">
<h4 class="card-title">
<?php the_title(); ?>
</h4>
<small class="text-muted">Written by <?php the_author_posts_link(); ?></small>
<hr>
<p class="card-text"><?php the_excerpt(); ?></p>
</div>
</div>
</div>
</div>
</div>
</section>
<?php } ?>
while is also a loop. Inside the loop, you can just put the repeated code. As I've understood your code than you need to something like this:
<section id="blog" class="py-3">
<div class="container">
<div class="row">
<?php while( have_posts() ) {
the_post();
?>
<div class="col-md-4">
<div class="card-columns">
<div class="card">
<img src="<?php the_post_thumbnail_url('medium')?>" alt="" class="img-fluid card-img-top">
<div class="card-body">
<h4 class="card-title">
<?php the_title(); ?>
</h4>
<small class="text-muted">Written by <?php the_author_posts_link(); ?></small>
<hr>
<p class="card-text"><?php the_excerpt(); ?></p>
</div>
</div>
</div>
<?php } ?>
</div>
</div>
</section>
Also, better to move code for one block to another file for example partials/post.php:
<div class="col-md-4">
<div class="card-columns">
<div class="card">
<img src="<?php the_post_thumbnail_url('medium')?>" alt="" class="img-fluid card-img-top">
<div class="card-body">
<h4 class="card-title">
<?php the_title(); ?>
</h4>
<small class="text-muted">Written by <?php the_author_posts_link(); ?></small>
<hr>
<p class="card-text"><?php the_excerpt(); ?></p>
</div>
</div>
</div>
</div>
And update your current file:
<section id="blog" class="py-3">
<div class="container">
<div class="row">
<?php while( have_posts() ) {
the_post();
get_template_part( 'partials/post' );
} ?>
</div>
</div>
</section>

Wordpress - How to use Ajax Load More plugin

I'm developing a website in wordpress and I want to load more news when scrolling but I already have a html structure and when I put ajax load more it put own structure and I don' want that.
I'm using the Ajax Load More plugin.
So, How can I use Ajax load more with this html structure:
<?php
$posts = get_posts(['cat' => get_cat_ID("news")]);
foreach($posts as $post){
setup_postdata($post);
?>
<div class="col-xs-12 col-sm-6 col-md-4">
<a class="news-link" href="<?php the_permalink() ?>">
<div class="news">
<div class="image">
<?php the_post_thumbnail('thumbnail') ?>
<div class="mask">
<div class="icon">
<i class="icon-plus"></i>
</div>
</div>
</div>
<div class="title">
<span>
<?php the_title(); ?>
</span>
</div>
<div class="excerpt">
<p class="date">
<?php echo get_the_date('Y-m-d'); ?>
</p>
</div>
<div class="excerpt">
<p>
<?php the_excerpt(); ?>
</p>
</div>
</div>
</a>
</div>
<?php
wp_reset_postdata();
} ?>
If i put this shortcode it shows but not with the structure that i want.
[ajax_load_more id="7279302844" container_type="div" post_type="post" category="news"]
Thank you

im trying to remove the double post image

when you go to:
http://dageniusmarketer.com/
you will see the posts have 2 images. I'm trying to remove the one on the bottom.
I initially added
<?php the_post_thumbnail( $size, $attr ); ?>
for the main post image, as I wasn't getting the placement I wanted, which was ABOVE the post statistics. Now that I have it above the statistics, I still have the original image, and I want to remove it.
I'm trying to play with the class .wp-image,
but that isn't giving me any sort of luck. I just want to remove the 2nd duplicate image underneath the statistics and keep whatever other images I may wish to write into my post body in the future. How do I do this?
edit: here is my php code:
<?php get_header(); ?>
<div id="main">
<div id="content">
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<!-- item -->
<div class="item entry" id="post-<?php the_ID(); ?>">
<div class="itemhead">
<h1>
<?php the_title(); ?>
</h1>
<?php the_post_thumbnail( $size, $attr ); ?>
<div class="postStatsContainer">
<div class="postViews">100 Views</div>
<div class="slash"></div>
<div class="postShares">100 Shares</div>
<div class="slash"></div>
<div class="postComments">100 Comments</div>
<div class="slash"></div>
<div class="date"><?php the_time('M jS, Y') ?></div>
</div>
<div style="clear: both"></div>
<!--<div class="readMore_Container">-->
<?php the_content('Read More »'); ?>
<div class="postCounter">
<i class="fa fa-pencil-square-o fa-2x"></i>#200
</div>
<div class="metadata" style="clear:both;">
<div class="TagIcon"></div>
Filed under
<span class="category"><?php the_category(', ') ?></span> |
<?php edit_post_link('Edit', '', ' | '); ?>
<?php comments_popup_link('Comment (0)', ' Comment (1)', 'Comments (%)'); ?>
</div>
<div style="clear:both;"></div>
<div style="clear:both;"></div>
</div>
</div>
<!-- end item -->
<?php comments_template(); // Get wp-comments.php template ?>
<?php endwhile; ?>
<div class="navigation">
<div class="alignleft"><?php next_posts_link('« Previous Entries') ?></div>
<div class="alignright"><?php previous_posts_link('Next Entries »') ?></div>
<p> </p>
</div>
<?php else : ?>
<h2 class="center">Not Found</h2>
<p class="center">Sorry, but you are looking for something that isn't here.</p>
<?php endif; ?>
<!-- end content -->
</div>
<div id="primary">
<?php include(TEMPLATEPATH."/l_sidebar.php");?>
</div>
<div id="secondary">
<?php include(TEMPLATEPATH."/r_sidebar.php");?>
</div>
<?php get_footer(); ?>

Wordpress - Search page for custom post type

I started to use Wordpress for a project, and using the following plugin Download Monitor
My page listings based on taxonomies all work fine, but im struggling with the search results
My form
<form role="search" method="get" class="right" id="download-form" action="<?php echo home_url( '/' ); ?>">
<div>
<input type="text" value="" name="dlm_download" id="dlm_download" placeholder="Search" />
</div>
</form>
So when i search and get the results mywebsite.com/?dlm_download=querythe home page gets show.
Than i created after research search-dlm_download.php, still get redirected to home.
Than i found this thread How to create a custom search for custom post type on wordpress exchange that does not work either.
So i am a bit stuck, could someone please point out what i am doing wrong?
EDIT:
search-dlm_download.php
<?php get_header(); ?>
<?php if (have_posts()) : ?>
<div id="page" class="border-top clearfix">
<div id="subtitle">
<h1><?php _e("Search Results for '$s'", 'framework') ?></h1>
<div id="breadcrumb"><?php the_breadcrumb(); ?></div>
<div class="hr4"><span class="seperator"></span><span class="lightborder"></span></div>
</div>
<div id="content-part">
<?php while (have_posts()) : the_post(); ?>
<div class="search-entry post-entry">
<h2><?php the_title(); ?></h2>
<div class="meta">
<?php _e('Posted on', 'framework'); ?> <strong><?php the_time('d.m.Y'); ?></strong> · <?php _e('Posted in', 'framework'); ?> <?php the_category(', ') ?>
</div>
<div class="entry">
<?php wpe_excerpt('wpe_excerptlength_blog', 'wpe_excerptmore'); ?>
</div>
<div class="entry-footer"></div>
</div>
<?php endwhile; ?>
<?php include (TEMPLATEPATH . '/framework/functions/nav.php' ); ?>
</div>
<div id="sidebar" class="sidebar-right">
<?php get_sidebar(); ?>
</div>
</div>
<?php else : ?>
<div id="page" class="border-top clearfix">
<div id="subtitle">
<h1><?php _e('No Results Found', 'framework') ?></h1>
<div id="breadcrumb"><?php the_breadcrumb(); ?></div>
<div class="hr4"><span class="seperator"></span><span class="lightborder"></span></div>
</div>
<div class="wrap clearfix">
<div id="content-part">
<div class="no-search-result">
<p><?php _e("Sorry, no results found. Try different words to describe what you are looking for.", 'framework') ?></p>
</div>
</div>
<div id="sidebar" class="sidebar-right">
<?php get_sidebar(); ?>
</div>
</div>
</div>
<?php endif; ?>
<?php get_footer(); ?>
Okay, found a solution by breaking the default search to 2 parts
If anybody needs it in the future you can find it here Create multiple search templates for custom post types

"Previous Posts" is Not Working

For some reason, when you click "Previous Posts" on my wordpress blog, the page URL changes, but the first ten posts are displayed again.
You can see the issue here: http://onedirectionconnection.com/ and then page two http://onedirectionconnection.com/page/2/#sthash.0SQiq9AP.dpbs (that's another thing - I'm not sure why that code is being added at the end of the following page's URL)...
Anyway, here is the code I'm using for my front page template saved in a file called front-page.php
<?php
/*
Template Name: Splash Page
*/
get_header(); ?>
<div id="primary" class="content-area">
<main id="main" class="site-main" role="main">
<div class="section-container">
<h1 class="section-title">Latest News</h1>
</div>
<?php $my_query = new WP_Query('showposts=1'); ?>
<?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
<h1 class="entry-title bottommargin big">
<?php the_title(); ?>
</h1>
<div class="entry-content">
<?php the_content(); ?>
</div>
<div class="row">
<div class="col-md-12">
<footer class="row no-margin">
<div class="col-md-3 meta-entry">
Author: <br>
<?php the_author_link(); ?>
</div>
<div class="col-md-3 meta-entry">
Posted On:<br>
<?php the_time('F j, Y'); ?>
</div>
<div class="col-md-3 meta-entry">
Categorized:<br>
<?php echo get_the_category_list(', '); ?>
</div>
<div class="col-md-3 meta-entry-right">
Discussion:<br>
<?php comments_number(); ?>
</div>
</footer>
</div>
</div>
<?php endwhile; ?>
<div class="section-container">
<h1 class="section-title">More News</h1>
</div>
<?php
$custom_query = new WP_Query(array(
'posts_per_page' => 10,
'offset' => 1,
'paged' => (get_query_var('paged')) ? get_query_var('paged') : 1
));
?>
<?php while ($custom_query->have_posts()) : $custom_query->the_post(); ?>
<div class="row topmargin">
<div class="col-md-3 no-padding center">
<?php the_post_thumbnail('thumbnail', array('class' => 'img-thumbnail img-responsive')); ?>
</div>
<div class="col-md-9">
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<header class="entry-header">
<h1 class="entry-title">
<?php the_title(); ?>
</h1>
</header><!-- .entry-header -->
<div class="entry-content">
<?php the_excerpt(); ?>
<?php
wp_link_pages( array(
'before' => '<div class="page-links">' . __( 'Pages:', 'professional1d' ),
'after' => '</div>',
) );
?>
</div><!-- .entry-content -->
</article><!-- #post-## -->
<?php
// If comments are open or we have at least one comment, load up the comment template
if ( comments_open() || '0' != get_comments_number() )
comments_template();
?>
</div>
</div>
<footer class="row no-margin">
<div class="col-md-3 meta-entry">
Author: <br>
<?php the_author_link(); ?>
</div>
<div class="col-md-3 meta-entry">
Posted On:<br>
<?php the_time('F j, Y'); ?>
</div>
<div class="col-md-3 meta-entry">
Categorized:<br>
<?php echo get_the_category_list(', '); ?>
</div>
<div class="col-md-3 meta-entry-right">
Discussion:<br>
<?php comments_number(); ?>
</div>
</footer>
<?php endwhile; // end of the loop. ?>
<div class="center">
<?php posts_nav_link(); ?>
</div>
</main><!-- #main -->
</div><!-- #primary -->
</div>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
Everything seems pretty standard so I really have no clue what the issue is. If anyone could help me out with this issue, it would be greatly appreciated!
After comparing two - three post/pages of your blog. i think, it add the # tag at the end of url. this happen only after loading the entire page. which means it is added by one of your plugin. the plugin may be for "load fresh content from the server instead of the local browser cache"
so first deactivate the plugin you installed for this kind of features

Categories