• Resolved alx359

    (@alx359)


    I’ve a nice cloud widget in my theme (Flatsome) that takes taxonomy. For MLA’s, the permalinks become /attachment_category/<cat-name> which leads to 404. What I’d need to do to get a list of images similar to these in archive pages (i.e. <tag-base>/<tag-slug>)?

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

    (@dglingren)

    Thanks for the question. The “404” problem has come up before, most recently in this topic:

    Problem with permalinks

    That topic and the earlier topics it links to should give you several solutions for your application. You can put the [mla_tag_cloud] shortcode in any text widget that allows shortcodes, such as the “MLA Text” widget MLA provides for just this purpose.

    You could, of course, modify the PHP archive page templates to look for the attachment_category taxonomy and display the gallery you want.

    I am marking this topic resolved, but please update it if you have problems or further questions regarding the solutions provided in the earlier topics.

    Thread Starter alx359

    (@alx359)

    Ah, I see. Sorry for the newbie question, still so much to learn about WP. Wasn’t sure really what the issue is to investigate further.

    Found this piece of code that seems to enable support of attachments in archive template page.

    
    /*********************************************************************/
    /**
     * When inside a custom taxonomy archive, include attachments AS WELL AS pages and posts
     * https://wordpress.stackexchange.com/questions/187629/creating-attachments-archive-in-tags-and-categories
     */
    add_action('parse_query', 'ew_attachments_in_archives');
    function ew_attachments_in_archives() {
        global $wp_query;
        // Note that is_tax() returns false on category archives and tag archives
        // Use is_category() and is_tag() respectively when checking for category and tag archives
        if (is_tax('attachment_category') OR is_tag() OR is_category()) {
            $wp_query->query_vars['post_type'] =  array( 'attachment', 'page', 'post' );
            $wp_query->query_vars['post_status'] =  array( null );
            return $wp_query;
        }
    }
    

    Will require tuning the archive template anyway, as the end-result looks quite raw.

    Thanks!

    Plugin Author David Lingren

    (@dglingren)

    Thanks for digging through the earlier topics. As you can see, this issue has troubled WordPress/MLA users for years. Basically, “attachments” are a very old precursor to the custom post types idea and there is a lot of legacy code scattered throughout WordPress core that treats them differently.

    The solution you found is a good start, but be careful of the post_status check:

    $wp_query->query_vars['post_status'] = array( null );

    This will include draft and trashed pages, posts and attachments in the query results. You might consider:

    $wp_query->query_vars['post_status'] = array( 'publish', 'inherit' );

    Let me know if you have any other problems or questions regarding archive page handling. Good luck with your template adaptations.

    Thread Starter alx359

    (@alx359)

    Thank you! Read a little bit about post_status before and fixed that code accordingly, as per your suggestion.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘/attachment_category/ archive pages’ is closed to new replies.