• Resolved saqwild

    (@saqwild)


    Hello.
    Thank you for such good plugin, since I am new to it, I have a few questions.

    1. I want to list all categories (only categories name, no file list) on a page, so that once its clicked, it shows all file lists inside.

    2. Inside the category list, I want to show file type icon and file name beside it. [audio icon]-filename.xxx

    thank you again

    https://www.ads-software.com/plugins/media-library-assistant/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author David Lingren

    (@dglingren)

    Thanks for the good words and for this question. The current MLA version can do some of what you want, when used with another plugin. As I understand it, you want to do three things:

    1. List all category names on a page.
    2. When a Category Name is clicked, display a list of all the files in that category.
    3. The list displays as one column, with an icon on the left and the file name beside it on the right

    Let’s take each item in turn.

    First, the bad news. There’s nothing in the current version of the plugin that will automatically generate a list of category names for display on the page. If you have a small or stable list of categories, you can build a page with each name and corresponding gallery added by hand. If you need a dynamic page, you can use WordPress templates and some PHP code to build one. It’s not hard but it does take some programming skills. If you want to undertake that, let me know and I can give you some guidance. Here are some earlier support topics that can give you an idea of what’s involved:

    Front-end Filtering
    Building an archive gallery with MLA
    Pagination Revisited
    template query for att. tags

    Second, opening a list of files in a given category when the name is clicked. This is easily done by combining MLA with another plugin, “Collapse-O-Matic” version 1.5.3 by “twinpictures, baden03”. You can find it with the Plugins/Install Plugins search page. For this step you wrap an [mla_gallery] shortcode within an [expand] shortcode. Her is an example from my test system:

    [expand title="California" tag="div" trigclass="level-2 third" targclass="level-2-targ"][mla_gallery attachment_tag=california size=icon mla_style=table mla_markup=table columns=1][/expand]

    The title=California is displayed on the page with a little triangle beside it. When clicked, the gallery opens below the title. The attachment_tag=california size=icon portion selects all items in the Att. Tags taxonomy with a value of california and shows each item with a file type icon for non-image files or a small thumbnail rendering for image files.

    Third, you want the icon on the left and the file name on the right. This can be done with MLA Custom Style and Markup Templates. On the Settings/Media Library Assistant Documentation tab you can find “A Table-based Style and Markup Template Example”. Make custom Style and Markup templates called “table” (referenced in the above example as mla_style=table mla_markup=table), and replace the Item markup part with this:

    <td class='gallery-icon'>
    		[+link+]
    	</td>
    	<td class='wp-caption-text gallery-caption'>
    		<strong>[+title+]</strong><br />
    		[+file+]
    	</td>

    That will get you the format you want. I’ve thrown in the item Title; you can omit that or add other values as you need.

    I hope the above example gets you started on building the page you need. I’m going to mark this topic resolved, but please post an update if you have any problems or further questions. Thanks for your interest in the plugin and for this application idea.

    Thread Starter saqwild

    (@saqwild)

    Thank you David for your support and time you have spent, please let me know where to start for point # 1.

    regarding point 2, I think it relates to point #1, when category list names are displayed and I click on any category name, it would list all images inside it.

    point 3 is thou solved.

    Regards
    SAQ

    Plugin Author David Lingren

    (@dglingren)

    Here is one approach to composing a page containing a dynamic listing of (in my case) “Att. Tag” values that open a list of their associated Media Library items when a tag name is clicked.

    As I indicated in point two of my earlier post, the “Collapse-O-Matic” plugin supplies the [expand] shortcode that implements the “opening a list” part of the solution.

    To understand the solution, you must first understand how WordPress uses Templates to generate pages on your site. Here’s the Codex article with that part of the puzzle:

    Template Hierarchyhttps://codex.www.ads-software.com/Template_Hierarchy

    Templates are mixtures of PHP code and HTML code that work together to generate the pages you see. My example uses the WordPress-supplied “Twenty Twelve” theme, adding two Template files that implement the Attachment Tag listing.

    The second piece of the solution requires a list of the taxonomy terms that are associated with one or more Media Library items. This list is supplied by one of the many WordPress functions available to you:

    Function Reference/get termshttps://codex.www.ads-software.com/Function_Reference/get_terms

    Here, then, is one solution to your requirements.

    First, create a new WordPress Page that, when requested, will display the list.

    1. Open the Pages/Add New screen.
    2. Enter “Category Listing” as the page title. WordPress will generate a Permalink for the page that includes the page slug, “category-listing”. Call it anything you like, but note the page slug for the next steps in this process.
    3. Enter some page content, such as “Click on any of the names in the list below to see the images that are tagged with that value.”
    4. Publish the page.

    Second, create one or more Templates on your theme’s root directory that will process the new page, adding the list. In my example, we add two files to the /wp-content/themes/twentytwelve directory:

    1. page-category-listing.php – which will match the search for the “category-listing” page and process requests for it. Here, category-listing is the slug for the page you’ve just created.
    2. content-category-listing.php – which is called from the preceding template to fill in the content of the page. Your theme may not require this second step.

    The page-category-listing.php template is adapted from the page.php file already supplied by the Twenty Twelve theme. All I’ve done is to change the template part that’s called to fill in the details:

    get_header(); ?>
    
    	<div id="primary" class="site-content">
    		<div id="content" role="main">
    
    			<?php while ( have_posts() ) : the_post(); ?>
    				<?php get_template_part( 'content', 'category-listing' ); ?>
    				<?php comments_template( '', true ); ?>
    			<?php endwhile; // end of the loop. ?>
    
    		</div><!-- #content -->
    	</div><!-- #primary -->
    
    <?php get_sidebar(); ?>
    <?php get_footer(); ?>

    The changed line in the above template is <?php get_template_part( 'content', 'category-listing' ); ?>.

    The content-category-listing.php file, adapted from the theme’s content-page.php file, contains all the action:

    <?php
    function the_category_list() {
    	$terms = get_terms( 'attachment_tag' );
    error_log( 'the_category_list $terms = ' . var_export( $terms, true ), 0 );
    
    	if ( empty( $terms ) ) {
    		$output = 'There are no non-empty Att. Tag values';
    	}
    	else {
    		$output = '';
    		foreach ( $terms as $term ) {
    			$output .= '<p>' . do_shortcode( sprintf( '[expand title="%1$s" tag="div" trigclass="level-2 third" targclass="level-2-targ"][mla_gallery attachment_tag=%2$s size=icon mla_style=table mla_markup=table columns=1][/expand]', $term->name, $term->slug ) . "</p>\r\n" );
    		}// foreach term
    	} // ! empty
    
    	echo $output;
    }
    ?>
    	<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
    		<header class="entry-header">
    			<?php if ( ! is_page_template( 'page-templates/front-page.php' ) ) : ?>
    			<?php the_post_thumbnail(); ?>
    			<?php endif; ?>
    			<h1 class="entry-title"><?php the_title(); ?></h1>
    		</header>
    
    		<div class="entry-content">
    			<?php the_content(); ?>
    			<?php the_category_list(); ?>
    			<?php wp_link_pages( array( 'before' => '<div class="page-links">' . __( 'Pages:', 'twentytwelve' ), 'after' => '</div>' ) ); ?>
    		</div><!-- .entry-content -->
    		<footer class="entry-meta">
    			<?php edit_post_link( __( 'Edit', 'twentytwelve' ), '<span class="edit-link">', '</span>' ); ?>
    		</footer><!-- .entry-meta -->
    	</article><!-- #post -->

    At the top of this file is a new block of PHP code that retrieves the terms in the attachment_tag taxonomy and generates one or more paragraphs using the [mla_gallery] shortcode to generate a list of items, wrapped in an [expand] shortcode so Collapse-O-Matic can display it when the term name is clicked.

    Below the new block of code just one line has been added to the template; <?php the_category_list(); ?>. This line calls the function, which echoes the HTML for the expanding list into the body of the page.

    The specifics of your solution will vary depending on the taxonomy you use, your theme and so forth, but the basic idea is the same. I hope that gets you started on a solution that suits your application. Thanks again for a question that should interest many people.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Show main category with list inside’ is closed to new replies.