By laurent on Wednesday, 01 April 2020
Posted in Technical Issues
Replies 2
Likes 0
Views 518
Votes 0
Hello,

I need a specific text for readmore button for a specific category, i try in default.main.php whith this PHP code

<?php if ($categoryid = 2) {echo 'My custom text';} else {echo JText::_('COM_EASYBLOG_CONTINUE_READING');}?>

but it don't work, an idea ?

Thanks.
Hum i found, it is because i need ==

<?php if ($category->id == 2) {echo 'dsfsdfsdf';} else {echo JText::_('COM_EASYBLOG_CONTINUE_READING');}?>
·
Wednesday, 01 April 2020 22:31
·
0 Likes
·
0 Votes
·
0 Comments
·
A post can be posted into multiple category, therefore you want to check against it's primary category, https://take.ms/nvon1

To get a post's primary category, this is the code that you would want to use:


<?php
$primaryCategory = $post->getPrimaryCategory();

if ($primaryCategory->id == 10) {
echo "Category 10";
} else {
echo "Not category 10";
}
?>


Hope this helps! By the way, if you find this helpful, please set this topic as public as it would help others as well
·
Wednesday, 01 April 2020 22:36
·
0 Likes
·
0 Votes
·
0 Comments
·
View Full Post