ethanbeyer

HTML Body Classes Module

15 posts in this topic

Excuse me for the question but what is the benefit of a module instead of using a function?

Share this post


Link to post
Share on other sites

@ethfun, thanks for the module :)

I suggest you prefix the classes coming from the parent pages with "parents-" (or better "parent-" for the direct parent and "parents-" for grandparents). This is because a page name may start with a digit but CSS selectors don't like that.

Quote

In CSS, identifiers (including element names, classes, and IDs in selectors) can contain only the characters [a-zA-Z0-9] and ISO 10646 characters U+00A0 and higher, plus the hyphen (-) and the underscore (_); they cannot start with a digit, two hyphens, or a hyphen followed by a digit.

That is from the CSS2 spec - I can't lay my hands on the CSS3 equivalent right now but I believe it is still advisable to avoid classes starting with digits.

2 people like this

Share this post


Link to post
Share on other sites
9 hours ago, tpr said:

Excuse me for the question but what is the benefit of a module instead of using a function?

Anyone can install it with a few clicks ;) 

1 person likes this

Share this post


Link to post
Share on other sites

I'm still not convinced it's easier :) If there would multiple helper methods in the module I would say it's beneficial. Having a module for such simple things is sooo... wordpress :)

Classes starting with digits are OK in css3 afaik but I also try to avoid them.

1 person likes this

Share this post


Link to post
Share on other sites
<?php $bodyout = $page->name . " template-" . $page->template . " page-id-" . $page->id; ?>
<body class="<?php echo $bodyout; ?>">

here you go..


like @tpr said: :frantics:

Quote

Having a module for such simple things is sooo... wordpress :)

 

Share this post


Link to post
Share on other sites

@Robin S thanks for the feedback! I will make that change.

 

@maxf5 I see what you're saying completely - but I am also endeavoring to keep my sites from disintegrating into the norm of wordpress sites - being made up of gazillions of similar, undocumented functions. At least with a module they're easy to find...

 

I also plan to add more functionality to the module in the long run. I like your one-line solution, but as much as anything else, it was an educational experience for me, that's all! :P

2 people like this

Share this post


Link to post
Share on other sites

It might be interesting to have a module with general functions for the many common problems that we find here every day. Something similar to what Ryan did with the uikit file. I know that just could be a simple file for include like _func.php, but I like much more the module format because it's more easy to include it directly from the repository, easy locate the last version (updated, enhanced and fixed) As a plus maybe you can configure which features to include before you download it..

2 people like this

Share this post


Link to post
Share on other sites

i have a theme engine module that i use which is part of a suite of modules that together, provide a frontend, or 'markup' api.

The Theme Engine handles things like the body classes and is basically a wrapper module for a collection of functions/methods helpful for optimizing front end development. It includes helpers for webfonts and facilitates the handling of the site assets, enabling each template to add dependencies (js or css files, or inline scripts/styles), as well as acting as a wrapper for ProCache whereby it allows the developer to enable/disable ProCache minification as needed. For example, superusers may disable minification and the module will output the individual assets with a url paramter appended to prevent caching. It also provides a simple 'hook' system where the developer can add containers to the main template, into which templates can 'inject' markup, similar to Wordpress do_action.

The Meta Engine reads settings from a settings module where the admins can enter the primary settings for the site, such as site title, copyright year and holder, publisher, social media links, contact information and more and provides an easy API to access those settings, as well as formatting for convenience. It also allows for individual templates to add and modify items to the header and footer, such as prefetch/prerender, next/prev, schema, open graph tags, custom favicon sets, and any custom markup.

other members of the suite are a Blog Engine, and Events/Calendar Engine.

6 people like this

Share this post


Link to post
Share on other sites

Wow! Just for curiosity, how many hours/years did take you to be in that moment? ..To calculate if I can finish my own "engine" before retiring jjj because I'm right now in the middle of my first "advance" stuff for social media tasks .. Congratulations

Share this post


Link to post
Share on other sites
1 hour ago, Macrura said:

and Events/Calendar Engine

That sounds interesting - could you say a bit more about that? Does your module have support for recurring events? Variations to recurring events? And does it have a calendar interface in admin?

PW really needs a good calendar/events module.

2 people like this

Share this post


Link to post
Share on other sites
10 hours ago, Pixrael said:

Wow! Just for curiosity, how many hours/years did take you to be in that moment? ..To calculate if I can finish my own "engine" before retiring jjj because I'm right now in the middle of my first "advance" stuff for social media tasks .. Congratulations

most of the functions were previously in helper files and called procedurally, there is nothing too complicated about any of the functions; i just finally figured it was time to put them all into a module so that i could have a config screen and not worry about field naming between sites, because the config screen lets the module's methods be field-agnostic (for example in the blog engine, you would tell it what field is used for date, what the posts index page is, post index template etc)... I will probably put it on GitHub once it has been tested more in some varied environments. You can find a lot of these types of functions in other modules, depending on your specific needs, or don't even use a module for it, a lot of developers just put each thing into a partial and then include or wireRenderFile them all in the main template.

10 hours ago, Robin S said:

That sounds interesting - could you say a bit more about that? Does your module have support for recurring events? Variations to recurring events? And does it have a calendar interface in admin?

the events engine that i'm using is just helpers for front end, so primarily deals with date formatting, handling feeds, URL segments for things like archive or month/year based results (/calendar/year/2016/), categories and tags if those are used, media (images/audio/video), related events, and schema.. recurring events are usually handled with either a multiplier for a date field, a table, or a page table, depending on the needs of the site. The Elliott Carter events listing uses a page table for recurring events because each event recurrence can actually be in a different location (for example a tour).

2 people like this

Share this post


Link to post
Share on other sites
47 minutes ago, Macrura said:

I will probably put it on GitHub once it has been tested more in some varied environments

I will happily help you with this - it seems like your modules totally pwn the one I wrote. I'd love to try it out!

Share this post


Link to post
Share on other sites

That would be great - i will probably need a few weeks to sort out some issues;

the theme module works by using a new WireData within global $config to store everything, and it gets initialized manually;
i am trying to decide about this, and whether it should just create it's own api variable; if using $config, then it makes it easier for submodules to intercommunicate, because there is sitting the $config and then a module can check to see if there is a property in there to use; also with the theme's headAssets method, it will be better once the minification engine can be selected, right now it is hardcoded to use ProCache, but plans are in place to make it selectable between ProCache, AIOM+, or none. Another thing i have to implement is a way to register your injectable areas; right now the module init defines those, but there probably needs to be a hook or method where you can register the areas in your theme, like wp add_action..

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.