I want to remove the excerpt function or render it functionless as i want all posts to be viewed in full of its content. I think the theme has some tracking to make sure the excerption is in that line, so it must exist.
function excerpt($limit) {
$excerpt = explode(' ', get_the_excerpt(), $limit);
if (count($excerpt)>=$limit) {
array_pop($excerpt);
$excerpt = implode(" ",$excerpt).'...';
} else {
$excerpt = implode(" ",$excerpt);
}
$excerpt = preg_replace('`\[[^\]]*\]`','',$excerpt);
return $excerpt;
}
function content($limit) {
$content = explode(' ', get_the_content(), $limit);
if (count($content)>=$limit) {
array_pop($content);
$content = implode(" ",$content).'...';
} else {
$content = implode(" ",$content);
}
$content = preg_replace('/\[.+\]/','', $content);
$content = apply_filters('the_content', $content);
$content = str_replace(']]>', ']]>', $content);
return $content;
}
I only have these 2 lines of codes which i know is related.
I dont know where the $limit come from, i tried to find on all theme related php,no findings.
Please help me. Thank you very muc.
Just find your template file (could be index.php) where you want to display the full content instead of excerpted content and replace the function the_excerpt() with the_content() inside the loop, i.e.
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<!-- do other stuff ... -->
the_content();
<?php endwhile; ?>
<?php endif; ?>
About the_content() and the loop.
Related
I'm trying to customize the excerpt length on posts. I'm using this function on function.php:
function get_excerpt(){
$excerpt = get_the_content();
$excerpt = preg_replace(" ([.*?])",'',$excerpt);
$excerpt = strip_shortcodes($excerpt);
$excerpt = strip_tags($excerpt);
$excerpt = substr($excerpt, 0, 25);
$excerpt = substr($excerpt, 0, strripos($excerpt, " "));
$excerpt = trim(preg_replace( '/s+/', ' ', $excerpt));
$excerpt = $excerpt.'... [...]';
return $excerpt;
}
and using it on this tag
<article class="secundary">
<div class="mini">
<?php the_post_thumbnail('large', array('class' => 'img-responsive')); ?>
</div>
<h1><?php the_title(); ?></h1>
<p>por <span><?php the_author_posts_link(); ?></span> em <span><?php the_category(' '); ?></span> <?php the_tags('Tags: ', ', '); ?></p>
<p><?php echo get_the_date(); ?></p>
<p><?php get_excerpt(); ?></p>
</article>
Anyone could help me? It didn't work… why?
Thank you! :)
I would avoid limiting by characters as that delivers a performance hit. Instead, limit by words. Put the following in your functions.php:
function excerpt($limit) {
$excerpt = explode(' ', get_the_excerpt(), $limit);
if (count($excerpt)>=$limit) {
array_pop($excerpt);
$excerpt = implode(" ",$excerpt).'...';
} else {
$excerpt = implode(" ",$excerpt);
}
$excerpt = preg_replace('`[[^]]*]`','',$excerpt);
return $excerpt;
}
Wherever you use the excerpt in your template files, you can now add the amount of words you would like displayed (for example, 30) as follows:
echo excerpt(30)
You don't have to write a custom function for changing the excerpt length.
You can use the excerpt_length filter. You can use following code in your functions.php file.
function mytheme_custom_excerpt_length( $length ) {
return 25;
}
add_filter( 'excerpt_length', 'mytheme_custom_excerpt_length', 999 );
And then just use the default the_excerpt() tag in your post template.
This will display post excerpt of 25 characters. For more option to customize excerpt check the following link.
https://developer.wordpress.org/reference/functions/the_excerpt/
Hope this helps.
In single.php I use <?php the_category(', '); ?>. This function lists categories attached to post, but title attribute (on hover) is missing. How can I add this? I've tried with adding a filter in functions.php and making a new function like <?php the_better_category('%cat% - my text'); ?>, but the result is miserable.
From the WordPress Codex:
<?php single_cat_title( '', true ); ?>
The first part (in single quotes) will output whatever custom text you put there before the category title and true means it will display (false is use in PHP).
Have you tried:
<?php
$categories = get_the_category();
$separator = ' ';
$output = '';
if($categories){
foreach($categories as $category) {
$output .= ''.$category->cat_name.''.$separator;
}
echo trim($output, $separator);
}
?>
I want to make in my style for WP excerpt like
HERE
When post title is higher, excerpt is reduced to smaller.
Its a plugin or something else?
I just found a solution to limiting the number of words in the excerpt without plugins. Add the following code to your functions.php file.
<?php
// Custom Excerpt
function excerpt($limit) {
$excerpt = explode(' ', get_the_excerpt(), $limit);
if (count($excerpt)>=$limit) {
array_pop($excerpt);
$excerpt = implode(" ",$excerpt).'...';
} else {
$excerpt = implode(" ",$excerpt);
}
$excerpt = preg_replace('`\[[^\]]*\]`','',$excerpt);
return $excerpt;
}
// Content Limit
function content($limit) {
$content = explode(' ', get_the_content(), $limit);
if (count($content)>=$limit) {
array_pop($content);
$content = implode(" ",$content).'...';
} else {
$content = implode(" ",$content);
}
$content = preg_replace('/\[.+\]/','', $content);
$content = apply_filters('the_content', $content);
$content = str_replace(']]>', ']]>', $content);
return $content;
}
?>
If you want to limit your excerpt to 25 words the code would look like this:
<?php echo excerpt(25); ?>
<?php echo content(25); ?>
Another way to display limited excerpt by character. Here is the functions.php file code.
<?php
function get_excerpt(){
$excerpt = get_the_content();
$excerpt = preg_replace(" (\[.*?\])",'',$excerpt);
$excerpt = strip_shortcodes($excerpt);
$excerpt = strip_tags($excerpt);
$excerpt = substr($excerpt, 0, 100);
$excerpt = substr($excerpt, 0, strripos($excerpt, " "));
$excerpt = trim(preg_replace( '/\s+/', ' ', $excerpt));
$excerpt = $excerpt.'... Read More';
return $excerpt;
}
?>
After this you need to add where you want to display your customized character by character.
<?php echo get_excerpt(); ?>
Source: Web Design Company Bangladesh
Do it with CSS:
.truncated_exercept{
overflow:hidden;
text-overflow:ellipsis;
}
but in more then one line in current CSS is not possible with nice … (...) ending, have to use one of js or js+jQuery solutions look there:
http://dotdotdot.frebsite.nl/
I'm using this function to split the content
function split_content() {
global $more;
$more = true;
$content = preg_split('/<span id="more-\d+"><\/span>/i', get_the_content('more'));
for($c = 0, $csize = count($content); $c < $csize; $c++) {
$content[$c] = apply_filters('the_content', $content[$c]);
}
return $content;
}
Now I'm using a shortcode to display an icon, the problem is that no mater where i put it in the content, it always is displayed before the split content function, is the're a way to do the shortcode after the split content function?
The shortcode function
add_shortcode( 'ikona', 'add_device_icon' );
function add_device_icon($attr){
global $post;
$icons = array(0=>'wybierz',1=>'piekarnik',2=>'frytkownica',3=>'mikrofalówka',4=>'patelnia',5=>'garnek',6=>'grill',7=>'opiekacz');
$icon_number = get_post_meta( $post->ID, 'product-icon-type', true );
extract( shortcode_atts( array( 'do' => ''), $atts ) );
$style='';
if($do!=''){
$style = 'style="float:left"';
}
echo "<span class='icon-$icon_number' title='{$icons[$icon_number]}' $style></span>";
}
The content is displayed in the wordpress loop
<div class='holder'>
<h3><?php the_title() ?></h3>
<?php $content = split_content() ?>
<?php echo $content[0] ?>
<?php if(count($content )> 1 ) :?>
zobacz więcej…
<?php endif ?>
</div>
<div class="more">
<?php echo $content[1] ?>
</div>
I have to get specific page content (like page(12))
I used that :
<?php $id=47; $post = get_page($id); echo $post->post_content; ?>
Work nice execpt for compatibility with translations, it returns both French and English text
But the loop is fine, return only the good language version
<?php if(have_posts()) : while(have_posts()) : the_post(); ?>
<div id="post">
<?php the_content(); ?>
</div> <!-- .post -->
So the question.... HOW to get a specific page content inside the loop...
I've answered my own question. Call apply_filter and there you go.
<?php
$id=47;
$post = get_post($id);
$content = apply_filters('the_content', $post->post_content);
echo $content;
?>
get page content by page name:
<?php
$page = get_page_by_title( 'page-name' );
$content = apply_filters('the_content', $page->post_content);
echo $content;
?>
I used this:
<?php echo get_post_field('post_content', $post->ID); ?>
and this even more concise:
<?= get_post_field('post_content', $post->ID) ?>
A simple, fast way to get the content by id :
echo get_post_field('post_content', $id);
And if you want to get the content formatted :
echo apply_filters('the_content', get_post_field('post_content', $id));
Works with pages, posts & custom posts.
Just only copy and paste this code it will get your page content.
<?php
$pageid = get_the_id();
$content_post = get_post($pageid);
$content = $content_post->post_content;
$content = apply_filters('the_content', $content);
$content = str_replace(']]>', ']]>', $content);
echo $content;
?>
The wp_trim_words function can limit the characters too by changing the $num_words variable. For anyone who might find useful.
<?php
$id=58;
$post = get_post($id);
$content = apply_filters('the_content', $post->post_content);
$customExcerpt = wp_trim_words( $content, $num_words = 26, $more = '' );
echo $customExcerpt;
?>
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array( 'prev_text' >' Previous','post_type' => 'page', 'posts_per_page' => 5, 'paged' => $paged );
$wp_query = new WP_Query($args);
while ( have_posts() ) : the_post();
//get all pages
the_ID();
the_title();
//if you want specific page of content then write
if(get_the_ID=='11')//make sure to use get_the_ID instead the_ID
{
echo get_the_ID();
the_title();
the_content();
}
endwhile;
//if you want specific page of content then write in loop
if(get_the_ID=='11')//make sure to use get_the_ID instead the_ID
{
echo get_the_ID();
the_title();
the_content();
}
One liner:
<? if (have_posts()):while(have_posts()): the_post(); the_content(); endwhile; endif; ?>