• Resolved SimonGiddings

    (@simongiddings)


    I have seen that when posts are displayed, they have a “class” of their category embedded within the article container.
    For example :

    <article class="post-49 post type-post status-publish format-standard
    hentry category-projet row-fluid" id="post-49">
        ....
    </article>

    As can be seen here, the post has been categorised in the project category.

    I would like to be able to equally categorise pages that I create – or something like it.

    Why ?

    Well, this would enable me to change the format-icon definition depending on the category used.

    However, I do not see any category section within the admin page for creating pages.
    If I try by creating a custom field, this is not output in the same way.

    Am I pushing too far ?
    Is this kind of behaviour possible ?

Viewing 9 replies - 1 through 9 (of 9 total)
  • Look at the body tag of your categories pages.

    Thread Starter SimonGiddings

    (@simongiddings)

    Sorry, but I do not see where you are referring to.
    There are no categories for pages.

    Sorry I thought you meant categories pages, you meant wordpress pages.
    You want to categorize pages, you can do that, for example.. using the same template. Isn’t that beautiful but..
    Create as many templates as the “cagetories pages” you want, and then you can style them because the template you will use will be one of the class of the body tag of those pages.

    <body class="page page-id-48 page-template-default" itemscope itemtype="https://schema.org/WebPage">

    In this case “page-template-default”, or

    <body class="page page-id-48 page-template page-template-custom-page-php logged-in admin-bar no-customize-support" itemscope itemtype="https://schema.org/WebPage">

    if you use the custom template.. and so on

    Thread Starter SimonGiddings

    (@simongiddings)

    Totally agree with you.

    However …. my case is where I am displaying excerpts of these same pages with the blog articles on the home page.
    This is what you helped me with before today :
    Adding last published pages to home page

    This is where I am lifting up the <article …> tag I mentioned at the beginning.

    Mmm, wanna try this?

    add_filter('tc_article_selectors', 'my_selectors');
    function my_selectors($selectors){
        global $post;
        if ($post -> post_type == 'page'){
            $page_id = get_the_ID();
            $template_slug = get_page_template_slug( $page_id );
    
            if ( ! empty($template_slug) )
                $class = 'page-template-' . sanitize_html_class( str_replace( '.', '-', $template_slug ) );
            else
               $class = 'page-template-default';
    
            $selectors = str_replace('class="','class="'.$class.' ', $selectors);
        }
        return $selectors;
    }

    This will put the above mentioned template class in the article class.

    Thread Starter SimonGiddings

    (@simongiddings)

    Excellent !
    Thank you for this excellent work. +1 ??

    Thread Starter SimonGiddings

    (@simongiddings)

    Resolved

    Totally missed your reply, sorry.
    Glad you solved ??

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Categorise pages’ is closed to new replies.