2023-12-11, 10:33 PM
(This post was last modified: 2023-12-12, 10:16 PM by Joey_Pham423. Edited 4 times in total.)
Hi all,
I just want to share this MyCode I whipped up. It's pretty self-explanatory. I wrote this for my forum because I don't want to have posts that are too long. Sure, some people can say I could just use hide or spoiler plugins, but those completely hide the contents I believe. This one will work almost like an excerpt of a WordPress blog post, but for chosen parts of a post:
Demo: https://mybb.vn/Thread-test-test-more-ta...180#pid180
Let's get started:
1. Add this into your global.css:
2. Add this into your headerinclude template:
3. Add MyCode:
Regular expression:
Replacement:
4. How to use:
Feel free to style or change it to fit your forum's needs. If there's enough request I can turn it into a simple plugin with some basic options. But for now, enjoy this MyCode tutorial
I just want to share this MyCode I whipped up. It's pretty self-explanatory. I wrote this for my forum because I don't want to have posts that are too long. Sure, some people can say I could just use hide or spoiler plugins, but those completely hide the contents I believe. This one will work almost like an excerpt of a WordPress blog post, but for chosen parts of a post:
Demo: https://mybb.vn/Thread-test-test-more-ta...180#pid180
Let's get started:
1. Add this into your global.css:
/*Read More CSS*/
.readmore {
border: 1px solid #214f7e;
background-color: #fdf6e3;
transition: max-height 0.5s ease;
overflow: hidden;
max-height: 150px;
width: 90%;
margin: 10px auto;
padding: 15px;
border-left: 4px solid #214f7e;
position: relative;
}
.readmore.expanded {
max-height: none /* Set height to auto for expanded state */
}
.readmore-button-container {
position: relative;
color: #214f7e;
border-bottom: 1px solid #214f7e;
padding-bottom: 3px;
margin: 0 0 10px 0;
font-style: normal;
font-weight: bold;
}
.readmore-button {
margin-right: 10px;
}
/*End Read More CSS */
2. Add this into your headerinclude template:
<script>
function toggleReadMore(button) {
var content = button.closest('.readmore');
content.classList.toggle('expanded');
var readMoreButton = content.querySelector('.readmore-button');
if (content.classList.contains('expanded')) {
readMoreButton.innerHTML = "Read Less";
} else {
readMoreButton.innerHTML = "Read More";
}
}
</script>
3. Add MyCode:
Regular expression:
\[more\](.*?)\[/more\]
Replacement:
<div class="readmore">
<div class="readmore-button-container">
<button class="readmore-button" onclick="toggleReadMore(this)">Read More</button>
</div>
<p>$1</p>
</div>
4. How to use:
[more] Your long, lengthy content here [/more]
Feel free to style or change it to fit your forum's needs. If there's enough request I can turn it into a simple plugin with some basic options. But for now, enjoy this MyCode tutorial