• Hallo
    I am a beginner i php and wordpress and i want some help.
    I wounder wher i can find who i gone do to have subpages in a page in wordpress? i have see a code like that

      <?php wp_list_pages(‘child_of=8&title_li=’);?>

    What do this code? can i find som plugin to use?
    And if i have several of pages that i want to have suppages on. Who can i fix that?

    Somthing like this

    The menu on the top in the header.php

    about (the page and under it the subpages)

    :: my camera
    :: my car
    :: my brother

    I hope you can give me some tip
    /Apel

Viewing 12 replies - 1 through 12 (of 12 total)
  • Everything is here:
    http://codex.wordpress.org/Template_Tags/wp_list_pages

    The code you have says: Display in a list only subpages of the Page that has ID number 8. So if your page “About” has the ID number 8, it will show its subpages.
    In the Codex link above, you will see how to show subpages for all main pages. So, you will not have to make an extra code for every page (i.e. Page ID 9, 10, etc.), but WordPress will do it automatically.

    Thread Starter Apel

    (@apel)

    Tanks.
    /Apel

    Thread Starter Apel

    (@apel)

    Yes its works!
    Now if i have this code
    <?php wp_list_pages(‘child_of=8&title_li=’);?> i want to have a images in the code can any one tells or show me who!

    /Apel

    I don’t understand, can you give me an example, show me a website where it is working?
    A plugin is doing this but only for Categories, not for Pages, like this one:
    http://www.coffee2code.com/wp-plugins/#categoryimages
    http://devcorner.georgievi.net/wp-plugins/wp-category-icons/

    You can add images to your Page lists – but it’ll appear on your Pages as well. There’s a workaround (I’ve had to do it before) but it takes a little effort.

    First, go to Write Page. in the “title” area, put in the HTML code for the image you want to appear. If you also want text, then type the text in, too.

    Write your page content, save.

    Now, in your list, the Page will appear with whatever you put in the title.

    The only thing is, though, that when the end user views the actual page itself, the title of the page will also be formatted in this same way. If you *don’t* want the image to appear with the title, then go back to the Page, and within the post itself (in the content area, before the actual content starts) add in:

    <h1>Post title here<h1>

    and in your stylesheet, add:

    div.post h2 {
    display:none;
    }

    and then give your div.entry h1 the formatting you want for the text. Now you have an image in your list, but the title for the actual page is text.

    Yeah, it’s some doing, but it works.

    Thread Starter Apel

    (@apel)

    Hi
    I wont to have a code that include an image in that code.
    <?php wp_list_pages (‘show a image her’)(‘child_of=8&title_li=’);?>
    so that

    • i wount an image.
      i hope some one understan?
      /Apel

    Well, you can’t do that! You’d have to write a plugin to do such a thing – the list_pages is a function that’s pre-written. To automatically add an image int he code would require custom coding to do so.

    If you’re wanting to add an image just to have one there in the nav bar, use your stylesheet to do it, or the method I described above. (But the method I described above is for *seriously* involved css reasons – if you’re just wanting to add an image with no certain and extremely involved coding reasons, then using your CSS will work just dandy.)

    Hi all,

    I’m a rookie in PHP, but I have some programming background. Today I’ve hacked successfully the issue of “associate an image with a category” in sidebars.
    You can check out how it works here: http://www.smuff.ro

    And there u are with the instructions:

    1. I’ve used the idea of “Category Icon Images” from http://www.nationaljoke.com/home/wordpress-plugins/. I mean the images shown for a category are .jpg files named after the category’s “nice_name”.
    2. Then I’ve hacked the /wp-includes/template-functions-category.php file’s list_cats() and wp_list_cats() function. First I’ve renamed the original functions to list_cats2() and wp_list_cats2() to keep WP original.
    3. I’ve put list_cats2() to attach image files to categories:

      $link = '|<img src="http://smuff.ro/wp-content/uploads-new/icons/'.$category->category_nicename.'.jpg" alt="" />';
    4. Then I’ve replaced the <li>, <ul> tags with delimiters like @, *, | to be able later to parse the generated result.
    5. Then I’ve put list_cats2() to return the generated string by replacing it’s default return code

      echo apply_filters('list_cats2', $thelist);

      with

      return $thelist;
    6. I’ve hacked then the sidebar.php to display my new fancy categories.

    There you are with the template functions modified:

    foreach ( (array) $categories as $category ) {
    if ( ( intval($hide_empty) == 0 || $category->category_count) && (!$hierarchical || $category->category_parent == $child_of) ) {
    $num_found++;
    $link = '|<img src="http://smuff.ro/wp-content/uploads-new/icons/'.$category->category_nicename.'.jpg" alt="" />';
    $link .= '|<a href="'.get_category_link($category->cat_ID).'" ';
    if ( $use_desc_for_title == 0 || empty($category->category_description) )
    $link .= 'title="'. sprintf(__("View all posts filed under %s"), wp_specialchars($category->cat_name)) . '"';
    else
    $link .= 'title="' . wp_specialchars(apply_filters('category_description',$category->category_description,$category)) . '"';
    $link .= '>';
    $link .= apply_filters('list_cats', $category->cat_name, $category).'</a>';
    if ( (! empty($feed_image)) || (! empty($feed)) ) {
    $link .= ' ';
    if ( empty($feed_image) )
    $link .= '(';
    $link .= '<a href="' . get_category_rss_link(0, $category->cat_ID, $category->category_nicename) . '"';
    if ( !empty($feed) ) {
    $title = ' title="' . $feed . '"';
    $alt = ' alt="' . $feed . '"';
    $name = $feed;
    $link .= $title;
    }
    $link .= '>';
    if ( !empty($feed_image) )
    $link .= "<img src='$feed_image' $alt$title" . ' />';
    else
    $link .= $name;
    $link .= '</a>';
    if (empty($feed_image))
    $link .= ')';
    }
    if ( intval($optioncount) == 1 )
    $link .= ' ('.intval($category->category_count).')|';
    if ( $optiondates ) {
    if ( $optiondates == 1 )
    $optiondates = 'Y-m-d';
    $link .= ' ' . gmdate($optiondates, $category_timestamp["$category->cat_ID"]);
    }
    if ( $list ) {
    /* $thelist .= "t<li"; */
    if (($category->cat_ID == $wp_query->get_queried_object_id()) && is_category()) {
    $thelist .= ' class="current-cat"';
    }
    /* $thelist .= ">$linkn"; */
    $thelist .= "*$link";
    } else {
    $thelist .= "t$link<br />n";
    }
    if ($hierarchical && $children)
    $thelist .= list_cats2($optionall, $all, $sort_column, $sort_order, $file, $list, $optiondates, $optioncount, $hide_empty, $use_desc_for_title, $hierarchical, $category->cat_ID, $categories, 1, $feed, $feed_image, $exclude, $hierarchical);
    if ($list)
    /* $thelist .= "</li>n"; */
    $thelist .= "**";
    }
    }
    if ( !$num_found && !$child_of ) {
    if ( $list ) {
    $before = '<li>';
    $after = '</li>';
    }
    echo $before . __("No categories") . $after . "n";
    return;
    }
    if ( $list && $child_of && $num_found && $recurse ) {
    /*
    $pre = "tt<ul class='children'>";
    $post = "tt</ul>n";
    */
    $pre = "@";
    $post = "@";
    } else {
    $pre = $post = '';
    }
    $thelist = $pre . $thelist . $post;
    if ( $recurse )
    return $thelist;
    /* echo apply_filters('list_cats2', $thelist); */
    return $thelist;
    }
    function list_cats($optionall ....

    And the code from Sidebar:

    <div>
    <h2 class="widgettitle">Catalog Produse</h2>
    <br/>
    <div class="category_table">
    <table class="category_table">
    <?php
    /* get all categories with images */
    $r = wp_list_cats2('optioncount=1&list=1&sort_column=ID');
    /* get each category w. subcategroies */
    $cats = explode('@', $r);
    /* build table */
    foreach ($cats as $c) {
    if ($c) {
    $kind = strpos(ltrim($c, "*"), "**");
    if ($kind === false) {
    /* main cat */
    $title = explode('|', $c);
    if ($title) {
    echo '<thead><tr><th colspan="2" class="category_table">' . $title[2] . '</th></tr></thead>';
    $img = array();
    $link = array();
    }
    }
    else {
    /* child cat */
    $body = explode('*', ltrim($c, "*"));
    foreach ($body as $b) {
    if ($b) {
    $t = explode('|', $b);
    $img[] = $t[1];
    $link[] = $t[2];
    } /* if */
    } /* foreach */

    /* build table cells */
    if ($img) {
    echo '<tbody><tr>';
    $i = 1;
    foreach ($img as $im) {
    echo '<td class="category_table">' . $im . '</td>';
    if (($i%2) == 0) {
    echo '</tr><tr>';
    echo '<td class="category_table">' . $link[$i-2] . '</td>';
    echo '<td class="category_table">' . $link[$i-1] . '</td>';
    echo '</tr><tr>';
    }
    $i++;
    }
    $j = count($link);
    if (($j%2) != 0) {
    echo '<td></td></tr>';
    echo '<tr><td class="category_table">' . $link[$i-2] . '</td><td></td></tr>';
    }
    echo '</tbody>';
    } /* endif img */
    } /* else */
    } /* if after foreach */
    } /*foreach */
    ?>
    </table>
    </div>
    </div>

    I hope it works also for you,
    Take care,
    cs.

    maybe this is not the perfect topic to show my solution, but all others discussing this issue were closed

    Post your code on your blog or at http://wordpress.pastebin.ca – we delete very long code portions from posts!
    Also, we do NOT encourage hacking core files; for the average user that’s not an option, it has to be updated with every upgrade.

    csbarton, if you added your code blocks to a plugin file it would

    1) make it easy for other users to use your code block

    2) ensure you can upgrade when new releases occur without grief

    Plugins Are Good πŸ™‚

    chicoman98

    (@chicoman98)

    Hi csbartus, thanks for the code example. I also checked out your site http://www.smuff.ro which is really slow to load. It appears you aren’t using the wp-cache plugin which I highly recommend using. I bet lots of people leave your site b/c it takes several seconds to fully render. Just trying to help so please don’t take it the wrong way. πŸ™‚

    ~David Cowgill

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘wp_list_pages(‘child_of=8&title_li=’)’ is closed to new replies.