Forum Replies Created

Viewing 9 replies - 1 through 9 (of 9 total)
  • Thread Starter mohawktopus

    (@mohawktopus)

    I finally made a solution! I feel so proud 🙂

    Put this in sidebar.php:

    <li><h2>Recent Attachments</h2>
    <ul>
    <?php
    $valid_ext = array("pdf", "doc", "rtf", "zip");
    $args = array(
    	'post_type' => 'attachment',
    	'numberposts' => -1,
    	'post_status' => null,
    	'post_parent' => null, // any parent
    	);
    $attachments = get_posts($args);
    if ($attachments) {
    	foreach ($attachments as $post) {
    $ext = getFileExt(wp_get_attachment_url($post->ID, false));
    if(in_array($ext, $valid_ext)) {
     ?>
    <li>
    <?php
    	setup_postdata($post);
    	the_attachment_link($post->ID, true);
    ?>
    </li>
    <?php
                    }
    	}
    }
    ?>

    And define getFileExt() in wp-includes/functions.php by pasting this at the bottom (before the final ?>):

    function getFileExt($file) {
         return strtolower(substr(strrchr($file,'.'),1));
    }

    This will put the latest uploads of particular extensions (defined by you in the $valid_ext array) in your sidebar. I needed this because I’m creating a website for a Boy Scout troop, and the latest permission slips and agendas need to be on the front page, while any images or other media they may upload do not.

    Hope this helps out someone else, too.

    Thread Starter mohawktopus

    (@mohawktopus)

    Maybe I’m not. I’m gonna see if wp_page_menu() is a better option.

    Thread Starter mohawktopus

    (@mohawktopus)

    I want to change wp_list_pages(), so when it iterates through each page, will also iterate through each page’s tagline meta_key and display that text alongside the page name.

    wp_list_pages() comes into the discussion because I want that function to generate what I just described. So for each page displayed, it will also display that page ID’s tagline metavalue.

    Am I making sense?

    Thread Starter mohawktopus

    (@mohawktopus)

    So in order to get the links & taglines the way I want, I should edit the wp_list_pages function to include the metadata from each post ID (since pages have post IDs)?

    Thread Starter mohawktopus

    (@mohawktopus)

    I found this snippet:

    <?php
    // list of approved file extensions
    $approved = array (
        'pdf' => "application/pdf",
        'doc' => "application/msword",
        'gif' => "image/gif",
        'jpg' => "image/jpeg",
        'jpeg' => "image/jpeg"
    };
    
    // for display purposes
    $filename = "index.html";
    
    // get the filename
    $ext = pathinfo($filename);
    
    switch (array_key_exists($ext['extension'], $approved)) {
        case true:
            break; // do nothing, break out...
        case false:
            echo $ext['extension'] ." is invalid!";
            exit;
        break;
    }
    
    ?>

    Is there anyway to integrate this with the above to solve my problem?

    Thread Starter mohawktopus

    (@mohawktopus)

    So WP treats pages exactly like posts?

    Thread Starter mohawktopus

    (@mohawktopus)

    I figured it out finally, but it was a while back now, and I don’t remember how…

    Thread Starter mohawktopus

    (@mohawktopus)

    This is a two-parter, actually. How do you remove images from a post gallery without deleting that image from the media library? And how do you add images to a post gallery without having to re-upload it?

    Thread Starter mohawktopus

    (@mohawktopus)

    I meant that I edited the template pages of Single Post and Single page. (By going to the Design > Theme Editor dealio.)

Viewing 9 replies - 1 through 9 (of 9 total)