Wordpress Custom user Display Page - wordpress

First I want to preface this with the page was working this morning and I left the page open and came back to the information of the user not displaying at all
This page is a custom written authors display page. Anyone who is a contributor of the site is listed here with a bio, Avitar and nickname, can someone please tell me what I am missing because I can't see what has been deleted.
<?php
/*
Template Name: Display Authors
*/
// Get all users order by amount of posts
$allUsers = get_users('orderby=post_count&order=DESC');
$users = array();
// Remove subscribers from the list as they won't write any articles
foreach($allUsers as $currentUser)
{
if(in_array( 'contributor', $currentUser->roles ))
{
$users[] = $currentUser;
}
}
?>
<?php get_header(); ?>
<section class="content-area" role="main">
<h1 class="entry-title"><?php the_title(); ?></h1>
<div class="authors">
<?php foreach($users as $user) { ?>
<div class="page-author author-<?php echo ($curauth->ID & 1 ? 'odd' : 'even'); ?>">
<div class="author-avatar">
<?php echo get_avatar( $curauth->user_email, '200' ); ?>
</div>
<div class="author-info">
<h2 class="author-name"><?php echo $curauth->first_name . ' ' . $curauth->last_name; ?></h2>
<h3 class="author-username"><?php echo $curauth->nickname; ?></h3>
</div>
<div class="clearfix"></div>
<p class="author-descrption"><?php echo get_user_meta($curauth->ID,'description', true); ?></p>
</div>
<?php
}
?>
</div>
</section>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
UPDATE:
So here is an update in my code, and still no luck, all the user information on the page remains empty. So its not showing the Name, Nickname, Bio...nothing
<?php
/*
Template Name: Display Authors
*/
// Get all users order by amount of posts
$allUsers = get_users('orderby=post_count&order=DESC');
$users = array();
// Remove subscribers from the list as they won't write any articles
foreach($allUsers as $currentUser)
{
if(in_array( 'contributor', $currentUser->roles ))
{
$users[] = $currentUser;
}
}
?>
<?php get_header(); ?>
<section class="content-area" role="main">
<h1 class="entry-title"><?php the_title(); ?></h1>
<div class="authors">
<?php foreach($users as $user): ?>
<div class="page-author author-<?php echo ($curauth->ID & 1 ? 'odd' : 'even'); ?>">
<div class="author-avatar">
<?php echo get_avatar( $curauth->user_email, '200' ); ?>
</div>
<div class="author-info">
<h2 class="author-name"><?php echo $curauth->first_name . ' ' . $curauth->last_name; ?></h2>
<h3 class="author-username"><?php echo $curauth->nickname; ?></h3>
</div>
<div class="clearfix"></div>
<p class="author-descrption"><?php echo get_user_meta($curauth->ID, 'description', true); ?></p>
</div>
<?php endforeach; ?>
</div>
</section>
<?php get_sidebar(); ?>
<?php get_footer(); ?>

Related

Worpress sort the posts

In wordpress Tag page(tag.pgp). I have a left menu like this.
<div class="well">
<div>
ALphabatically <br/>
</div>
<div >
By category <br/>
</div>
</div>
I have all the posts on right side in The loop.
<?php
while(have_posts()) {
the_post(); ?>
<div >
<h2><?php the_title(); ?></h2>
<div>
<p>Posted by <?php the_author_posts_link(); ?> on <?php the_time('n.j.y'); ?> in <?php echo get_the_category_list(', '); ?></p>
</div>
<div>
<?php the_excerpt(); ?>
<p>Continue reading »</p>
</div>
</div>
<?php }
echo paginate_links();
?>
How can I sort the post alphabetically and by category by clicking on the links on left.
<?php
$args_product = array(
'post_type' => 'product',
'posts_per_page' => 10,
'orderby'=>'title',
'order'=>'ASC',
'product_cat' => $all_categories_data->slug
);
$loop_product = new WP_Query( $args_product );
while ( $loop_product->have_posts() ) : $loop_product->the_post();
?>
<div >
<h2><?php the_title(); ?></h2>
<div>
<p>Posted by <?php the_author_posts_link(); ?> on <?php the_time('n.j.y'); ?> in <?php echo get_the_category_list(', '); ?></p>
</div>
<div>
<?php the_excerpt(); ?>
<p>Continue reading »</p>
</div>
<div>
<span><?php echo $all_categories_data->name;?></span>
</div>
</div>
<?php endwhile;?>
Use pre_get_posts action hook provided by WordPress.
Then, in your functions.php add the following code below:
function custom_pre_get_posts($query) {
// validate
if(!is_admin() && $query->is_main_query()) {
if(is_archive()) {
$query->set('orderby', 'title'); // order posts by title
$query->set('order', 'ASC'); // and in ascending order
}
}
}
add_action('pre_get_posts', 'custom_pre_get_posts');
For futher information visit https://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts

How to paginate custom post type in wordpress of custom taxonomy

I want to implement pagination on custom post type of a custom taxonomy.
but it is not showing the pagination links only shows on default posts but not working. When I click on next link it redirect me to the index page.
Any help.(New to Wordpress)
Code
<?php $term = get_queried_object();
$taxonomy = get_taxonomy($term->taxonomy);
?>
<div class="panel-heading"><h4><?php echo 'محصولات : '.$term->name;?></h4></div>
<div class="panel-body">
<?php
$paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
$args = array('post_type'=>'my_product', 'taxonomy'=>$taxonomy->name,
'posts_per_page'=> 1,
'term'=>$term->slug, 'paged'=>$paged);
$query = new WP_Query($args);
if ($query->have_posts()) {
while ($query->have_posts()): $query->the_post(); ?>
<div class="thumbnail">
<?php if (has_post_thumbnail()) {
the_post_thumbnail('featured');
} ?>
<div class="caption caption-content">
<h3><?php the_title(); ?></h3>
<p class="text-muted">
<!-- <strong>نویسنده:</strong> <?php //the_author();?> -->
تاریخ: <?php the_date(); ?></p>
<p> <?php the_excerpt(); ?> </p>
<div>
<p class="price-box">
<i class="fa fa-circle"> </i>قیمت:
<?php if (the_field('price') == '') {
// echo "00.00";
} else {
the_field('price');
} ?>
</p>
</div>
</div>
<hr>
</div>
<?php endwhile;
}
else {
echo '<h3>هیچ موردی درین بخش یافت نشد.</h3>';
}
?>
<!-- pagination here -->
<p> <?php
if (function_exists("custom_pagination")):
custom_pagination($custom_query->max_num_pages,"",$paged);
endif;
?>
<?php wp_reset_postdata(); ?>
</p>
</div>

Custom template for category WordPress

Hello I'm new in WordPress custom templates. Can anybody tell me how I can load a different template for a category.
Here is the index.php file
<?php
/**
* The main template file
*
* No comment for now
*
* #package WordPress
* #subpackage site
* #since site
*/
get_header(); ?>
<?php
$strFr='Featured';
$strFinancial='Financial Reports';
$strResearch='Research';
?>
<div id="page-body" role="main">
<div class="container">
<div class="row">
<div class="col-md-12 col-sm-12 col-xs-12 SearchTop">
<form role="search" method="get" id="searchform" class="searchform" action="<?php echo esc_url( home_url( '/' ) ); ?>">
<div class="input-group">
<div class="input-group-addon"><i class="fa fa-search"></i></div>
<input type="text" value="<?php echo get_search_query(); ?>" name="s" id="s" class="form-control customsearchfiled" placeholder="Search of anything related to Site" />
</div>
</form>
</div><!-- SearchTop -->
<div class="col-md-12 col-sm-12 col-xs-12">
<div class="col-md-12 col-sm-12 col-xs-12 mb20 no-gutter">
<div class="col-md-12 col-sm-12 col-xs-12 no-gutter">
<?php if (have_posts()) : ?>
<?php /* Start the Loop */ ?>
<?php while (have_posts()) : the_post(); ?>
<?php get_template_part('content', get_post_format()); ?>
<?php endwhile; ?>
<?php else : ?>
<article id="post-0" class="post no-results not-found">
<?php if (current_user_can('edit_posts')) :
// Show a different message to a logged-in user who can add posts.
?>
<header class="entry-header">
<h1 class="entry-title mt20"><?php _e('No posts to display', 'twentytwelve'); ?></h1>
</header>
<!--<div class="entry-content">
<p><?php //printf(__('Ready to publish your first post? Get started here.', 'twentytwelve'), admin_url('post-new.php')); ?></p>
</div> .entry-content -->
<?php else :
// Show the default message to everyone else.
?>
<header class="entry-header">
<h1 class="entry-title"><?php _e('Nothing Found', 'twentytwelve'); ?></h1>
</header>
<div class="entry-content">
<p><?php _e('Apologies, but no results were found. Perhaps searching will help find a related post.', 'twentytwelve'); ?></p>
<?php get_search_form(); ?>
</div><!-- .entry-content -->
<?php endif; // end current_user_can() check ?>
</article><!-- #post-0 -->
<?php endif; // end have_posts() check ?>
</div>
</div>
</div>
</div>
</div>
</div>
<?php get_footer(); ?>
As far I know the index file is calling content php file that shows the post layout but don't know how to do this. Tried a lot of things but only get php error. I don't know php syntax much
<?php
/**
* Custom template with better structure than WP default.
*
* Used for both single and index/archive/search.
*
* #package WordPress
* #subpackage site
* #since Site 1.0
*/
# for one post
if (is_single()) {
?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<header class="entry-header">
<?php if(function_exists('pf_show_link')){echo pf_show_link();} ?>
<p class="text-center topcategory">
<?php foreach((get_the_category()) as $category) {
echo $category->cat_name . ' ';
}
?>
</p>
<h1 class="entry-title"><?php the_title(); ?></h1>
<p class="postmetadown">By :<span class="bluecolor"><?php the_author(); ?></span> | <span><?php the_date() ?></span></p>
</header>
<div class="entry-content col-md-9 col-sm-9 col-xs-12">
<?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>
<div class="col-md-3 col-sm-3 col-xs-12">
<?php get_sidebar(); ?>
</div>
<?php if (comments_open()) : ?>
<!--<div id="disqus_thread"></div>

<script type="text/javascript">
/* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */
var disqus_shortname = 'site'; // required: replace example with your forum shortname
/* * * DON'T EDIT BELOW THIS LINE * * */
(function () {
var dsq = document.createElement('script');
dsq.type =
'text/javascript';
dsq.async = true;
dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js';
(document.getElementsByTagName('head')[0] ||
document.getElementsByTagName('body')
[0]).appendChild(dsq);
})();
</script>
<noscript>Please enable JavaScript to view the <a href="http://disqus.com/? ref_noscript">comments powered
by Disqus.</a></noscript>
comments powered by <span class="logo- disqus">Disqus</span>-->
<?php endif; ?>
<footer class="entry-meta col-md-12">
<?php if ($googlePlusAcc = get_the_author_meta('googleplus')) { ?>
<?php hr_single_entry_meta(); ?>
<?php } else { ?>
<?php twentytwelve_entry_meta(); ?>
<?php } ?>
<?php edit_post_link(__('Edit', 'twentytwelve'), '<span class="edit-link">', '</span>'); ?>
<?php if (is_singular() && get_the_author_meta('description') && is_multi_author()) : // If a user has filled out their description and this is a multi-author blog, show a bio on their entries. ?>
<div class="author-info">
<div class="author-avatar">
<?php
/** This filter is documented in author.php */
$author_bio_avatar_size = apply_filters('twentytwelve_author_bio_avatar_size', 68);
echo get_avatar(get_the_author_meta('user_email'), $author_bio_avatar_size);
?>
</div>
<!-- .author-avatar -->
<div class="author-description">
<h2><?php printf(__('About %s', 'twentytwelve'), get_the_author()); ?></h2>
<p><?php the_author_meta('description'); ?></p>
<div class="author-link">
<a href="<?php echo esc_url(get_author_posts_url(get_the_author_meta('ID'))); ?>"
rel="author">
<?php printf(__('View all posts by %s <span class="meta-nav">→</span>', 'twentytwelve'), get_the_author()); ?>
</a>
</div>
</div>
</div>
<?php endif; ?>
</footer>
</article>
<?php
#for listing page
} else {
$category = get_the_category();
if (!empty($category))
$category = $category[0];
?>
<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="col-md-4 col-sm-4 col-xs-12 categoryimg no-gutter">
<?php if (has_post_thumbnail()) { ?>
<div class="post-thumbnal-wrapper-multiple">
<?php the_post_thumbnail(); ?>
</div>
<?php } ?>
</div>
<div class="col-md-8 col-sm-8 col-xs-12 categoryContent">
<header class="entry-header">
<h1 class="entry-title">
<?php the_title(); ?>
</h1>
</header>
<?php if (is_search()) : // Only display Excerpts for Search ?>
<div class="entry-summary">
<?php the_excerpt(); ?>
</div>
<?php else : ?>
<div class="entry-content">
<?php the_excerpt_more(); ?>
</div>
<?php endif; ?>
<div class="col-md-12">
<footer class="entry-meta">
<?php twentytwelve_entry_meta(); ?>
<?php edit_post_link(__('Edit', 'twentytwelve'), '<span class="edit-link">', '</span>'); ?>
</footer>
</div>
</div><!-- categoryContent -->
</article>
<div class="clearfix"></div>
<?php
}
If you want a template for the category page, see https://codex.wordpress.org/Category_Templates. If you want a different template for the content, based on the category, you could use (in your content.php)
<?php if (is_category('Category A')) : ?>
<p>This is the text to describe category A</p>
<?php elseif (is_category('Category B')) : ?>
<p>This is the text to describe category B</p>
<?php else : ?>
<p>This is some generic text to describe all other category pages,
I could be left blank</p>
<?php endif; ?>
If there's a lot of difference between categories, I would place this in index.php, and create different templates for every category
Check out this page Template Hierachy. Basically if you want to target a specific category you create a file like so category-{slug}.php {slug} being the category slug you want to target.
I suggest you to read about Wordpress Template Hierarchy in https://developer.wordpress.org/themes/basics/template-hierarchy/
To answer your question, you need to create a category-{id}.php or category-{slug}.php file. in your theme folder (Choose only one)
id = your category ID
slug = your category slug
After creating the file, then you can put your custom code if you want.
Add your code inside archive.php which will list all the posts in the category and add the detail page template inside single.php .
https://codex.wordpress.org/Category_Templates

Wordpress category template is showing posts from all categories instead of specific category posts

I have an archive page that's set up to display category specific posts. However, instead of showing only the posts from a given category on the category page, it's showing all posts. For an example, see here.
Here's the code I'm using on my archive.php page. I know it's improper use of the loop, but I'm not sure how to fix it. Thanks for the help.
<?php get_header(); ?>
<div id="content">
<div id="inner-content" class="wrap clearfix">
<h1 class="blogTitle" style="margin:10px 0 3px 0;">Blog Title</h1>
<nav class="blogNav" role="navigation">
<?php bones_blog_nav(); // Adjust using Menus in Wordpress Admin ?>
</nav>
<div id="main" class="eightcol first clearfix" role="main">
<div class="catwhiteBg">
<?php if (is_category()) { ?>
<h1 class="catTitle">
<span><?php _e("", "bonestheme"); ?></span> <?php single_cat_title(); ?>
</h1>
<?php echo category_description( $category_id ); ?>
<?php } elseif (is_author()) { ?>
<div class="authorTop">
<?php
$curauth = (get_query_var('author_name')) ? get_user_by('slug', get_query_var('author_name')) : get_userdata(get_query_var('author'));
?>
<div class="author-pic"><?php echo get_avatar( $curauth->user_email, '80' ); ?></div>
<div class="author-name"><span style="font-weight: 200; color: #575757;">POSTS BY:</span>
<?php echo $curauth->first_name; ?> <?php echo $curauth->last_name; ?>
</div>
<div class="author-bio"><?php echo $curauth->description; ?></div>
<div class="author-twitter"><span>twitter</span></div>
</div>
<?php } elseif (is_day()) { ?>
<h1 class="archive-title h2">
<span><?php _e("Daily Archives:", "bonestheme"); ?></span> <?php the_time('l, F j, Y'); ?>
</h1>
<?php } elseif (is_month()) { ?>
<h1 class="archive-title h2">
<span><?php _e("Monthly Archives:", "bonestheme"); ?></span> <?php the_time('F Y'); ?>
</h1>
<?php } elseif (is_year()) { ?>
<h1 class="archive-title h2">
<span><?php _e("Yearly Archives:", "bonestheme"); ?></span> <?php the_time('Y'); ?>
</h1>
<?php } ?>
</div>
<div class="psts">
<?php
global $wp_query;
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
if ( get_query_var('paged') ) {
$paged = get_query_var('paged');
} elseif ( get_query_var('page') ) {
$paged = get_query_var('page');
} else {
$paged = 1;
}
query_posts(array('posts_per_page' => '8','paged'=>$paged));
?>
<?php
$count = 1;
while (have_posts()) : the_post(); ?>
<div class="sixcol small pst<?php if ((isset($count)) && ($count % 2 == 0 )) { echo ' last';} // same logic to add class of last to last item in row of two ?>" id="post-<?php the_ID(); ?>">
<article id="post-<?php the_ID(); ?>" role="article">
<div class="thumb-wrapper mobile">
<?php if(has_post_thumbnail()) { $image_src = wp_get_attachment_image_src( get_post_thumbnail_id(),'post-thumb' ); echo '<img src="' . $image_src[0] . '" width="100%" class="post-thumb" />'; } ?>
<header class="post-thumb-header">
<h2 class="post-title"><?php the_title(); ?></h2>
</header> <!-- end article header -->
<p class="meta"><?php the_category(', '); ?></p>
</div>
<section class="mobile-content">
<?php the_excerpt(); ?>
</section>
</article> <!-- end article -->
</div>
<?php $count++; ?>
<?php endwhile; ?>
<nav class="wp-prev-next">
<?php echo rb_pagination(); ?>
</nav>
</div> <!-- end .psts -->
</div> <!-- end #main -->
<?php get_sidebar(); // sidebar 1 ?>
</div> <!-- end #inner-content -->
</div> <!-- end #content -->
<?php get_footer(); ?>
I think you're overriding the original query with this line:
query_posts(array('posts_per_page' => '8','paged'=>$paged));
Can you swap this line with this, and let me know the results?
global $query_string;
query_posts( $query_string . "&posts_per_page=8&paged=$paged" );
if that fails try this:
query_posts(array('posts_per_page' => '8','paged'=>$paged, 'cat' => $category_id ));

the_author is empty when not logged in

Is there a reason why the_author should return an empty string on the first page when the user is not logged in, but return the author name just as it should when more posts are loaded through AJAX ?
The loop is the same in both cases.
Please help me resolve this issue as I'm clueless and I need it fixed ASAP to launch my site.
Here's the whole index.php:
<?php
get_header();
get_sidebar();
?>
<!-- MAIN DIV -->
<div id='content_and_floater'>
<?php get_template_part('social_floater'); ?>
<div id='content'>
<?php get_template_part('loop'); ?>
</div>
</div>
<?php get_template_part('loader'); ?>
<!-- MAIN DIV -->
<?php
get_footer();
?>
And here's how the infinitePaginator calls the loop in functions.php (the function is called when scrolled down to the bottom or the loader link is clicked):
function wp_infinitepaginate(){
$loopFile = $_POST['loop_file'];
$paged = $_POST['page_no'];
$posts_per_page = get_option('posts_per_page');
# Load the posts
query_posts(array('paged' => $paged ));
get_template_part( $loopFile );
exit;
}
You can see the behaviour at test.nowillnoskill.net.
In single posts it's not working either. My guess is that query_posts(array('paged' => $paged )); changed something in the query, but I don't know what is it.
I tried to insert setup_postdata($post); just after the_post() in loop.php as I found that worked for someone, but it doesn't for me.
I also tried to insert
query_posts(array('paged' => 1 ));
before calling the loop file in index.php, but no posts at all were shown.
Here is my loop.php:
<?php while ( have_posts() ) : the_post() ?>
<!-- POST1 -->
<article class='post'>
<header class='post_header'>
<?php
global $current_user;
$current_user = wp_get_current_user();
if (!empty($current_user)) {
$pid = get_the_id();
$uid = $current_user->ID;
$title = (is_favorite($pid, $uid)) ?
'Remove from favorites' :
'Add to favorites';
$trans = (is_favorite($pid, $uid)) ?
'' :
' transparent';
?>
<div>
<h2>
<a href="<?php the_permalink(); ?>">
<?php the_title(); ?>
</a>
</h2>
<?php if (is_user_logged_in()) { ?>
<a title='<?php echo $title ?>' class='post_favorite' href='#' alt='fpid=<?php echo $pid ?>uid=<?php echo $uid ?>'>
<span class='symbol<?php echo $trans ?>'>R</span>
</a>
<?php } ?>
</div>
<div class='post_header_div'>
<strong class='post_category'>
<?php echo get_the_category_list(', '); ?>
</strong>
<strong class='post_author'>
<span class='symbol'>U</span>
<?php the_author(); ?>
</strong>
</div>
<div>
<span class='post_author'>
<?php edit_post_link('[edit]'); ?>
</span>
</div>
<?php } ?>
</header>
<figure class='post_image'>
<!--<img src='design/img/flashkick.png' alt='logo' />-->
<?php the_post_thumbnail(); ?>
</figure>
<div class='post_perex'>
<?php the_content('Read more'); ?>
</div>
<div class='space'></div>
<footer class='post_footer'>
<div class='post_footer_top'>
<div class='post_tags'>
<?php the_tags('', '', ''); ?>
</div>
<div class='post_time'>
<time datetime="<?php the_time('Y-m-d'); ?>" pubdate>
<span class='symbol'>P </span>
<?php relative_post_the_date(); ?>
</time>
</div>
</div>
</footer>
<div class='space'></div>
</article>
<?php endwhile; ?>
Author informations are given by Wordpress in post informations.
Try to do a var_dump on your query_posts result, you should find where the author name is stored, to display it properly.
Can you please show your loop template ? At least the part displaying the author.

Resources