• <iframe src="https://view.officeapps.live.com/op/embed.aspx?src=<?php echo $attachment_url ?>" width="100%" height="500px" frameborder="0"></iframe>

    I have placed this loop in post.php. But is not working.

    <?php
    $args = array(
        'post_type' => 'attachment', // Retrieve attachments
        'post_mime_type' => 'application/vnd.ms-powerpoint', // Filter by MIME type for PPT files
        'posts_per_page' => -1, // Retrieve all attachments
    );
    
    $attachments = new WP_Query($args);
    
    if ($attachments->have_posts()) :
        while ($attachments->have_posts()) : $attachments->the_post();
            $attachment_id = get_the_ID();
            $attachment_title = get_the_title();
            $attachment_url = wp_get_attachment_url($attachment_id);
    
    
        endwhile;
    endif;
    
    wp_reset_postdata(); // Restore the original post data
    ?>

    Someone please help us in correcting this code.

Viewing 7 replies - 1 through 7 (of 7 total)
  • Moderator threadi

    (@threadi)

    What exactly do you want to output? Inside the loop there is no output at all.

    Thread Starter Kiran

    (@kiranbhai)

    The output requires the URL of the PPT.

    check Our Test Page : https://pdfseva.org/2023/10/22/cold-chain-system/

    Moderator threadi

    (@threadi)

    I still don’t quite see the connection to the loop, but presumably you have to place after

    $attachment_url = wp_get_attachment_url($attachment_id);

    the output of the iframe. So:

    $attachment_url = wp_get_attachment_url($attachment_id);
    ?><iframe src="https://view.officeapps.live.com/op/embed.aspx?src=<?php echo $attachment_url; ?>" width="100%" height="500" frameborder="0"></iframe><?php
    • This reply was modified 2 years, 7 months ago by threadi.
    Thread Starter Kiran

    (@kiranbhai)

    I tried all but ppt url is not loading in the frame.

    Moderator threadi

    (@threadi)

    What does the source code you use look like? The one above is not complete because the output inside the loop is missing.

    Thread Starter Kiran

    (@kiranbhai)

    I am not a developer. But with your help I will try to do something myself.
    Here is the overall code of post.php.
    I want to show .ppt in all posts.

    I want to show .ppt file from ifrem. But the URL of the ppt file attached in the post is not available.

    Hope you will solve it.

    <?php
    if ( ! defined( 'ABSPATH' ) ) exit;
    function my_simple_crypt( $string, $action = 'e' ) {
        $secret_key = 'drivekey';
        $secret_iv = 'google';
        $output = false;
        $encrypt_method = "AES-256-CBC";
        $key = hash( 'sha256', $secret_key );
        $iv = substr( hash( 'sha256', $secret_iv ), 0, 16 );
        if( $action == 'e' ) {
            $output = base64_encode( openssl_encrypt( $string, $encrypt_method, $key, 0, $iv ) );
        }else if( $action == 'd' ){
            $output = openssl_decrypt( base64_decode( $string ), $encrypt_method, $key, 0, $iv );
        }
        return $output;
    }
    
    
    function remove_wp_block_file_div($content) {
        $content = preg_replace('/<div class="wp-block-file">.*?<\/div>/s', '', $content);
        return $content;
    }
    add_filter('the_content', 'remove_wp_block_file_div');
    
    get_header();
    ?>
    
    <?php
    $args = array(
        'post_type' => 'attachment', // Retrieve attachments
        'post_mime_type' => 'application/vnd.ms-powerpoint', // Filter by MIME type for PPT files
        'posts_per_page' => -1, // Retrieve all attachments
    );
    
    $attachments = new WP_Query($args);
    $attachment_url = wp_get_attachment_url($attachment_id);
    
    if ($attachments->have_posts()) :
        while ($attachments->have_posts()) : $attachments->the_post();
            $attachment_id = get_the_ID();
            $attachment_title = get_the_title();
            $attachment_url = wp_get_attachment_url($attachment_id);
    
    
    
        endwhile;
    endif;
    
    wp_reset_postdata(); // Restore the original post data
    ?>`
    
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
        <div class="content ringtone" data-id="<?php echo get_the_ID(); ?>" data-value="<?php echo $URLs_Link_MP3 ; ?>">
            <div class="row">
                <div class="col-md-12">
                    <h1><?php the_title(); ?> PPT</h1>
                </div>
            </div>
            <div class="row">
          
    		<?php     $attachment_url = wp_get_attachment_url($attachment_id); ?>
    			<iframe src="https://view.officeapps.live.com/op/embed.aspx?src=<?php echo $attachment_url; ?>" width="100%" height="500" frameborder="0"></iframe>
    			
            </div>
    <?php get_footer(); 
    Moderator threadi

    (@threadi)

    Simply remove this line just above the iframe:

    <?php $attachment_url = wp_get_attachment_url($attachment_id); ?>

    I still hope that you have created a child theme for this. Because editing a post.php from an original theme can’t work in the long run because it will be overwritten with the next update.

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

The topic ‘Get wordpress Attachment PPT url in Post’ is closed to new replies.