Products
GG网络技术分享 2025-03-18 16:12 3
I am posting Hadiths in my website and i post it in 3 translations: Arabic, Urdu, English. In Hadith\'s page, where Hadiths are showing one by one, It\'s showing Arabic excerpt text.
See my web, Here is my Website link: IF Islam
I want here to show English Hadith excerpt text instead of Arabic and Urdu.
Which PHP code will do this?
Please help
Here is the content.php code:
<div class=\"col-lg-8 col-md-6\"><div class=\"card-body\">
<a href=\"<?php the_permalink(); ?>\" class=\"\">
<h2 class=\"single_post_title h3-responsive text-primary mb-1\"><?php the_title(); ?></h2>
</a>
<div class=\"blog_meta\">
<time class=\"blog_meta_posted_on grey-text\"><?php the_time(\'F j, Y g:i a\'); ?></time>
<a href=\"<?php echo get_author_posts_url(get_the_author_meta(\'ID\')); ?>\" class=\"blog_meta_author grey-text\"><?php the_author(); ?></a>
<a href=\"<?php the_permalink(); ?>#responses\" class=\"blog_meta_count_comments grey-text\"><?php echo get_comments_number(); ?> Comments</a>
<label class=\"blog_meta_tags_list\">
<?php echo get_the_tag_list( \'\', \', \', \'\' ); ?>
</label>
</div>
<div class=\"blog_excerpt_content black-text m-0 mt-2\">
<?php the_excerpt(); ?>
</div>
<a href=\"<?php the_permalink(); ?>\" class=\"btn btn-primary\">Read More</a>
</div>
</div>
Try to replace
<?php the_excerpt(); ?>
With
<?php$position = strpos(get_the_content(), \'Hadith in English Translation\');
$excerpt = strip_tags(substr(get_the_content(), $position));
echo $excerpt;
?>
I think get_the_content() returns the post full contents in HTML. We constructed a new $excerpt
starting from \'Hadith in English Translation\'
to the end of the post contents using the functions strpos and substr. We also stripped the excerpt from any HTML tags using strip_tags.
Of course you need to use the code only for the Hadith category (inside the \\\"category-hadith.php\\\" you added?) since you only need the modification there.
Check if it is working and note that the solution supposes that the post contents has always the string \'Hadith in English Translation\'
and the english translation comes in last position after the two others.
###
I think we need a little more information in order to answer your question correctly. For starters, could you show us your code that you use for showing the excerpts. Based on your question, i only can imagine that your literally typed Arabic text in the excerpt in your CMS.
Demand feedback