WordPress.org

Ready to get started?Download WordPress

Forums

Create multiple columns from long list of wp_list_bookmarks and wp_list_authors (12 posts)

  1. olivier-wp-forum
    Member
    Posted 4 years ago #

    Hi everyone,

    I am trying to write 2 new queries, but unfortunately, I haven't got the necessary skills to make it work...

    I have generated two "page" pages on my sites; one handling a query on Authors and one handling a query on Bookmarks.

    This is the code I currently have on my page template:

    <div class="post">
    
         <?php if (is_page('5904')) : ?> //the feed list page
    	<ul><?php wp_list_bookmarks('title_li=&categorize=0&category=24'); ?></ul>
         <?php endif; ?>
    
         <?php if (is_page('59427')) : ?> //the author list page
            <ul><?php wp_list_authors('show_fullname=1&optioncount=1&show_count=1'); ?></ul>
         <?php endif; ?>
    
         <?php the_content(); ?>
    
    </div>

    Both calls return a mile long bullet point list, which is not very attractive. I therefore would like to return each list on their respective pages in a controlled table. I am looking at a 3-column table for each list.

    I also found this thread and code on the WP forum but I am not able to modify the respective queries to work for wp_list_bookmarks and wp_list_authors.

    Would someone be able to help me to modify/put together the respective queries, while maintaining the UL and LI parameters, please?

    I would be most grateful.

    Many thanks,

    Cheers,

    Olivier

  2. ahmedjasim
    Member
    Posted 4 years ago #

    Hello ,

    You can control this by css .

    <?php if (is_page('5904')) : ?> //the feed list page
    	<ul class="bookmarks_list"><?php wp_list_bookmarks('title_li=&categorize=0&category=24'); ?></ul>
         <?php endif; ?>

    Now in css .

    .bookmarks_list li{
    width:100px ;/*you can adjust this*/
    display:block;
    float:left;
    padding:3px;
    }

    may be your problem is solved .

    Thanks
    Ahmed Jasim

  3. olivier-wp-forum
    Member
    Posted 4 years ago #

    Hi Ahmed,

    Thanks for your feedback. But your suggestions does not answer my question (sorry). I am trying to 'break' the long lists into several columns of a table.

    Meaning that for instance when column A, cell 1 reached (say) 50 records, it will create a second column B (to the right of column A). When columnB, cell 1 reaches 50 records, it'll create another third column C to the right of column B. When column C reaches its 50 records, it'll create a second row column A cell 2... ans so on and so forth.

    I can only see a PHP query being able to handle this, similar to the one shown in the thread I referred to in my original post above.

    Many thanks,

    Cheers,

    O

  4. olivier-wp-forum
    Member
    Posted 4 years ago #

    Hi,

    Really no one can help on this one?

    Many thanks,

    Cheers,

    Olivier

  5. night2008
    Member
    Posted 4 years ago #

    I think you'll have to create a table in your page's source code, and display a category of bookmarks or something in each cell...

    <table>
    <tr>
    <td>
    
    <ul class="bookmarks_list"><?php wp_list_bookmarks('title_li=&categorize=0&category=1'); ?></ul>
    
    </td>
    <td>
    
    <ul class="bookmarks_list"><?php wp_list_bookmarks('title_li=&categorize=0&category=2'); ?></ul>
    
    </td>
    <td>
    
    <ul class="bookmarks_list"><?php wp_list_bookmarks('title_li=&categorize=0&category=3'); ?></ul>
    
    </td>
    </tr>
    </table>

    This way, you can specify a category of bookmarks for each "column" in your table. It's also very easy to change the "layout" of your bookmarks page, by just changing the surrounding "container" code from a table, to a div-based layout for example.

    Kind regards and hoping to solve something ;-)
    Kim

  6. QueroMedia
    Member
    Posted 4 years ago #

    I think I solved your problem with the following code:

    <table class="bookmarks-table">
    	<?php
    	/**
    	* get_bookmarks()
    	*
    	* Retrieves the list of bookmarks
    	*
    	* Attempts to retrieve from the cache first based on MD5 hash of arguments. If
    	* that fails, then the query will be built from the arguments and executed. The
    	* results will be stored to the cache.
    	*
    	* List of default arguments are as follows:
    	* 'orderby' - Default is 'name' (string). How to order the links by. String is
    	*		based off of the bookmark scheme.
    	* 'order' - Default is 'ASC' (string). Either 'ASC' or 'DESC'. Orders in either
    	*		ascending or descending order.
    	* 'limit' - Default is -1 (integer) or show all. The amount of bookmarks to
    	*		display.
    	* 'category' - Default is empty string (string). Include the links in what
    	*		category ID(s).
    	* 'category_name' - Default is empty string (string). Get links by category
    	*		name.
    	* 'hide_invisible' - Default is 1 (integer). Whether to show (default) or hide
    	*		links marked as 'invisible'.
    	* 'show_updated' - Default is 0 (integer). Will show the time of when the
    	*		bookmark was last updated.
    	* 'include' - Default is empty string (string). Include other categories
    	*		separated by commas.
    	* 'exclude' - Default is empty string (string). Exclude other categories
    	*		separated by commas.
    	*
    	* @since 2.1.0
    	* @uses $wpdb Database Object
    	* @link http://codex.wordpress.org/Template_Tags/get_bookmarks
    	*
    	* @param string|array $args List of arguments to overwrite the defaults
    	* @return array List of bookmark row objects
    	*/
    	$bookmarks 	= get_bookmarks(); // add 'category=1' as parameter to limit the bookmarks to a category.
    	//	set counter to zero
    	$i 			= 0;
    	//	set the number of cols in our table rows
    	$cols 		= 4;
    	//	start an initial row
    	echo '<tr>';
    	//	loop through our returned bookmarks
    	foreach ($bookmarks as $bookmark) {
    		//	increment our counter
    		$i++;
    		//	print our link date and hyperlink to bookmark
    		//	access to the following vars:
    		/*
    		link_id,
    		link_url,
    		link_name,
    		link_image,
    		link_target,
    		link_description,
    		link_visible,
    		link_owner,
    		link_rating,
    		link_updated,
    		link_rel,
    		link_notes,
    		link_rss
    		*/
    		?>
    		<td class="archive-date"><?php echo date('d-m-Y', strtotime($bookmark->link_updated)) ?></td>
    		<td class="archive-title"><a href="<?php echo $bookmark->link_url ?>" rel="bookmark" title="Bookmark to <?php echo attibute_escape($bookmark->link_name) ?>" target="<?php echo attibute_escape($bookmark->link_target); ?>"><?php echo $bookmark->link_name ?></a></td>
    		<?php
    		//	if our counter is dividable by 4 (= the number of cols), close our row
    		if ( ( $i % $cols ) == 0 ) {
    			echo '</tr>' . "\n";
    			echo '<tr>';
    		}
    	}
    	//	close our initial (or last) row
    	echo '</tr>';
    	?>
    </table>

    Kind regards,
    Kim

  7. raphievila
    Member
    Posted 4 years ago #

    I think I solved your problem with the following code:

    Wow, awesome code... I used it for a wordpress blog I'm working on with a tweak to use it with posts instead of bookmarks this is the code:

    <table class="bookmarks-table" cellpadding="0" cellspacing="0" border="0">
                <th colspan="2">
                    <h4>Lista De Eventos</h4>
                </th>
                    <?php
    
                    query_posts('category_name=Eventos');// use your post category id or name here
                    /*
                     * showpost = to limit the quantity of post in the list ex. query_posts('category_name=Name&showpost=10')
                     * category = to enter category id
                     * category_name = to specify which post to be display
                     */
                    $i 	= 0;
                    $cols 	= 2;
                    echo '<tr>';
                    if(have_posts()): while (have_posts()) : the_post();
                            $i++;
                            ?>
                            <td class="archive-title" width="50%" valign="top"><div class="eachLink"><a href="<?php the_permalink(); ?>" rel="bookmark" title="Enlace para <?php the_title(); ?>" ><?php the_title(); ?></a></div></td>
                            <?php
                            if ( ( $i % $cols ) == 0 ) {
                                    echo '</tr>' . "\n";
                                    echo '<tr>';
                            }
                    endwhile;
    
                    else:
                        echo '<tr><td colspan="2">No hay Eventos enlistados a&uacute;n!</td>';
                    endif;
                    echo '</tr>';
                    ?>
            </table>

    Thanks for the inspiration... Blessings

    Hope this will help anyone.

  8. raphievila
    Member
    Posted 4 years ago #

    For those who are intereste in a function for your function.php page this is the code you need:

    <?php 
    
    function contentListTable($categoryName,$colQty){
    
        if (isset($colQty) && ($colQty > 1 || $colQty != '')):
            $colSpan = 'colspan='.$colQty;
        else:
            $colSpan = '';
        endif;
    ?>
    
    <div id="tableContent" class="post_details">
        <table class="bookmarks-table" cellpadding="0" cellspacing="0" border="0">
            <th <?php echo $colSpan; ?>>
                <h4>List for <?php echo $categoryName; ?></h4>
            </th>
                <?php
    
                query_posts('category_name='.$categoryName);// use your post category id or name here
                /*
                 * showpost = to limit the quantity of post in the list ex. query_posts('category_name=Name&showpost=10')
                 * category = to enter category id
                 * category_name = to specify which post to be display
                 */
                $i 	= 0;
                $cols 	= $colQty;
                echo '<tr>';
                if(have_posts()): while (have_posts()) : the_post();
                        $i++;
                        ?>
                        <td class="archive-title" width="50%" valign="top"><div class="eachLink"><a href="<?php the_permalink(); ?>" rel="bookmark" title="Enlace para <?php the_title(); ?>" ><?php the_title(); ?></a></div></td>
                        <?php
                        if ( ( $i % $cols ) == 0 ) {
                                echo '</tr>' . "\n";
                                echo '<tr>';
                        }
                endwhile;
    
                else:
                    echo '<tr><td <?php echo $colSpan; ?>>There are no list for '.$categoryName.'!</td>';
                endif;
                echo '</tr>';
                ?>
        </table>
    </div>
    <?php } ?>

    This is for a table of content, for each post you might need to use this function repeatedly.

    Standard Use: (with this I mean what you should put in your sidebar or any page template).

    <?php contentListTable([Your Post Category],[Number of Columns]); ?>

    Remember that in php you don't quote string values in a function example of use with a posts under Events category name.

    <?php contentListTable(Events,1); ?>

    This is querying for post in the Category 'Events' with a table of just 1 column.

    Happy designing!

  9. flamaestro
    Member
    Posted 4 years ago #

    I think I solved your problem with the following code:

    Hello! Thanks for this code man i bet it can do everything i need i for my website (show links in two columns using images that i set for each bookmark in my wordpress panel)

    i'm also pretty sure it's about using this var/thing (dunno how to call it :P) link_image, however i have no clue how to put it all together

    here is an example of how i want those links to look like :
    http://www.wprecipes.com/
    (there are those 125x125px images on the sidebar - thats what im looking for)

    oh and i almost forgot, there is a misspell in code i guess
    attibute_escape
    should be attribute_escape

  10. MCWebdesign
    Member
    Posted 4 years ago #

    Hi there,

    Just trying to figure out how to adjust this code to display pages. have changed it to the following, and I can get it to display archive dates in columns, but there are no links. have tried changing various buts in the "<td class= ..." section but to no avail, I'm only getting various php errors.

    Any suggestions?

    Many thanks

    <?php
    	/**
    	* get_pages()
    	*
    	* Retrieves the list of bookmarks
    	*
    	* Attempts to retrieve from the cache first based on MD5 hash of arguments. If
    	* that fails, then the query will be built from the arguments and executed. The
    	* results will be stored to the cache.
    	*
    	* List of default arguments are as follows:
    	* 'orderby' - Default is 'name' (string). How to order the links by. String is
    	*		based off of the bookmark scheme.
    	* 'order' - Default is 'ASC' (string). Either 'ASC' or 'DESC'. Orders in either
    	*		ascending or descending order.
    	* 'limit' - Default is -1 (integer) or show all. The amount of bookmarks to
    	*		display.
    	* 'category' - Default is empty string (string). Include the links in what
    	*		category ID(s).
    	* 'category_name' - Default is empty string (string). Get links by category
    	*		name.
    	* 'hide_invisible' - Default is 1 (integer). Whether to show (default) or hide
    	*		links marked as 'invisible'.
    	* 'show_updated' - Default is 0 (integer). Will show the time of when the
    	*		bookmark was last updated.
    	* 'include' - Default is empty string (string). Include other categories
    	*		separated by commas.
    	* 'exclude' - Default is empty string (string). Exclude other categories
    	*		separated by commas.
    	*
    	* @since 2.1.0
    	* @uses $wpdb Database Object
    	* @link http://codex.wordpress.org/Template_Tags/get_bookmarks
    	*
    	* @param string|array $args List of arguments to overwrite the defaults
    	* @return array List of bookmark row objects
    	*/
    	$pages = get_pages(); // add 'category=1' as parameter to limit the bookmarks to a category.
    	//	set counter to zero
    	$i 			= 0;
    	//	set the number of cols in our table rows
    	$cols 		= 3;
    	//	start an initial row
    	echo '<tr>';
    	//	loop through our returned bookmarks
    	foreach ($pages as $page) {
    		//	increment our counter
    		$i++;
    		//	print our link date and hyperlink to bookmark
    		//	access to the following vars:
    		/*
    		link_id,
    		link_url,
    		link_name,
    		link_image,
    		link_target,
    		link_description,
    		link_visible,
    		link_owner,
    		link_rating,
    		link_updated,
    		link_rel,
    		link_notes,
    		link_rss
    		*/
    		?>
    
        <td class="archive-date"><?php echo date('d-m-Y', strtotime($page->link_updated)) ?></td>
    		<td class="archive-title"><a href="<?php echo $page->link_url ?>" rel="page" title="Bookmark to <?php echo attribute_escape($page->link_name) ?>" target="<?php echo attribute_escape($page->link_target); ?>"><?php echo $page->link_name ?></a></td>
    
    		<?php
    		//	if our counter is dividable by 3 (= the number of cols), close our row
    		if ( ( $i % $cols ) == 0 ) {
    			echo '</tr>' . "\n";
    			echo '<tr>';
    		}
    	}
    	//	close our initial (or last) row
    	echo '</tr>';
    	?>
    </table>
  11. nicholsco
    Member
    Posted 4 years ago #

    raphievila, you posted exactly what I was looking for... but for some reason it is only showing 10 posts... any thoughts?

    <table class="table" cellpadding="2" cellspacing="2" border="0">
                <th colspan="2">
                </th>
                    <?php
    
                    query_posts('cat=1&showpost=300');// use your post category id or name here
                    /*
                     * showpost = to limit the quantity of post in the list ex. query_posts('category_name=Name&showpost=10')
                     * category = to enter category id
                     * category_name = to specify which post to be display
                     */
                    $i 	= 0;
                    $cols 	= 3;
                    echo '<tr>';
                    if(have_posts()): while (have_posts()) : the_post();
                            $i++;
                            ?>
                            <td class="archive-title" valign="top"><div class="eachLink"><a href="<?php the_permalink(); ?>" rel="bookmark" title=" <?php the_title(); ?>" ><?php the_title(); ?></a></div></td>
                            <?php
                            if ( ( $i % $cols ) == 0 ) {
                                    echo '</tr>' . "\n";
                                    echo '<tr>';
                            }
                    endwhile;
    
                    else:
                        echo '<tr><td colspan="2"></td>';
                    endif;
                    echo '</tr>';
                    ?>
            </table>
  12. nicholsco
    Member
    Posted 4 years ago #

    Figured it out. Sorry for invading the thread...

    query_posts('cat=46&orderby=title&order=asc&show=1&posts_per_page=500');

Topic Closed

This topic has been closed to new replies.

About this Topic