Wordpress: Include custom_fields (Book author) in search results - wordpress

I am using TwentyEleven as my base theme which I have skinned.
In my Content.php file, the search results looks something like this
<?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>', 'twentyeleven' ) ); ?>
<?php wp_link_pages( array( 'before' => '<div class="page-link"><span>' . __( 'Pages:', 'twentyeleven' ) . '</span>', 'after' => '</div>' ) ); ?>
</div><!-- .entry-content -->
<?php endif; ?>
I am trying to pull the "Author" Meta key/value pairs to return in my search results along with the Post Title and Post Content like so:
<?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>', 'twentyeleven' ) ); ?>
<?php get_post_meta(get_the_ID(), _wpsc_author, true); ?>
<?php wp_link_pages( array( 'before' => '<div class="page-link"><span>' . __( 'Pages:', 'twentyeleven' ) . '</span>', 'after' => '</div>' ) ); ?>
</div><!-- .entry-content -->
<?php endif; ?>
Note the line:
<?php get_post_meta(get_the_ID(), _wpsc_author, true); ?>
Yet, this returns nothing?
I have read a fair amount on the topic of the_meta(), get_post_custom() etc, but nothing I am trying seems to have worked.
Would appreciate some insight?
EDIT:
Apologies, I wasn't too clear about the "Author" part.
Author is a custom field in the post_meta table along with "book type", book condition" published year" etc. It is not the Post Author.
Thanks

Do one thing just add echo before the function it will display the result and the last argument of the function will give you an array if it is set to false and a string if it set to true so change it according to your requirement

have you tried the_author_meta(); ?
You can use it like: the_author_meta('user_email')
Please note this function only works inside the loop... but there are ways around it, but they're gross.
available keys:
user_login
user_pass
user_nicename
user_email
user_url
user_registered
user_activation_key
user_status
display_name
nickname
first_name
last_name
description
jabber
aim
yim
user_level
user_firstname
user_lastname
user_description
rich_editing
comment_shortcuts
admin_color
plugins_per_page
plugins_last_view
ID

Related

Add comment date to comment author div wordpress

I'm trying to learn to use wordpress.
I'm trying to change comments layout and I want to join comment date to comment author data. But I am not getting it. For example, I have what is in first image but I want what it is in second. Can you help please? Thanks so much!
I think your main problem is that you want to customize the way the date is placed using only css but that's extremely hard.
The best thing for you to do is have your own custom comment code.
Wordpress let's you have your own comments code.
For example when you call the comment template code instead of doing this:
wp_list_comments( array(
'style' => 'ol',
'short_ping' => true,
'avatar_size' => 42,
) );
You can do something like this:
<ol class="commentlist">
<?php wp_list_comments( 'type=comment&callback=mytheme_comment' ); ?>
</ol>
And on the function.php file you can add the mytheme_comment function with the original comment code that wp has and reaarrange the classes and html code placement so you can have the date where you want.
function mytheme_comment($comment, $args, $depth) {
if ( 'div' === $args['style'] ) {
$tag = 'div';
$add_below = 'comment';
} else {
$tag = 'li';
$add_below = 'div-comment';
}
?>
<<?php echo $tag ?> <?php comment_class( empty( $args['has_children'] ) ? '' : 'parent' ) ?> id="comment-<?php comment_ID() ?>">
<?php if ( 'div' != $args['style'] ) : ?>
<div id="div-comment-<?php comment_ID() ?>" class="comment-body">
<?php endif; ?>
<div class="comment-author vcard">
<?php if ( $args['avatar_size'] != 0 ) echo get_avatar( $comment, $args['avatar_size'] ); ?>
<?php printf( __( '<cite class="fn">%s</cite> <span class="says">says:</span>' ), get_comment_author_link() ); ?>
</div>
<?php if ( $comment->comment_approved == '0' ) : ?>
<em class="comment-awaiting-moderation"><?php _e( 'Your comment is awaiting moderation.' ); ?></em>
<br />
<?php endif; ?>
<div class="comment-meta commentmetadata"><a href="<?php echo htmlspecialchars( get_comment_link( $comment->comment_ID ) ); ?>">
<?php
/* translators: 1: date, 2: time */
printf( __('%1$s at %2$s'), get_comment_date(), get_comment_time() ); ?></a><?php edit_comment_link( __( '(Edit)' ), ' ', '' );
?>
</div>
<?php comment_text(); ?>
<div class="reply">
<?php comment_reply_link( array_merge( $args, array( 'add_below' => $add_below, 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>
</div>
<?php if ( 'div' != $args['style'] ) : ?>
</div>
<?php endif; ?>
<?php
}
In the default code you can see that the code:
<?php
/* translators: 1: date, 2: time */
printf( __('%1$s at %2$s'), get_comment_date(), get_comment_time() );
?>
is what gives you the date information.
Hope you understanded this.
Here's the original WP documentation about this:
wp list comments

Wordpress Attachment Page Title

I would like to change the download link title on the attachment page to say Download link : ATTACHMENT_TITLE. Where do I start? The theme has no attachment.php
EDIT :
I've found that I could edit single.php
<?php if ( is_attachment() ) { echo "Download Link : "; } ?>
<?php get_template_part( 'content', 'single' ); ?>
That puts the text above the link. It would be nice to be inline with the link. I am looking at content-single.php now. That calls a function called the_content(); If I could follow where that function goes maybe I could put the "Download Link : " text within the div itself before the link.
content-single.php
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<?php do_action( 'esteem_before_post_content' ); ?>
<div class="entry-content clearfix">
<?php
the_content();
$esteem_tag_list = get_the_tag_list( '', ' ', '' );
if( !empty( $esteem_tag_list ) ) {
?>
<div class="tags">
<?php
_e( 'Tagged on: ', 'esteem' ); echo $esteem_tag_list;
?>
</div>
<?php
}
wp_link_pages( array(
'before' => '<div style="clear: both;"></div><div class="pagination
clearfix">'.__( 'Pages:', 'esteem' ),
'after' => '</div>',
'link_before' => '<span>',
'link_after' => '</span>'
) );
?>
</div>
<div class="entry-meta-bar clearfix">
<div class="entry-meta clearfix">
<span class="icon-user"><a href="<?php echo get_author_posts_url( get_the_author_meta( 'ID'
) ); ?>"><?php the_author(); ?></a></span>
<span class="icon-time"><a href="<?php the_permalink(); ?>" title="<?php echo esc_attr(
get_the_time() ); ?>"><?php the_time( get_option( 'date_format' ) ); ?></a></span>
<?php if( has_category() ) { ?>
<span class="icon-tag"><?php the_category(', '); ?></span>
<?php } ?>
<?php if ( comments_open() ) { ?>
<span class="icon-comment-alt"><?php comments_popup_link( __( 'No Comments', 'esteem' ), __(
'1 Comment', 'esteem' ), __( '% Comments', 'esteem' ), '', __( 'Comments Off', 'esteem' ) ); ?></span>
<?php } ?>
<?php edit_post_link( __( 'Edit', 'esteem' ), '<span class="icon-pencil">', '</span>' ); ?>
</div><!-- .entry-meta -->
</div><!-- .entry-meta-bar -->
<?php
do_action( 'esteem_after_post_content' );
?>
</article>
Here is the base code you can use in the page template:
<?php
$attachment_id = 1; // ID of attachment
$attachment_page = get_attachment_link( $attachment_id );
?>
Download Link**
Reference: http://codex.wordpress.org/Function_Reference/get_attachment_link
Note: If you want to modify the attachment page, you can either modify (if it exists) the attachments.php template or create one. The template hierarchy reference is here: http://codex.wordpress.org/Template_Hierarchy
EDIT:
Ok I found a simpler solution for you. On your single.php page wrap the content-single.php template part in an if statement. You can use this for the base of what you're trying to do. Give it a shot and let me know how it goes.
<?php if ( is_attachment() ) {
$attachment_link = wp_get_attachment_url();
echo 'Download Link';
} else {
get_template_part( 'content', 'single' );
} ?>

Twenty Twelve display only Title and Meta for tag, category, archive results

I want to only have the post title and meta (cat, tag, date) to be displayed on the results page.
I have used this code posted by Esmi at wp-forums to partially achieve this.
<?php if ( is_search() ) : // Only display Excerpts for Search ?>
<div class="entry-summary">
<?php the_excerpt(); ?>
</div><!-- .entry-summary -->
<?php elseif( !is_category() ) : ?>
<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; ?>
This code in the child theme's content.php will produce Excerpts on the Search page results, but just the Title and Meta for the Category results.
I have tried adding !is_tag || !is_archive to the elseif statement.. then everything returns the full post.
I have replaced the elseif !is_category with elsif !is_tag and I once again get just the title and meta result on the tag page, which is what I want.
It seems I should be able to add this list to the else if statement to get what I want, but I must not the the correct code to do such.
I also tried replacing the top string php if is_search
with is_search || is_tag || is_archive || is_category
and the gave me whole posts as well.
This should be simple.. but I am stuck. Any help will be appreciated.

Show Categorie(s) of a post in a list of custom posts

I've searched this question a lot, but all I find is answers of how to show every category for a specific taxonomy.
I'm developing a theme, and I'm going to filter a list of posts (custom post type 'jobs') using jQuery, but I need to have a <div> with a class showing the categories of that specific post.
I'm going to filter these on the category page (jobs).
For this to work, I'm putting all my code in the loop.php.
<div class="post_entry">
<div class="post-thumb"><?php the_post_thumbnail('single-post-thumbnail'); ?></div>
<h4 class="post-title"><?php the_title(); ?></h4>
<?php
$location = get_post_meta($post->ID, 'location', TRUE);
$organization = get_post_meta($post->ID, 'organization', TRUE);
$url = get_post_meta($post->ID, 'url', TRUE);
?>
<div class="post-meta">
<?php if($organization != ''){ ?><p class="post_meta_organization"><?php echo $organization; ?></p><?php } ?>
<?php if($location != ''){ ?><p class="post_meta_location"><?php echo $location; ?></p><?php } ?>
<?php if($url != ''){ ?><p class="post_meta_url">Website: Click Here</p><?php } ?>
</div>
<div class="hidden tags">
</div>
<?php if ( is_archive() || is_search() ) : // Only display excerpts for archives and search. ?>
<p class="post_excerpt"><?php the_excerpt(); ?></p>
<?php else : ?>
<div class="category_read_more"><?php the_content( __( 'Read More', 'twentyten' ) ); ?></div>
<?php wp_link_pages( array( 'before' => '' . __( 'Pages:', 'twentyten' ), 'after' => '' ) ); ?>
<?php endif; ?>
<?php edit_post_link( __( 'Edit', 'twentyten' ), '', '' ); ?>
<?php comments_template( '', true ); ?>
</div>
I've been lucky to add meta-box information, but I want to show the posts custom categories (jobtype) in <div class="hidden tags"></div>
To take a look at the website, check out http://www.cirkut.net/wp/libertyguide/jobs
If anyone could help, that would be fantastic! If any more information is needed, let me know.
In the loop:
Category: <?php echo get_the_category_list(', '); ?>
Update:
Wordpress writes:
Listing the terms
If you want to have a custom list in your theme, then you can pass the
taxonomy name into the the_terms() function in the Loop, like so:
the_terms( $post->ID, 'people', 'People: ', ', ', ' ' );
This should address your problem.
http://codex.wordpress.org/Taxonomies#Listing_the_terms

WordPress: Using custom field to define posts to display in loop

I'm trying to use a custom field in which I input the post ID numbers of the posts I want to show, seperated by commas. For some reason though, only the first post of the series of the post IDs are displaying. Can someone help? The value of $nlPostIds is (minus the quotes): "1542,1534,1546". Here's the code... the most important part is the 4th line 'post__in' => array($nlPostIds)
<?php
$nlPostIds = get_post_meta($post->ID, 'nlPostIds', true);
$args=array(
'post__in' => array($nlPostIds)
);
query_posts($args);
if ( $wp_query->have_posts() ) : while ( $wp_query->have_posts() ) : $wp_query->the_post(); ?>
<div class="entry">
<div class="post" id="post-<?php the_ID(); ?>">
<h2><?php the_title(); ?></h2>
<div class="allinfos"><span class="date"><?php the_time('F jS, Y') ?></span> | <span class="comments"><?php comments_popup_link('No Comments', '1 Comment', '% Comments'); ?> </span> | <span class="category">Posted in <?php the_category(', ') ?></span> <!-- by <?php the_author() ?> --></div>
<?php the_content('More ยป'); ?>
<?php the_tags('Tags: ', ', ', ' '); ?> <?php edit_post_link('Edit', '[ ', ' ]'); ?>
<div class="clear"></div>
</div></div>
<?php endwhile; endif; ?>
Thanks!
I think you need to also pass the argument 'posts_per_page' as -1 in your $args array (see the Codex on query_posts()).
UPDATE:
Apologies, I've just re-read your question and I think I know the problem. Pass $nlPostIds as the direct argument, without placing it an array. You only pass an array when each element is an ID. In this care you're just passing a comma-separated string.
UPDATE:
Use;
$args = array('post__in' => #explode(',', $nlPostIds), 'posts_per_page' => -1);

Resources