Would Custom Content Shortcode work within a page ?
-
…to show all the attachments of all the custom posts of any given category ?
So far, no luck with
[loop type=”product”]
Post title: [field title]
[if attached]
This post has attachments:
[attached][field thumbnail][/attached]
[else]
This post has no attachments.
[/if]
[/loop]Thanks for this great plugin
-
Hmm, I tested this and it’s working on my end.
Could you tell me the result of your code? Do all of them show as no attachments, or only the thumbnail is not working? Also, does it work with posts and pages for you?
I believe you did.
The thing is, I’m not trying to call the page’s attachment and show their thumbnail within that same page, but rather trying to dedicated an unrelated page (an empty one) to show all attachments from a type of custom post, in that case my product.
Could your plugin do that, or will the shortcode always work within the loop it’s paste ?
The title of the page is showing, but the shortcode is not rendering anything. There is no output. Most likely because the page doesn’t have anything attached to it itself ?
ThanksYes, it should work as you described.
When you use [if attached] inside a [loop], it checks if each post in the loop has attachments. When you use it outside the loop, it checks the current post.
So, I’m curious why it’s not working for you..
Can you tell me the output if you do this?
[loop type="product"] [if attached] [attached][field id][/attached] [/if] [/loop]Are any attachment IDs displayed?
If not, maybe the attachments are saved in a custom field. You can check in the admin panel, under Dashboard -> Content. Under the post type product, there should be a list of custom field names. Do you think the attachments could be stored in any of them?
Nothing either.
Must be the custom field option. Here they are, under Dashboard/Contentrttheme_background_color
rttheme_background_image_url
rttheme_background_overlay_image_url
rttheme_enable_background_overlay
rttheme_header_background_image
rttheme_header_text
rttheme_rt_hidden
rtthemeattached_documents
rtthemecustom_sidebar_position
rtthemefree_tab_1_content
rtthemefree_tab_1_title
rtthemefree_tab_2_content
rtthemefree_tab_2_title
rtthemefree_tab_3_content
rtthemefree_tab_3_title
rtthemerelated_products[]
rtthemert_gallery_image_descs
rtthemert_gallery_image_titles
rtthemert_gallery_images
rtthemeshort_description
slide_templateIs there a way to get rtthemeattached_documents to dance along with your plugin ?
I see – so if the previous code showed nothing, it means what you’re looking for aren’t “normal” attachments. What do you get if you do this?
[loop type="product"] [if field="rtthemeattached_documents"] Post [field id] has attachments: [field rtthemeattached_documents]<br> [/if] [/loop]Probably the attachments are in an array, so we’ll have to dig further to get individual documents.
If the field displays as “Array”, then could you replace this part:
[field rtthemeattached_documents]..with..
[array rtthemeattached_documents debug="true"][/array]..which should show how the attachments are stored. Hopefully it will be a list of attachment IDs. If so, you can replace the above with..
[array rtthemeattached_documents][field thumbnail][/array]Hi Eliot
I tried the one you suggested before your message, no results (blank page).
So I just tried the second option, with no luck either.single-products php reads:
$rt_attached_documents = get_post_meta($post->ID, THEMESLUG.'attached_documents', true);Ok. We’ve made some progress (products with an “s”):
[loop type=”products”]
[if field=”rtthemeattached_documents”]
Post [field id] has attachments: [field rtthemeattached_documents]
[/if]
[/loop]shows :
http://studiocmyk.com/asfaltex2.com/?page_id=1963
So now I guess I have to inject some thumbnails, to shape the list as I need it, no ? Basically I need it to show as on the “tab” named “documentos adjuntos” on http://studiocmyk.com/asfaltex2.com/?post_type=products&p=2422
In the first link, I see that the attached documents are saved in the field, not as array but as a long string with each document title and URL separated by “|”. Hmm, with only shortcodes, this will be difficult to extract each attachment separately.
I’m curious, can you show me how
single-products.phpis getting each attachment from$rt_attached_documents? This could help figure out the content structure.When we extract each attachment title and URL, you can display them how you like – probably the easy way would be to look at the code inside the tab “documentos adjuntos”, and copy the HTML including the “pdf” image.
Yeah, the HTML way and replace elements to generate the same code was my approach. Here’s single-products.php loop bit for attachments display :
<?php if($rt_attached_documents && !$password_protected):?> <?php if(@!$tabbed_page):?><div class="line"></div><?php endif;?> <div class="pane"> <!-- document icons --> <div class="doc_icons"> <?php if(trim($rt_attached_documents)): $rt_attached_documents = trim(preg_replace("/(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+/", "\n", $rt_attached_documents)); $rt_attached_documents = explode("\n", $rt_attached_documents); endif; if(is_array($rt_attached_documents)){ echo "<ul>"; foreach($rt_attached_documents as $a_file){ if(strpos($a_file,"|")) { $a_file = explode("|", $a_file); $fileURL = trim( $a_file[1] ); $fileName = trim( $a_file[0] ); }else{ $fileURL = trim( $a_file ); $fileName = ""; } echo "<li>"; if(strpos($fileURL, ".doc")){ echo '<a href="'.$fileURL.'" title="'.__('Download Word File','rt_theme').'"><img src="'.THEMEURI.'/images/assets/icons/Word.png" alt="'.__('Download Word File','rt_theme').'" class="png" /></a>'; } elseif(strpos($fileURL, ".xls")){ echo '<a href="'.$fileURL.'" title="'.__('Download Excel File','rt_theme').'"><img src="'.THEMEURI.'/images/assets/icons/File_Excel.png" alt="'.__('Download Excel File','rt_theme').'" class="png" /></a>'; } elseif(strpos($fileURL, ".pdf")){ echo '<a href="'.$fileURL.'" title="'.__('Download PDF File','rt_theme').'"><img src="'.THEMEURI.'/images/assets/icons/File_Pdf.png" alt="'.__('Download PDF File','rt_theme').'" class="png" /></a>'; } elseif(strpos($fileURL, ".ppt")){ echo '<a href="'.$fileURL.'" title="'.__('Download PowerPoint File','rt_theme').'"><img src="'.THEMEURI.'/images/assets/icons/File_PowerPoint.png" alt="'.__('Download PowerPoint File','rt_theme').'" class="png" /></a>'; } else{ echo '<a href="'.$fileURL.'" title="'.__('Download File','rt_theme').'"><img src="'.THEMEURI.'/images/assets/icons/File.png" alt="'.__('Download File','rt_theme').'" class="png" /></a>'; } //file name if( $fileName ) echo "<strong>" .$fileName ."</strong>"; echo "</li>"; } echo "</ul>"; } ?> </div> <!-- document icons --> </div> <?php endif;?>Woo, that’s a complicated way of extracting attachments! I think it’s not possible to do this with shortcodes.
Here’s what I would do. In the page where you want to display the attachments:
[load dir="views" file="attachments.html"]This will load a template from
wp-content/views/attachments.html– just as an example. You can put the template file anywhere.At the beginning of the file:
<?php $rt_attached_documents = get_post_meta( YOUR_POST_ID, THEMESLUG.'attached_documents', true); ?>..replacing
YOUR_POST_IDwith the ID of the post you want. Then, you can copy the code above that you posted fromsingle-product.php. That should display the attachments.Ok !
And this would work with a post’s attachments. For all attachments for a custom post type such as “products” [all products], how should I proceed ?
To loop through attachments from all products, you can do something like this:
<?php $products = get_posts(array( 'post_type' => 'products', 'posts_per_page' => -1 )); foreach ($products as $product) { $rt_attached_documents = get_post_meta( $product->ID, THEMESLUG.'attached_documents', true); $password_protected = false; $tabbed_page = false; ?> <!-- Put the attachments display code from single-product.php --> <?php }Thanks !
I’ll try that ASAP
It’s working !
http://studiocmyk.com/asfaltex2.com/?page_id=1963
Now I have to put a item-limit like a post page (10+ create a nav underneath the objects). I’ll look into that now. Thanks !!
I’m quite happy with the result.
And your amazing support did it all, I’ll spread the word around me.
Thanks from Barcelona, Spain !
The topic ‘Would Custom Content Shortcode work within a page ?’ is closed to new replies.