ThemeShaper Forums » ThemeShaper WordPress Themes

[closed]

Filtering postheaders

(10 posts)
  • Started 8 years ago by erikas_boy
  • Latest reply from erikas_boy
  • This topic is resolved
  1. So here's the deal:
    I wanted to add a custom div in a child theme I'm building for a client that holds a "splash" on the front page and a section name for other pages, where the section name is the same as the name of the parent pages ("articles", "services", etc). So obviously, I don't want the postheader directly underneath displaying the same word again. So I needed to filter it out. BUT I needed to keep the titles there for children pages. So this is what I put in my functions.php:


    // ---------- Add a Landing Splash/Sections

    // Identify Parents and Children

    function is_tree($pid) {
    global $post;
    $anc = get_post_ancestors( $post->ID );
    foreach($anc as $ancestor) {
    if(is_page() && $ancestor == $pid) {
    return true;
    }
    }
    if(is_page()&&(is_page($pid)))
    return true;
    else
    return false;
    };

    //Add Splash/section divs

    function splash() {
    if (is_front_page() & !is_paged()) { ?>
    <div id="splash">
    <div id="quotes">
    <p>TransitionMatters is an organization specializing in successful tranisitions with specific emphasis on the needs of small businesses and the leaders in those businesses that are experiencing or anticipating organizational of personal transition.</p>
    <p class="bottom">It is not the strongest of the species that survives, nor the most intelligent, but the one most responsive to change." - Charles Darwin </p>
    </div>
    </div>

    <?php }

    if (is_tree('3')){ ?>
    <div id="section">
    <h2>Services</h2>
    </div>
    <?php }

    if (is_tree('5')){ ?>
    <div id="section">
    <h2>Links</h2>
    </div>
    <?php }

    if (is_tree('9')){ ?>
    <div id="section">
    <h2>Contact</h2>
    </div>
    <?php }

    if (is_tree('15')){ ?>
    <div id="section">
    <h2>Blog</h2>
    </div>
    <?php }

    if (is_tree('7')){ ?>
    <div id="section">
    <h2>Articles</h2>
    </div>
    <?php }

    if (is_tree('21')){ ?>
    <div id="section">
    <h2>About Us</h2>
    </div>
    <?php }

    }
    add_action('thematic_belowheader', 'splash');

    // Remove Titles from Parent Pages
    function remove_posttitle($posttitle) {
    global $post;

    if ( is_page() && $post->post_parent ) {
    return $posttitle ;

    } else {
    return '<div id="hiddentitle">' . $posttitle . '</div>';
    }

    }
    add_filter('thematic_postheader_posttitle','remove_posttitle');

    Where "hiddentitle" is a div with display set to "none". So far so good. But my front page is not the blog loop, it's a static page. And when I click into my "blog" menu item, there is no splash. But you will note that I did add the blog id (15) as one of the section titles.

    Any ideas how to get that pesky section title on my blog page? Is this totally confusing? Is there a much easier way to do this? I am doing this on a local server, so I don't have a link to show what I'm doing, sorry.
    Thanks in advance.
    Chris

    Posted 8 years ago #
  2. Hmmmm,
    Still nothing, eh? I've messed around trying changing the "is_tree" to a variety of other filtering options, but none of them work, and it really seems like the original try should have worked. The worst part is, I have been searching a variety of forums and guides, and can't find much on filtering when blog posts aren't the front page.
    Any help is welcomed.
    C

    Posted 8 years ago #
  3. GAH!

    if (is_home()){ ?>
    <div id="section">
    <h2>Blog</h2>
    </div>

    gets the pesky blog title up there now.

    So, now to the new problem. By removing the titles from the pages, I've also removed the blog post titles, thus removing the permalink.....
    I'm looking for ideas, but any suggestons would be nice.
    Thx
    C

    Posted 8 years ago #
  4. I should note, part of why I'm annoyed, is that "is_home" sounds like it's going to point at the front page, but I found in the wordpress.org forums a mod who confirmed that it will point to the blog loop, whether it's the front page or not.

    Posted 8 years ago #
  5. Okay, if you're in the same boat as me, we just bumped into the harbour wall:

    Take this chunk:


    // Remove Titles from Parent Pages
    function remove_posttitle($posttitle) {
    global $post;

    if ( is_page() && $post->post_parent ) {
    return $posttitle ;

    } else {
    return '<div id="hiddentitle">' . $posttitle . '</div>';
    }

    }
    add_filter('thematic_postheader_posttitle','remove_posttitle');

    and make it:


    // Remove Titles from Parent Pages
    function remove_posttitle($posttitle) {
    global $post;

    if ( is_page() && $post->post_parent ) {
    return $posttitle ;
    }

    elseif ( is_home()) {
    return $posttitle ;
    } else {
    return '<div id="hiddentitle">' . $posttitle . '</div>';
    }

    }
    add_filter('thematic_postheader_posttitle','remove_posttitle');

    Happy Days.

    Posted 8 years ago #
  6. Oops, just realized this solution isn't, erm, a solution, as single page posts in the blog now don't have the section name displayed, and their titles are gone too. Don't think it will be hard to fix, but I'm off to the bar, and will have to do it later.

    Posted 8 years ago #
  7. Okay, pretty easy to do, actually, as expected.

    first off, get rid of this:

    if (is_home()){ ?>
    <div id="section">
    <h2>Blog</h2>
    </div>

    and replace it with:

    if ($paged <= "1"){ ?>
    <div id="section">
    <h2 class="blog">Blog</h2>
    </div>

    Okay, now you've got the Section title up there on all the blog pages (if you'd left the first "if (is_home)" bit, you'd have it twice).

    So, now we've got to get the titles back for the blog posts. So stick this in your remove_posttitle code:


    elseif ($paged <= "1"){
    return $posttitle ;
    }

    With me? Below is my final working code. Obviously, you can totally change all the .css references and html coding, whether you want big old section titles like me, or just a little doo-dad.


    // ---------- Add a Landing Splash/Sections

    // Identify Parents and Children

    function is_tree($pid) { // $pid = The ID of the page we're looking for pages underneath
    global $post; // load details about this page
    $anc = get_post_ancestors( $post->ID );
    foreach($anc as $ancestor) {
    if(is_page() && $ancestor == $pid) {
    return true;
    }
    }
    if(is_page()&&(is_page($pid)))
    return true; // we're at the page or at a sub page
    else
    return false; // we're elsewhere
    };

    //Add Splash

    function splash() {
    if (is_front_page() & !is_paged()) { ?>
    <div id="splash">
    <div id="quotes">
    <p>TransitionMatters is an organization specializing in successful tranisitions with specific emphasis on the needs of small businesses and the leaders in those businesses that are experiencing or anticipating organizational of personal transition.</p>
    <p class="bottom">It is not the strongest of the species that survives, nor the most intelligent, but the one most responsive to change." - Charles Darwin </p>
    </div>
    </div>

    <?php }

    if ($paged <= "1"){ ?>
    <div id="section">
    <h2 class="blog">Blog</h2>
    </div>

    <?php }

    if (is_tree('3')){ ?>
    <div id="section">
    <h2>Services</h2>
    </div>
    <?php }

    if (is_tree('5')) { ?>
    <div id="section">
    <h2>Links</h2>
    </div>
    <?php }

    if (is_tree('9')){ ?>
    <div id="section">
    <h2>Contact</h2>
    </div>
    <?php }

    if (is_tree('7')){ ?>
    <div id="section">
    <h2>Articles</h2>
    </div>
    <?php }

    if (is_tree('21')){ ?>
    <div id="section">
    <h2>About Us</h2>
    </div>
    <?php }

    }
    add_action('thematic_belowheader', 'splash');

    // Remove Titles from Parent Pages
    function remove_posttitle($posttitle) {
    global $post;

    // Display post titles on "children" pages
    if ( is_page() && $post->post_parent ) {
    return $posttitle ;
    }

    // Display post titles on the "Blog Loop" pages
    elseif ( is_home()) {
    return $posttitle ;
    }

    elseif ($paged <= "1"){
    return $posttitle ;
    }

    // Remove post titles from Non-front-page "Parent" pages
    else {
    return '<div id="hiddentitle">' . $posttitle . '</div>';
    }

    }
    add_filter('thematic_postheader_posttitle','remove_posttitle');

    Enjoy, and let me know if you have any questions.
    Chris

    Posted 8 years ago #
  8. Haha, I really shouldn't boast....

    Now the "Blog" Section title appears on *every* page.

    Fix to follow.....

    Posted 8 years ago #
  9. Okay,
    Get rid of that:


    if ($paged <= "1"){ ?>
    <div id="section">
    <h2 class="blog">Blog</h2>
    </div>

    That made me so happy to add. Put back the:


    if (is_home()){ ?>
    <div id="section">
    <h2>Blog</h2>
    </div>

    and add


    if (is_single()){ ?>
    <div id="section">
    <h2>Blog</h2>
    </div>

    Now (and this should be obvious)
    remove:


    elseif ($paged <= "1"){
    return $posttitle ;
    }

    and change it to:


    elseif (is_single()){
    return $posttitle ;
    }

    See what I'm doing? It's so effing easy, it pains me to know how long it took me to get to it. So (hopefully) for the last time (though, no promises):


    // ---------- Adding the logo image to the header ENDS HERE

    // ---------- Add a Landing Splash/Sections

    // Identify Parents and Children

    function is_tree($pid) { // $pid = The ID of the page we're looking for pages underneath
    global $post; // load details about this page
    $anc = get_post_ancestors( $post->ID );
    foreach($anc as $ancestor) {
    if(is_page() && $ancestor == $pid) {
    return true;
    }
    }
    if(is_page()&&(is_page($pid)))
    return true; // we're at the page or at a sub page
    else
    return false; // we're elsewhere
    };

    //Add Splash

    function splash() {
    if (is_front_page() & !is_paged()) { ?>
    <div id="splash">
    <div id="quotes">
    <p>TransitionMatters is an organization specializing in successful tranisitions with specific emphasis on the needs of small businesses and the leaders in those businesses that are experiencing or anticipating organizational of personal transition.</p>
    <p class="bottom">It is not the strongest of the species that survives, nor the most intelligent, but the one most responsive to change." - Charles Darwin </p>
    </div>
    </div>

    <?php }

    if (is_home()){ ?>
    <div id="section">
    <h2 class="blog">Blog</h2>
    </div>

    <?php }

    if (is_single()){ ?>
    <div id="section">
    <h2 class="blog">Blog</h2>
    </div>

    <?php }

    if (is_tree('3')){ ?>
    <div id="section">
    <h2>Services</h2>
    </div>
    <?php }

    if (is_tree('5')) { ?>
    <div id="section">
    <h2>Links</h2>
    </div>
    <?php }

    if (is_tree('9')){ ?>
    <div id="section">
    <h2>Contact</h2>
    </div>
    <?php }

    if (is_tree('7')){ ?>
    <div id="section">
    <h2>Articles</h2>
    </div>
    <?php }

    if (is_tree('21')){ ?>
    <div id="section">
    <h2>About Us</h2>
    </div>
    <?php }

    }
    add_action('thematic_belowheader', 'splash');

    // Remove Titles from Parent Pages
    function remove_posttitle($posttitle) {
    global $post;

    // Display post titles on "children" pages
    if ( is_page() && $post->post_parent ) {
    return $posttitle ;
    }

    // Display post titles on the "Blog Loop" pages
    elseif ( is_home()) {
    return $posttitle ;
    }
    elseif ( is_single()) {
    return $posttitle ;
    }

    // Remove post titles from Non-front-page "Parent" pages
    else {
    return '<div id="hiddentitle">' . $posttitle . '</div>';
    }

    }
    add_filter('thematic_postheader_posttitle','remove_posttitle');

    Posted 8 years ago #
  10. Still solved, but (if you're keen-eyed) you'll note I need to clean-up my header tags to be semantically correct (which is pretty straight-forward. Gotta make it an <h1> for the "parent" categories, and keep them <h2>s for the "children"). Just thought I'd mention it...... Too tired to now though. Bed now, semantic mark-up tomorrow.

    Posted 8 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.