I'm running a variation of the _underscores theme for my clients site and we already have the page or post title displayed in a custom header element, so it doesn't need to be inside of the loop anymore on template-parts/content.php. I thought just deleting 'get_the_title' would eliminate seeing the title in the body of my post, but instead, I just got a variety of errors like 'unexpected ')'' or similar. So how do I get rid of the get_the_title reference and still make this valid? Here's what I have currently.
<div class="entry-content">
<?php if ( is_category() || is_archive() ) {
the_excerpt('');
} else {
the_content( sprintf(
wp_kses(
/* translators: %s: Name of current post. Only visible to screen readers */
__( 'Continue reading<span class="screen-reader-text"> "%s"</span>', 'orchestra' ),
array(
'span' => array(
'class' => array(),
),
)
),
get_the_title()
) );
if ( is_category() || is_archive() ) {
echo '<p class="btn-cc">Read More</p>';
}
wp_link_pages( array(
'before' => '<div class="page-links">' . esc_html__( 'Pages:', 'orchestra' ),
'after' => '</div>',
) );
}
?>
The formatting on this makes it relatively hard to read. So first I'd clean that up a bit. If you look at the documentation for the_content() you'll see that the first parameter is the $more_text_link. So lines 5 through 15 are adding a "Continue Reading [Post Title]" test.
If you don't need that at all, you can just use the_content() like so:
<div class="entry-content">
<?php
if( is_category() || is_archive() ){
the_excerpt('');
} else {
the_content();
if( is_category() || is_archive() ){
echo '<p class="btn-cc">Read More</p>';
}
wp_link_pages( array(
'before' => '<div class="page-links">' . esc_html__( 'Pages:', 'orchestra' ),
'after' => '</div>',
) );
}
?>
Otherwise, you'll want to add in your own default text:
<div class="entry-content">
<?php
if( is_category() || is_archive() ){
the_excerpt('');
} else {
the_content( 'Continue Reading' );
if( is_category() || is_archive() ){
echo '<p class="btn-cc">Read More</p>';
}
wp_link_pages( array(
'before' => '<div class="page-links">' . esc_html__( 'Pages:', 'orchestra' ),
'after' => '</div>',
) );
}
?>
Related
I have some code
'next_text' => sprintf( esc_html__( '%s', 'mytheme' ), '%title' ),
and I need to add html inside it. Basically I want to add
<span>Previous article</span>
before the title. How can I do this?
EDIT: The full function is
function mytheme_single_post_navigation() {
if ( ! is_singular( 'post' ) ) {
return;
}
if ( ! intval( mytheme_get_theme_mod( 'blog_single_navigation' ) ) ) {
return;
}
the_post_navigation( array(
/* translators: %s: title syntax. */
'prev_text' => sprintf( esc_html__( '%s', 'mytheme' ), '%title' ),
/* translators: %s: title syntax. */
'next_text' => sprintf( esc_html__( '%s', 'mytheme' ), '%title' ),
) );
}
endif;
If you want to edit the wordpress post navigation in the single.php of your posts, you can use:
<span> <?php previous_post_link( '%link', '‹ Previous article' ); ?> </span>
<span> <?php next_post_link( '%link', 'Next article ›' ); ?> </span>
If you want to make it with setting 'next_text', you can also put your outpout in a string and use this:
<?php $next_post = '<span>Previous article</span>'; ?>
and then assign it to the 'next_text':
'next_text' => $next_post
If you read sprintf() function https://www.w3schools.com/php/func_string_sprintf.asp
you can add html tags with no problem. So it could also work with:
'next_text' => sprintf( esc_html__( '%s', 'mytheme' ), '<span> %title </span>' ),
But you do not want to have the title, so you don't actualy need this, if I got your question right.
EDIT:
If you want to show the span before the name of your post, you can use:
<?php previous_post_link( '%link', '<span>Previous article</span>'.' %title' ); ?>
With the dot . you are connecting the span element with the title.
So in your code, your the_post_navigation can look like:
the_post_navigation( array(
/* translators: %s: title syntax. */
'prev_text' => sprintf( esc_html__( '%s', 'mytheme' ), '<span>Previous article</span>'.' %title' ),
/* translators: %s: title syntax. */
'next_text' => sprintf( esc_html__( '%s', 'mytheme' ), '<span>Next article</span>'.' %title' ),
) );
I am trying to fix the linting issue here is code.
function get_the_breadcrumb() {
if ( ! is_front_page() ) {
// Start the breadcrumb with a link to your homepage.
echo '<div class="o__breadcrumb">';
echo '<a href="';
echo esc_html( get_option( 'home' ) );
echo '"> Home';
echo '</a> <span> ';
echo esc_html( Load::atom( 'icons/breadcrumb_arrow' ) );
echo '</span>';
// Check if the current page is a category, an archive or a single page. If so show the category or archive name.
if ( is_category() || is_single() ) {
the_category( 'title_li=' );
} elseif ( is_archive() || is_single() ) {
if ( is_day() ) {
/* translators: %s: text term */
printf( esc_html( __( '%s', 'text_domain' ) ), esc_html( get_the_date() ) );
} elseif ( is_month() ) {
/* translators: %s: text term */
printf( esc_html( __( '%s', 'text_domain' ) ), get_the_date( _x( 'F Y', 'monthly archives date format', 'text_domain' ) ) );
} elseif ( is_year() ) {
/* translators: %s: text term */
printf( esc_html( __( '%s', 'text_domain' ) ), get_the_date( _x( 'Y', 'yearly archives date format', 'text_domain' ) ) );
} else {
esc_attr_e( 'Blog Archives', 'text_domain' );
}
}
// If the current page is a single post, show its title with the separator.
if ( is_single() ) {
echo '<span>';
echo esc_html( Load::atom( 'icons/breadcrumb_arrow' ) );
echo '</span>';
the_title();
}
// If the current page is a static page, show its title.
if ( is_page() ) {
echo the_title();
}
// if you have a static page assigned to be you posts list page. It will find the title of the static page and display it. i.e Home >> Blog.
if ( is_home() ) {
global $post;
$page_for_posts_id = get_option( 'page_for_posts' );
if ( $page_for_posts_id ) {
$post = get_page( $page_for_posts_id );
setup_postdata( $post );
the_title();
rewind_posts();
}
}
echo '</div>';
}
}
Linting response
FOUND 3 ERRORS AFFECTING 3 LINES
----------------------------------------------------------------------
193 | ERROR | Strings should have translatable content
196 | ERROR | Strings should have translatable content
199 | ERROR | Strings should have translatable content
Line number 193
printf( esc_html( __( '%s', 'text_domain' ) ), esc_html( get_the_date() ) );
Line number 196
printf( esc_html( __( '%s', 'text_domain' ) ), get_the_date( _x( 'F Y', 'monthly archives date format', 'text_domain' ) ) );
Line number 199
printf( esc_html( __( '%s', 'text_domain' ) ), get_the_date( _x( 'Y', 'yearly archives date format', 'text_domain' ) ) );
It's because you have %s as the text inside the translation function call __(...), which is not translatable.
Instead you should have your printf() call inside the translation call, so the translator can actually see what the heck you're trying to translate.
But, you shouldn't be trying to translate the date this way. It won't work because the date is always changing and the way __() translation works is by matching the exact string passed in to a translation. According to this answer, you should use date_i18n
And why are you trying to translate the date formatting strings you are passing to get_the_date, those are code values used by php, they don't change based on where you are. Translating these can only cause you problems.
You also call esc_html twice on line 193.
So, instead you should write your lines of code like so:
Line number 193
esc_html( date_i18n( get_the_date() ) );
Line number 196
esc_html( date_i18n( get_the_date('F Y') ) );
Line number 199
esc_html( date_i18n( get_the_date( 'Y' ) ) );
Note, I don't think the esc_html calls are actually necessary here, since the internals is just WordPress functions that only return dates... no html should be in there
I am trying to remove the words "Category Archives:" on the posts category page or The7 Wordpress Theme.
This one really has me stumped. I have gone through every file in the theme that I can think of and even tried to change this via the SEO plugin but am having no luck.
I was wondering if anyone had any ideas?
Here is the development site address: http://bellparktest.com/category/research-center/
Thank you,
Derek
OK- First of all - You should use the theme's child theme to make this kind of modification because when you make an update in the future it will wipe out all your changes.
You should look for the function "function presscore_get_page_title()" inside > wp-content > themes > dt-the7 > inc > helpers> .
copy it from line 12: "if ( ! function_exists( 'presscore_get_page_title' ) ) :"
to line 97 "endif;"
paste it inside your child theme "function.php" > wp-content > themes > dt-the7-child .
then change 'category' => __( 'Category Archives: %s', 'the7mk2' ), to 'category' => __( ' %s', 'the7mk2' ),
You should get something like this:
// THIS FUNCTION REMOVES "Category Archives:" FROM BLOG POSTS
if ( ! function_exists( 'presscore_get_page_title' ) ) :
/**
* Function return current page title.
*
* #return string
*/
function presscore_get_page_title() {
$default_page_title_strings = array(
'search' => __( 'Search Results for: %s', 'the7mk2' ),
'category' => __( '%s', 'the7mk2' ),
'tag' => __( 'Tag Archives: %s', 'the7mk2' ),
'author' => __( 'Author Archives: %s', 'the7mk2' ),
'day' => __( 'Daily Archives: %s', 'the7mk2' ),
'month' => __( 'Monthly Archives: %s', 'the7mk2' ),
'year' => __( 'Yearly Archives: %s', 'the7mk2' ),
'archives' => __( 'Archives: ', 'the7mk2' ),
'page_404' => __( 'Page not found', 'the7mk2' ),
'blog' => __( 'Blog', 'the7mk2' ),
);
/**
* Filter all default titles at once.
*
* #since 4.2.1
*/
$page_title_strings = apply_filters( 'presscore_page_title_strings', $default_page_title_strings );
$page_title_strings = wp_parse_args( $page_title_strings, $default_page_title_strings );
$title = '';
if ( is_home() && ! is_front_page() ) {
$title = single_post_title( '', false );
} elseif ( is_page() || is_single() ) {
$title = get_the_title();
} elseif ( is_search() ) {
$title = sprintf( $page_title_strings['search'], '<span>' . get_search_query() . '</span>' );
} elseif ( is_archive() ) {
if ( is_category() ) {
$title = sprintf(
$page_title_strings['category'],
'<span>' . single_cat_title( '', false ) . '</span>'
);
} elseif ( is_tag() ) {
$title = sprintf( $page_title_strings['tag'], '<span>' . single_tag_title( '', false ) . '</span>' );
} elseif ( is_author() ) {
the_post();
$title = sprintf(
$page_title_strings['author'],
'<span class="vcard"><a class="url fn n" href="' . esc_url(
get_author_posts_url( get_the_author_meta( 'ID' ) )
) . '" title="' . esc_attr( get_the_author() ) . '" rel="me">' . get_the_author() . '</a></span>'
);
rewind_posts();
} elseif ( is_day() ) {
$title = sprintf( $page_title_strings['day'], '<span>' . get_the_date() . '</span>' );
} elseif ( is_month() ) {
$title = sprintf( $page_title_strings['month'], '<span>' . get_the_date( 'F Y' ) . '</span>' );
} elseif ( is_year() ) {
$title = sprintf( $page_title_strings['year'], '<span>' . get_the_date( 'Y' ) . '</span>' );
} else {
$title = $page_title_strings['archives'];
}
} elseif ( is_404() ) {
$title = $page_title_strings['page_404'];
} else {
$title = $page_title_strings['blog'];
}
return apply_filters( 'presscore_get_page_title', $title );
}
endif;
I'm not sure about 'Category Archives:', I only see 'Category:'—that can be removed e.g. with the plugin 'Slash Admin' ('Frontend > Miscellaneous > Remove "Category:" from archives'). That seems to accomplish the task as follows (remove the 'if' around the 'add_filter' if you implement this yourself):
/*
* Remove "Category:" from archives
*/
function slashadmin_remove_category( $title ) {
if ( is_category() ) {
$title = single_cat_title( '', false );
}
if ( is_post_type_archive() ) {
$title = post_type_archive_title( '', false );
}
if ( is_tax() ) {
$title = single_term_title( '', false );
}
return $title;
}
if ( slash_admin( 'remove_category' ) ) {
add_filter( 'get_the_archive_title', 'slashadmin_remove_category', 10, 2 );
}
Disable the page title via Custom CSS located in Advanced CSS in Theme Options.
.category-research-center .page-title {
display: none !important;
}
You have this filter for all cases: "get_the_archive_title". But then there are different cases.
For exemple for simple category you can do :
function prefix_category_title( $title ) {
if(is_category()){
$title = single_cat_title( '', false );
}
return $title;
}
add_filter( 'get_the_archive_title', 'prefix_category_title' );
For custom post type you should do :
function prefix_category_title( $title ) {
if(is_archive('slug-of-your-custom-post-type')){
$title = single_cat_title( '', false );
}
return $title;
}
add_filter( 'get_the_archive_title', 'prefix_category_title' );
need a little help again, here is a function that return text content and read more link in wordpress:
function whisper_entry_contentoffer1()
{
global $whisper;
// Check on singular pages
$is_single = is_singular() && !is_page_template( 'tpl/blog.php' ) && !is_page_template( 'tpl/blog-boxes.php' );
// Allow to config via global variable
if ( isset( $whisper['is_single'] ) )
$is_single = $whisper['is_single'];
if ( $is_single )
{
echo '<div class="entry-content">';
the_content();
wp_link_pages( array(
'before' => '<p class="pages">' . __( 'Pages:', 'whisper' ),
'after' => '</p>',
'link_before' => '<span>',
'link_after' => '</span>',
) );
echo '</div>';
return;
}
// Archives & Blog pages
// Display type
$display = fitwp_option( 'blog_display' );
// Allow to config via global variable
if ( isset( $whisper['blog_display'] ) )
$display = $whisper['blog_display'];
if ( !$display )
$display = 'content';
echo '<div class="entry-summary">';
// Excerpt
if ( 'excerpt' == $display )
{
the_excerpt();
return;
}
$more_text = whisper_more_text2();
// Post content before more tag
if ( 'more' == $display )
{
if ( is_page_template( 'tpl/blog.php' ) || is_page_template( 'tpl/blog-boxes.php' ) )
{
global $more;
$more = false;
}
the_content( $more_text );
wp_link_pages( array(
'before' => '<p class="pages">' . __( 'Pages:', 'whisper' ),
'after' => '</p>',
'link_before' => '<span>',
'link_after' => '</span>',
) );
}
else
{
whisper_content_limitoffer1( whisper_content_length(), $more_text );
}
echo '</div>'; // .entry-summary
}
Now i need to limit output text to 12 word. any suggestions or soultions?!
Thanks...
This? replace $string with your string
echo implode(" ",array_splice(explode(" ",$string),0,20));
I was translating the titles and sentences right on the editor. I don't know what went wrong, but when I hit upload I keep getting this:
Parse error: syntax error, unexpected 'Comentários' (T_STRING) in /home2/tkleinow/public_html/wp-content/themes/fashionistas/inc/template-tags.php on line 94
Then I tried to copy the original code for that section (template tags) on the zip files, but I keep getting the same error.
I pasted it on Excel to find what the line was, and this is wat I got:
<?php printf( __( '%s', 'athemes' ), sprintf( '<cite class="fn">%s</cite>', get_comment_author_link() ) ); ?>
My website was doing just fine, I don't know how I screwed it like that.
This is the whole thing:
<?php
/**
* Custom template tags for this theme.
*
* Eventually, some of the functionality here could be replaced by core features
*
* #package aThemes
*/
if ( ! function_exists( 'athemes_content_nav' ) ) :
/**
* Display navigation to next/previous pages when applicable
*/
function athemes_content_nav( $nav_id ) {
global $wp_query, $post;
// Don't print empty markup on single pages if there's nowhere to navigate.
if ( is_single() ) {
$previous = ( is_attachment() ) ? get_post( $post->post_parent ) : get_adjacent_post( false, '', true );
$next = get_adjacent_post( false, '', false );
if ( ! $next && ! $previous )
return;
}
// Don't print empty markup in archives if there's only one page.
if ( $wp_query->max_num_pages < 2 && ( is_home() || is_archive() || is_search() ) )
return;
$nav_class = ( is_single() ) ? 'post-navigation' : 'paging-navigation';
?>
<nav role="navigation" id="<?php echo esc_attr( $nav_id ); ?>" class="<?php echo $nav_class; ?>">
<h1 class="screen-reader-text"><?php _e( 'Post navigation', 'athemes' ); ?></h1>
<?php if ( is_single() ) : // navigation links for single posts ?>
<?php previous_post_link( '<div class="nav-previous"><span>Artigo Anterior</span>%link</div>', '<span class="meta-nav">' . _x( '←', 'Link do Post Anterior', 'athemes' ) . '</span> %title' ); ?>
<?php next_post_link( '<div class="nav-next"><span>Próximo Artigo</span>%link</div>', '%title <span class="meta-nav">' . _x( '→', 'Link para o próximo artigo', 'athemes' ) . '</span>' ); ?>
<?php elseif ( $wp_query->max_num_pages > 1 && ( is_home() || is_archive() || is_search() ) ) : // navigation links for home, archive, and search pages ?>
<?php if ( get_next_posts_link() ) : ?>
<div class="nav-previous"><?php next_posts_link( __( '<span class="meta-nav">←</span> Artigos Anteriores', 'athemes' ) ); ?></div>
<?php endif; ?>
<?php if ( get_previous_posts_link() ) : ?>
<div class="nav-next"><?php previous_posts_link( __( 'Artigos Recentes <span class="meta-nav">→</span>', 'athemes' ) ); ?></div>
<?php endif; ?>
<?php endif; ?>
</nav><!-- #<?php echo esc_html( $nav_id ); ?> -->
<?php
}
endif; // athemes_content_nav
if ( ! function_exists( 'athemes_comment' ) ) :
/**
* Template for comments and pingbacks.
*
* Used as a callback by wp_list_comments() for displaying the comments.
*/
function athemes_comment( $comment, $args, $depth ) {
$GLOBALS['comment'] = $comment;
if ( 'pingback' == $comment->comment_type || 'trackback' == $comment->comment_type ) : ?>
<li id="comment-<?php comment_ID(); ?>" <?php comment_class(); ?>>
<div class="comment-body">
<?php _e( 'Pingback:', 'athemes' ); ?> <?php comment_author_link(); ?> <?php edit_comment_link( __( 'Edit', 'athemes' ), '<span class="edit-link">', '</span>' ); ?>
</div>
<?php else : ?>
<li id="comment-<?php comment_ID(); ?>" <?php comment_class( empty( $args['has_children'] ) ? '' : 'parent' ); ?>>
<article id="div-comment-<?php comment_ID(); ?>" class="comment-body">
<footer class="clearfix comment-meta">
<div class="reply">
<?php comment_reply_link( array_merge( $args, array( 'add_below' => 'div-comment', 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>
</div><!-- .reply -->
<div class="clearfix comment-author vcard">
<?php if ( 0 != $args['avatar_size'] ) echo get_avatar( $comment, $args['avatar_size'] ); ?>
<div class="comment-metadata">
<a href="<?php echo esc_url( get_comment_link( $comment->comment_ID ) ); ?>">
<time datetime="<?php comment_time( 'c' ); ?>">
<?php printf( _x( '%1$s', '1: date, 2: time', 'athemes' ), get_comment_date(), get_comment_time() ); ?>
</time>
</a>
</div><!-- .comment-metadata -->
<?php printf( __( '%s', 'athemes' ), sprintf( '<cite class="fn">%s</cite>', get_comment_author_link() ) ); ?>
</div><!-- .comment-author -->
<?php if ( '0' == $comment->comment_approved ) : ?>
<p class="comment-awaiting-moderation"><?php _e( 'Seu comentário será aprovado assim que passar pela moderação.', 'athemes' ); ?></p>
<?php endif; ?>
</footer><!-- .comment-meta -->
<div class="comment-content">
<?php comment_text(); ?>
</div><!-- .comment-content -->
</article><!-- .comment-body -->
<?php
endif;
}
endif; // ends check for athemes_comment()
if ( ! function_exists( 'athemes_the_attached_image' ) ) :
/**
* Prints the attached image with a link to the next attached image.
*/
function athemes_the_attached_image() {
$post = get_post();
$attachment_size = apply_filters( 'athemes_attachment_size', array( 1200, 1200 ) );
$next_attachment_url = wp_get_attachment_url();
/**
* Grab the IDs of all the image attachments in a gallery so we can get the
* URL of the next adjacent image in a gallery, or the first image (if
* we're looking at the last image in a gallery), or, in a gallery of one,
* just the link to that image file.
*/
$attachment_ids = get_posts( array(
'post_parent' => $post->post_parent,
'fields' => 'ids',
'numberposts' => -1,
'post_status' => 'inherit',
'post_type' => 'attachment',
'post_mime_type' => 'image',
'order' => 'ASC',
'orderby' => 'menu_order ID'
) );
// If there is more than 1 attachment in a gallery...
if ( count( $attachment_ids ) > 1 ) {
foreach ( $attachment_ids as $attachment_id ) {
if ( $attachment_id == $post->ID ) {
$next_id = current( $attachment_ids );
break;
}
}
// get the URL of the next image attachment...
if ( $next_id )
$next_attachment_url = get_attachment_link( $next_id );
// or get the URL of the first image attachment.
else
$next_attachment_url = get_attachment_link( array_shift( $attachment_ids ) );
}
printf( '%3$s',
esc_url( $next_attachment_url ),
the_title_attribute( array( 'echo' => false ) ),
wp_get_attachment_image( $post->ID, $attachment_size )
);
}
endif;
if ( ! function_exists( 'athemes_posted_on' ) ) :
/**
* Prints HTML with meta information for the current post-date/time and author.
*/
function athemes_posted_on() {
$time_string = '<time class="entry-date published" datetime="%1$s">%2$s</time>';
//if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) )
//$time_string .= '<time class="updated" datetime="%3$s">%4$s</time>';
$time_string = sprintf( $time_string,
esc_attr( get_the_date( 'c' ) ),
esc_html( get_the_date() ),
esc_attr( get_the_modified_date( 'c' ) ),
esc_html( get_the_modified_date() )
);
printf( __( '<span class="posted-on">%1$s</span>', 'athemes' ),
sprintf( '%3$s',
esc_url( get_permalink() ),
esc_attr( get_the_time() ),
$time_string
)
);
}
endif;
/**
* Returns true if a blog has more than 1 category
*/
function athemes_categorized_blog() {
if ( false === ( $all_the_cool_cats = get_transient( 'all_the_cool_cats' ) ) ) {
// Create an array of all the categories that are attached to posts
$all_the_cool_cats = get_categories( array(
'hide_empty' => 1,
) );
// Count the number of categories that are attached to the posts
$all_the_cool_cats = count( $all_the_cool_cats );
set_transient( 'all_the_cool_cats', $all_the_cool_cats );
}
if ( '1' != $all_the_cool_cats ) {
// This blog has more than 1 category so athemes_categorized_blog should return true
return true;
} else {
// This blog has only 1 category so athemes_categorized_blog should return false
return false;
}
}
/**
* Flush out the transients used in athemes_categorized_blog
*/
function athemes_category_transient_flusher() {
// Like, beat it. Dig?
delete_transient( 'all_the_cool_cats' );
}
add_action( 'edit_category', 'athemes_category_transient_flusher' );
add_action( 'save_post', 'athemes_category_transient_flusher' );