WordPress.org

Support

Support » How-To and Troubleshooting » Link Category header change number

Link Category header change number

  • In default theme, has this method to get link categories and all links:
    get_links_list
    But the categories are surrounded by h2 tags; how do i change this to h3?

    (ideally without having to mess with the actual method itself, so its easier to update)

    is there a similar method that accepts a parameter of ‘title=h3’ or something? tried looking on codex but couldnt find what I’m after.

Viewing 5 replies - 1 through 5 (of 5 total)
  • http://wordpress.org/support/topic/24245

    Or you can just style them through the CSS file, by using something like:
    #nav h2 {... or similar depending in which div they are.

    I’m new to php, but couldn’t you do something like this?

    <?php
    $tempstr = get_links_list();
    for ( $i = 0; $i < strlen ( $tempstr ); $i++) {
    if ( substr ( $tempstr, $i, 4) == '<h2>' ) {
    echo "<h3>";
    $i = $i + 3;
    elseif ( substr ( $tempstr, $i, 5) == '</h2>' ) {
    echo "</h3>";
    $i = $i + 4;
    else {
    $l = substr ( $tempstr, $i, 1 );
    echo $l;
    ?>

    This is untested, but I have plans to do something similar with my own templates. I must say that I’m disappointed to find WP exhibiting this kind of behavior in the first place — I hope that eventually all formating will be left to the template designer. It certainly looks like such functionality is being built into the tag system.

    No doubt this is sucky code to begin with, but I realized I forgot closing brackets:

    <?php
    $tempstr = get_links_list();
    for ( $i = 0; $i < strlen ( $tempstr ); $i++) {
    if ( substr ( $tempstr, $i, 4) == '<h2>' ) {
    echo "<h3>";
    $i = $i + 3;
    } elseif ( substr ( $tempstr, $i, 5) == '</h2>' ) {
    echo "</h3>";
    $i = $i + 4;
    } else { $l = substr ( $tempstr, $i, 1 ); echo $l; }
    } ?>

    Gah! I’m trying to get this to work, but I’m stuck. I did some digging and rewrote the code thusly:

    <?php
    $string = get_links_list('order');
    $pattern = '/<h2>(.*?)</h2>/';
    $replacement = '<h3>\\1</h3>';
    echo preg_replace( $pattern, $replacement, $string );
    ?>

    For the life of me, I cannot get it to work. I’ve even tried running very simple preg_replace queries and they aren’t working. I’m missing something.

    Ah ha!

    <?php
    ob_start();
    get_links_list('order');
    $string = ob_get_contents();
    ob_end_clean();
    ob_end_flush();
    $patterns[0] = '/echo/';
    $patterns[1] = '/h2/';
    $replacements[0] = '';
    $replacements[1] = 'h3';
    preg_replace( $patterns, $replacements, $string );
    ?>

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Link Category header change number’ is closed to new replies.
Skip to toolbar