MyBB Community Forums

Full Version: Changing <body> in all templates script
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Is it possible to run a sql or php script to change all <body> attributes to <body="forums"> in all templates on a theme?

I don't know either sql or php so i'm not sure. just looking for a quick way to change <body> attribute in all templates.
1. <body="forums">? Did you mean <body class="forums"> or <body id="forums">?
2. what about jQuery?

jQuery(document).ready(function() {
  jQuery('body').attr('id', 'forums');
});
(2014-08-11, 05:06 PM)metonator Wrote: [ -> ]1. <body="forums">? Did you mean <body class="forums"> or <body id="forums">?
2. what about jQuery?

jQuery(document).ready(function() {
  jQuery('body').attr('id', 'forums');
});

Yea sorry i meant <body id="forums"> Thanks guys i'll try them out now.

Used your way metonator, thanks saved me alot of time.

EDIt: is it possible for the jquery script to not effect portal, search, members, calendar, help

It's an active tab so every time i click one of them it auto goes back to forums?
	var file_name, file_end, file_page, claimed_forum_pages, claimed_member_pages;
	
	claimed_forum_pages = ["forumdisplay", "showthread", "private", "usercp", "modcp", "stats", "newthread", "newreply"];
	claimed_member_pages = ["member"];

	file_name = document.location.href;
	file_end = (file_name.indexOf("?") == -1) ? file_name.length : file_name.indexOf("?");
	file_page = file_name.substring(file_name.lastIndexOf("/")+1, file_end);
	file_page = file_page.replace('.php','').replace('#','');

	$('body').addClass("page_" + file_page);
	
	if (file_page == '/' || file_page == '') {
		file_page = "index";
	}
	
	if ($.inArray(file_page, claimed_forum_pages) >= 0) {
		$('.menu li').removeClass('active');
		$(".menu").find('a[href *="index.php"]').parent("li").addClass("active");
	} else if ($.inArray(file_page, claimed_member_pages) >= 0) {
		$('.menu li').removeClass('active');
		$(".menu").find('a[href *="memberlist.php"]').parent("li").addClass("active");
	} else {
		$('.logorow_menu li').removeClass('active');
		$(".logorow_menu").find('a[href *="' + file_page  + '.php"]').parent("li").addClass("active");
	};

This is what we use to fix active tabs. It checks the URL you're currently on against links that are in the header menu, if it's not an already claimed page.
I don't know javascript but i tested your script and didn't work for me.

Thats what i'm trying to achieve. i have the active tab coded with, just don't fancy changing all the <body> in every template so looking for something to automate it ;/
Yeah this is built for a menu like:

<ul class="menu">
<li><a href="#">Link</a></li>
<li><a href="#">Link</a></li>
<li><a href="#">Link</a></li>
</ul>

It adds the class "active" to whatever page you're on. So you'd style .active {} in your CSS to make use of it. It also adds a class to the body so for example on the index, it will add class="page_index" to <body>.
(2014-08-12, 12:15 AM)iAndrew Wrote: [ -> ]Thats what i'm trying to achieve. i have the active tab coded with, just don't fancy changing all the <body> in every template so looking for something to automate it ;/

It's much easier to achieve with Template Conditionals, also faster than jQuery: http://mybbhacks.zingaburga.com/showthread.php?tid=464

Download, activate then add something like this to your menu links HTML:
<if THIS_SCRIPT == "index.php" then>class="menuactive"</if>
That checks if we're currently on index page, similar codes can be created for other scripts. Actions can be checked too (for instance to detect profile):
<if THIS_SCRIPT == "member.php" && $mybb->input['action'] == "profile" then>class="menuactive"</if>
Thanks but it's for a theme i'm gonna release so i wont use Template Conditionals otherwise people have to install another plugin. I done it now anyway just took time changing all templates.
How about you export the theme and replace the <body> tags with Notepad++?