Editing Theme to apply Co-Authors Plus - php

I'm trying to implement the Co-Authors Plus Plugin. It says that you will need to change some PHP in the theme. It outlines the changes on this Link.
I believe I have found where I would need to change it in my theme. In a file called "post-author-info.php".
This is what it looks like:
<?php
/**
* Post Author Info
*
* #package WP Journal
* #subpackage Include
*/
?>
<div id="authorinfo" class="columns alpha omega marT30 marB20">
<?php echo get_avatar( get_the_author_meta('email'), '80' ); ?>
<h5 class="marB10"><?php _e('By', 'contempo'); ?>: <?php the_author(); ?></h5>
<p><?php the_author_meta('description'); ?></p>
<div class="clear"></div>
</div>
Just adding this line <?php if ( function_exists( 'coauthors' ) ) { coauthors(); } else { the_author(); } ?> seems to give me something that I want. Both "Admin" And "Andrew Gable" are displayed.
Here is the screen shot when changes are applied.
I'm unsure on how to get it to link correctly, and how to handle photos and multiple Bio's.
Thanks

You might wanna post this question at https://wordpress.stackexchange.com/
I had a similar issue and resolved it this way:
global $post;
$author_id=$post->post_author;
foreach( get_coauthors() as $coauthor ): ?>
<div class="entry-author co-author">
<?php echo get_avatar( $coauthor->user_email, '96' ); ?>
<h3 class="author vcard"><span class="fn"><?php echo $coauthor->display_name; ?></span></h3>
<p class="author-bio"><?php echo $coauthor->description; ?></p>
<div class="clear"></div>
</div><!-- .entry-author co-author -->
<?php endforeach;
Be sure to use that global $post;and the foreach-loop.
This function will display an author box containing author image/avatar, author name with link to its archive, and the author's bio. You might want to use your own theme's CSS classes though.

Related

Wordpress Author details not displaying on landing page

In Wordpress the default behavior is that all posts are displayed on the landing of the domain(myblogsite.com) but the post's displayed don't show the author's name or gravatar. This is only shown if the user selects an individual post(myblogsite.com/date/title). Is there a plugin or fix(or hack) to display the author name and gravatar for posts that are displayed on the landing page?
I've looked at similar questions on Wordpress' forum and the solutions I've tried did not work.
As an example:
Add this after or before <?php the_content(''); ?>
<?php if ($lw_post_author == "true" && is_attachment() != TRUE) : ?>
<div class="about_author">
<div class="alignleft"><?php echo get_avatar( get_the_author_id(), '28' ); ?></div>
<div class="alignleft"><h4><?php _e('Author','lightword'); ?>: <?php the_author(); ?></h4>
<?php the_author_description(); if(!get_the_author_description()) _e('No description. Please complete your profile.','lightword'); ?></div><div class="clear"></div> </div>
<?php endif; ?>
I am using Wordpress 4.4.2

Want to target specific posts in a loop

My Wordpress site has a loop that creates posts, and I want to target specific posts to change their css values.
html - index.php
<?php /* Start the Loop */ ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php
get_template_part( 'content' );
?>
<?php endwhile; ?>
content.php
<?php
if (has_post_thumbnail()) {
$thumbnail_data = wp_get_attachment_image_src( get_post_thumbnail_id( get_the_ID() ), 'my-fun-size' );
$thumbnail_url = $thumbnail_data[0];
}
?>
<article id="post-<?php the_ID(); ?>" style="background-image:url('<?php echo $thumbnail_url ?>')" <?php post_class('container-fluid'); ?> >
<div class="container-fluid">
<div class="col-md-12 text-cell">
<h2><?php the_title(); ?></h2>
<?php the_category(', '); ?>
</div>
</div>
</article><!-- /#post -->
It was suggested that I use 'get_post_meta ...' but I am not familiar with how to use it. I just want to change css values (padding, font-size, etc) for different posts
I would suggest using Custom Fields for this, so that you can define the values in the post itself, as opposed to having to edit the code every time you add a new post.
In the post, make sure you have Custom Fields visible (Togglable from screen options at the top)
Then make a field called "Alignment" or whatever you prefer and assign a value to it. (for example 'left')
Then you can add a conditional in the loop.
<?php $alignment = get_post_meta(get_the_ID(),'Alignment',true);
if($alignment) == 'left'):?>
<p>Do stuff and things here...</p>
<?php endif;?>
You can read more about it here: https://codex.wordpress.org/Custom_Fields
Hopefully that will work for you. If you want to get fancier with it, I would suggest looking at the Advanced Custom Fields plugin, which allows a lot more flexibility and options.
EDIT from comments:
1st option:
Set a field of "ExtraCSS" to "color:green;"
<?php $extraCSS = get_post_meta(get_the_ID(),'ExtraCSS',true);?>
<article id="post-<?php the_ID(); ?>" style="background-image:url('<?php echo $thumbnail_url ?>'); <?php echo $extraCSS;?>" <?php post_class('container-fluid'); ?> >
2nd option:
(In your stylesheet:)
article:nth-child(2n+0)
{
color:green;
}
http://www.w3schools.com/cssref/sel_nth-child.asp

Only run wordpress query in one section

I currently have a setup where i have the following files being called in order.
in my header.php, i am calling <?php get_theme_part( 'front', 'current-front' ); ?>
The contents of that file are
<?php query_posts("showposts=1&cat=6"); ?>
<?php
/**
* The template for displaying list of recent posts on the front page.
*
* #package WordPress
* #subpackage xxx
* #since xxx 1.0
*/
if ( !have_posts() )
return;
?>
<div class="front-current-print">
<div class="current-print">
<?php while ( have_posts() ) : the_post(); ?>
<?php get_theme_part( 'current-print' ); ?>
<?php endwhile; ?>
</div>
</div>
That file is calling current-print.php, which has this code:
<?php
?><article <?php post_class( 'compact bg-secondary' ); ?>>
<?php the_post_thumbnail( 'current-print' ); ?>
<h5 class="title">
<a class="inverse" href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
</h5>
<div class="entry-summary"><?php the_excerpt(); ?></div>
<?php the_post_episode(); ?>
</article>
This code allows me to have a thumbnail for a specific post from a specific category.
This works fine on the front page, but it seems that for all inside pages and posts it will only display the category and the post. I've tried taking out <?php query_posts("showposts=1&cat=6"); ?> and the posts come through fine. Is there any way i can have that script only run in the header and not affect the rest of the site?
You need to use wp_reset_query();:
wp_reset_query() restores the $wp_query and global post data to the original main query. This function should be called after query_posts(), if you must use that function.
See: http://codex.wordpress.org/Function_Reference/wp_reset_query
In your case this would be:
<?php query_posts("showposts=1&cat=6"); ?>
<?php
/**
* The template for displaying list of recent posts on the front page.
*
* #package WordPress
* #subpackage xxx
* #since xxx 1.0
*/
if ( !have_posts() )
return;
?>
<div class="front-current-print">
<div class="current-print">
<?php while ( have_posts() ) : the_post(); ?>
<?php get_theme_part( 'current-print' ); ?>
<?php endwhile; ?>
</div>
</div>
<?php wp_reset_query(); ?>

How to create taxonomy archive that can display list of post of that taxonomy

I am creating wordpress template that can use custom taxonomy(like categories). i want that every time i click the post's category it shows the list of post of that category. here is my category.php.
<?php get_header(); ?>
<body>
<div id="container">
<div id="header"><h1><?php bloginfo('name'); ?></h1></div>
<div id="menu"><?php wp_nav_menu( array( 'sort_column' => 'menu_order', 'menu_class' => 'nav', 'theme_location' => 'primary-menu' ) ); ?></div>
<div id="content">
<div id="blog">
<?php $post = $posts[0]; // Hack. Set $post so that the_date() works. ?>
<?php /* If this is a category archive */ if (is_category()) { ?>
<h2>Archive for the ‘<?php single_cat_title(); ?>’ Category:</h2>
<?php /* If this is a tag archive */ } elseif( is_tag() ) { ?>
<h2>Posts Tagged ‘<?php single_tag_title(); ?>’</h2>
<?php /* If this is a daily archive */ } elseif (is_day()) { ?>
<h2>Archive for <?php the_time('F jS, Y'); ?>:</h2>
<?php /* If this is a monthly archive */ } elseif (is_month()) { ?>
<h2>Archive for <?php the_time('F, Y'); ?>:</h2>
<?php /* If this is a yearly archive */ } elseif (is_year()) { ?>
<h2>Archive for <?php the_time('Y'); ?>:</h2>
<?php /* If this is an author archive */ } elseif (is_author()) { ?>
<h2>Author Archive</h2>
<?php /* If this is a paged archive */ } elseif (isset($_GET['paged']) && !empty($_GET['paged'])) { ?>
<h2>Blog Archives</h2>
<?php } ?>
<?php if(have_posts()) : ?><?php while(have_posts()) : the_post(); ?>
<div class="post">
<br>
<br>
<h3><?php the_title(); ?></h3>
<div class="entry">
<br>
<?php the_content(); ?>
<p class="postmetadata">
<?php _e('Filed under:'); ?> <?php the_category(', ') ?> <?php _e('by'); ?> <?php the_author(); ?><br />
<?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?> <?php edit_post_link('Edit', ' | ', ''); ?>
</p>
</div>
<br>
<hr>
<br>
</div>
<?php endwhile; ?>
<div class="navigation">
<?php posts_nav_link(); ?>
</div>
<?php endif; ?>
</div>
</div>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
I already searching whole day and nothing working. what custom taxonomy template archive name i should use ? what code that i must change in this category.php to fulfill the needs of displaying the custom taxonomy archives(that can display all post that related to the clicked taxonomy) ?
You should create a taxonomy.php for terms belonging to a custom taxonomy. You can just simply copy the template above and call it taxonomy.php
EDIT
You have one big fundamental flaw when registering your two taxonomies.
You cannot have white spaces in your custom taxonomy names, and this applies to function names and custom post type names as well. The following rules apply, and there is no work around these.
names cannot contain white spaces or any special character.
only lowercase letters are allowed
if a name contains more that one word, you can only use underscores (_) to separate them. Do not use hyphens (-) as you will have issues later on
see the codex for the limitation on character count for taxonomies and post types
So, in short, kategori berita and tag berita is invalid names. They should be kategori_berita and tag_berita. As I said, there are no work around to this problem. Your only solutions is to change your taxonomy names accordingly
When the name of your taxonomy is "roles", you could create a file called taxonomy-roles.php. You can expand this with the term (in this example "ceo") like this as well: taxonomy-roles-ceo.php.
As #pietergoosen said you can just copy paste the code that you provided with in those files.
For more info on this you can check out the following link: http://codex.wordpress.org/Template_Hierarchy#Custom_Taxonomies_display

Serious php get_template_part() Wordpress issues - easy fix?

I am needing some serious Wordpress expertise from others. I am in the process of building a custom theme, read about the get_template_part() method and decided that would help in cleaning up and organizing my code. I updated my theme to use this method several places and now the site is completely broken...not a single thing will load!! :( I would really appreciate any help! I will copy and paste a few of the php files below. Maybe someone with more experience with using this method can point out the problem. THANKS!
page.php
<?php get_header(); ?>
<div id="content" class="content">
<?php while ( have_posts() ) : the_post(); ?>
<!-- About page -->
<?php if (is_page('about')) ?>
<?php get_template_part( 'page', 'about' ); ?>
<!-- Media & Gallery page -->
<?php if (is_page('media-gallery')) ?>
<?php get_template_part( 'page', 'mediagallery' ); ?>
<?php endwhile; // end of the loop. ?>
</div> <!--/end content -->
<?php get_footer(); ?>
page-about.php
<div id="about">
<div class="text">
<h2 class="about"><?php echo get_the_title(); ?></h2>
<?php the_content(); ?>
</div>
</div>
page-mediagallery.php
<div id="pic-gallery">
<?php include_once 'includes/pwaplusphp/albums.php'; ?>
</div>
index.php
<?php get_header(); ?>
<div class="content">
<?php if ( have_posts() ) : ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'content', get_post_format() ); ?>
<br class="clr"/>
<?php endwhile; ?>
<?php content_nav( 'nav-below' ); ?>
<?php else : ?>
<article id="post-0" class="post no-results not-found">
<header class="entry-header">
<h3 class="blog"><?php _e( 'Nothing Found' ); ?></h3>
</header> <!-- .entry-header -->
<div class="entry-content">
<p><?php _e( 'Apologies, but no results were found for the requested archive. Perhaps searching will help find a related post.'); ?></p>
</div> <!-- .entry-content -->
</article> <!-- #post-0 -->
<?php endif; ?>
</div> <!--/end content -->
<?php get_footer(); ?>
content-gallery.php
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<div class="post-date"><?php the_time(get_option('date_format')); ?></div>
<h3 class="blog"><?php the_title(); ?></h3>
<div class="post-content"><?php the_content(); ?></div>
</div>
Any thoughts why these may not be working? All of these files are under the root directory of the theme so the get_template_part() method should be finding all of the files. What's weird is no code is being spit out by Wordpress. aka. Since I've started using this method, not a single line of code is spit out in my browser when I inspect the source.
I am using the newest version of Wordpress and Google Chrome for my browser.
I also have this code at the top of each of my .php files, but that shouldn't mess up anything because it's commented as seen below:
<?php
/**
* I put a description of what the file does here.
*
* #package Keynote_WP_Themes
* #subpackage Rhymz_Suhreal
* #copyright Rhymz Suhreal, 2012
* #author Kyle Affolder <myemail#example.com>
*/
?>
I don't have the slightest clue as to what I'm doing wrong. :(
Ideas coding friends?!
Using your page-about.php as an example, you should be calling it like this in the template it's to be place in:
<?php get_template_part( "page-about" ); ?>
The template needs to be in the root of your theme directory so you can use "page-about" without the .php, and not have to indicate the location/directory the file would otherwise be located.
I've run into this a few times before as well - I can't really explain why yet as I'm still digging through the documentation, but it seems you can't call template parts this way when you are inside a post loop ;)
Anytime you are inside the loop, try using this instead:
<?php include(get_query_template('page-about')); ?>

Categories