WordPress.org

Ready to get started?Download WordPress

Forums

Link Category header change number (6 posts)

  1. fo3nix
    Member
    Posted 9 years ago #

    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.

  2. moshu
    Member
    Posted 9 years ago #

    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.

  3. nateomedia
    Member
    Posted 9 years ago #

    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.

  4. nateomedia
    Member
    Posted 9 years ago #

    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; }
    } ?>

  5. nateomedia
    Member
    Posted 9 years ago #

    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.

  6. nateomedia
    Member
    Posted 9 years ago #

    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 );
    ?>

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags