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' );
} ?>
Related
I have a comments section which I am looking to have inline validation. It appears to work when no details are entered in the form fields. But if I enter an email that is not in the correct format (eg. notavalidemail.com) I am redirected to /wp-comments-post.php
How do I prevent this default action and include inline validation. Is this something that can only be done with JS/jQuery and is not a native action?
My comments file includes -
// comments.php
if ( post_password_required() ) {
return;
}
$boilerplate_comment_count = get_comments_number();
?>
<div id="comments" class="comments <?php echo get_option( 'show_avatars' ) ? 'comments__avatars--show' : ''; ?>">
<?php
if ( have_comments() ) :
?>
<h2 class="comments__title">
<?php if ( '1' === $boilerplate_comment_count ) : ?>
<?php esc_html_e( '1 comment', THEME_NAME ); ?>
<?php else : ?>
<?php
printf(
/* translators: %s: Comment count number. */
esc_html( _nx( '%s comment', '%s comments', $boilerplate_comment_count, 'Comments title', THEME_NAME ) ),
esc_html( number_format_i18n( $boilerplate_comment_count ) )
);
?>
<?php endif; ?>
</h2>
<ol class="comments__list">
<?php
$args = array(
'type' => 'comment',
'callback' => 'boilerplate_format_comment'
);
wp_list_comments( $args );
?>
</ol>
<?php
the_comments_pagination(
array(
'before_page_number' => esc_html__( 'Page', THEME_NAME ) . ' ',
'mid_size' => 0,
'prev_text' => sprintf(
'<span class="nav-prev-text">%s</span>',
esc_html__( 'Older comments', THEME_NAME )
),
'next_text' => sprintf(
'<span class="nav-next-text">%s</span>',
esc_html__( 'Newer comments', THEME_NAME ),
),
)
);
?>
<?php if ( ! comments_open() ) : ?>
<p class="comments__none"><?php esc_html_e( 'Comments are closed.', THEME_NAME ); ?></p>
<?php endif; ?>
<?php endif; ?>
<?php
comment_form(
array(
'logged_in_as' => null,
'title_reply' => esc_html__( 'Leave a comment', 'twentytwentyone' ),
'title_reply_before' => '<h2 id="reply-title" class="comment-reply-title">',
'title_reply_after' => '</h2>',
)
);
?>
</div>
The comments are being formatted by:
function boilerplate_format_comment($comment, $args, $depth) {
$GLOBALS['comment'] = $comment; ?>
<li id="li-comment-<?php comment_ID() ?>" <?php comment_class(); ?>>
<article id="div-comment-<?php comment_ID(); ?>" class="comments__item">
<div class="comments__item--media">
<?php if ( 0 != $args['avatar_size'] ) echo get_avatar( $comment, '160' ); ?>
</div>
<div class="comments__item--content">
<div class="comments__item--title">
<?php
/* translators: %s: comment author link */
printf( __('<h3>%s</h3>'), get_comment_author_link( $comment ) );
?>
<div class="comments__item--date">
<time datetime="<?php comment_time( 'c' ) ?>">
<?php
/* translators: 1: comment time, 2: comment date */
printf( __( 'Posted at %1$s, %2$s' ), get_comment_time(), get_comment_date( 'd F', $comment ) );
?>
</time>
</div>
</div>
<div class="comments__item--comment">
<?php comment_text(); ?>
</div>
<?php if ( '0' == $comment->comment_approved ) : ?>
<div class="comments__moderation--await">
<p><?php _e( 'Your comment is awaiting moderation.' ); ?></p>
</div>
<?php endif; ?>
<div class="comments__item--conversation">
<?php
if (get_comment_type() == 'comment') {
comment_reply_link( array_merge( $args, array(
'add_below' => 'div-comment',
'depth' => $depth,
'max_depth' => $args['max_depth'],
'before' => '<div class="comments__item--reply">',
'after' => '</div>'
) ) );
}
?>
<?php edit_comment_link( __( 'Edit' ), '<div class="comments__item--edit">', '</div>' ); ?>
</div>
</div>
</article>
<?php }
Is there something that I am missing out that is native to WP or can this type of action only be perform by JS? I see that comment_form() has the action argument that defaults to /wp-comments-post.php. DO I need to make changes here?
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
I want to pull the 5 most recent podcasts from an iTunes feed and post them along with their audio to a WP page.
The code I have is below
its pulling the feed and displaying the name, details, etc fine but its using the same podcast audio for each item.
<div class="podcastfeed">
<h4>Recent Podcasts</h4>
<?php // Get $feed Feed(s)
include_once( ABSPATH . WPINC . '/feed.php' );
$hpFeed=get_post_meta($post->ID, "cmb_hp_feed", true);
$feed = fetch_feed( $hpFeed );
$feed->init();
$feed->handle_content_type();
foreach ($feed->get_items() as $item)
{
if ($enclosure = $item->get_enclosure())
{
$enclosure->get_link();
}
}
if ( ! is_wp_error( $feed ) ) : // Checks that the object is created correctly
// Figure out how many total items there are, but limit it to 5.
$maxitems = $feed->get_item_quantity( 5 );
// Build an array of all the items, starting with element 0 (first element).
$feed_items = $feed->get_items( 0, $maxitems );
endif;
$attr = array(
'src' => $enclosure->get_link(),
'loop' => '',
'autoplay' => '',
'preload' => 'none'
);
?>
<ol>
<?php if ( $maxitems == 0 ) : ?>
<li><?php _e( 'No items', 'my-text-domain' ); ?></li>
<?php else : ?>
<?php // Loop through each feed item and display each item as a hyperlink. ?>
<?php foreach ( $feed_items as $item ) : ?>
<li>
<a href="<?php echo esc_url( $item->get_permalink() ); ?>"
title="<?php printf( __( 'Posted %s', 'my-text-domain' ), $item->get_date('F j, Y') ); ?>">
<p>
<span>
<?php echo esc_html( $item->get_title() ); ?>
</span>
<span><?php printf( __( '%s', 'my-text-domain' ), $item->get_date('F j, Y') ); ?></span>
</p>
</a>
<?php echo wp_audio_shortcode( $attr );?>
</li>
<?php endforeach; ?>
<?php endif; ?>
</ol>
</div>
I got it working in the end though it took some fiddling with
The page is now displaying each of the podcasts as audio.
<div class="podcastfeed">
<?php // Get $feed Feed(s)
include_once( ABSPATH . WPINC . '/feed.php' );
$hpFeed=get_post_meta($post->ID, "cmb_hp_feed", true);
// Get a SimplePie feed object from the specified feed source.
$rss = fetch_feed( $hpFeed );
if ( ! is_wp_error( $rss ) ) : // Checks that the object is created correctly
// Figure out how many total items there are, but limit it to 5.
$maxitems = $rss->get_item_quantity( 5 );
// Build an array of all the items, starting with element 0 (first element).
$rss_items = $rss->get_items( 0, $maxitems );
endif;
?>
<?php if ( $maxitems == 0 ) : ?>
<ol style="display:none;"><?php _e( 'No items', 'my-text-domain' ); ?></ol>
<?php else : ?>
<h4>Recent Podcasts</h4>
<ol>
<?php // Loop through each feed item and display each item as a hyperlink. ?>
<?php foreach ( $rss_items as $item ) : ?>
<li>
<a href="<?php echo esc_url( $item->get_permalink() ); ?>"
title="<?php printf( __( 'Posted %s', 'my-text-domain' ), $item->get_date('F j, Y') ); ?>">
<p>
<span>
<?php echo esc_html( $item->get_title() ); ?>
</span>
<span>
<?php printf( __( '%s', 'my-text-domain' ), $item->get_date('F j, Y') ); ?>
</span>
</p>
</a>
<?php
if ($enclosure = $item->get_enclosure()){
$enclosure->get_link();
}
?>
<?php
$attr = array(
'src' => $enclosure->get_link(),
'loop' => '',
'autoplay' => '',
'preload' => 'none'
);
?>
<?php echo wp_audio_shortcode( $attr );?>
</li>
<?php endforeach; ?>
<?php endif; ?>
</ol>
</div>
after updating to WP 3.8 I can't see anymore my thumbs in archive.php.
Here's the code:
<div class="post-entry">
<?php if( has_post_thumbnail() ) : ?>
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
<?php the_post_thumbnail( 'thumbnail', array( 'class' => 'alignleft' ) ); ?>
</a>
<?php endif; ?>
<?php the_excerpt(); ?>
<?php wp_link_pages( array( 'before' => '<div class="pagination">' . __( 'Pages:', 'responsive' ), 'after' => '</div>' ) ); ?>
</div>
In the functions.php I've added the following:
add_theme_support( 'post-thumbnails' );
But nothing to do. The thumbnails still no more there.
Any help?
Thanks in advance,
Vince
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