Wordpress - display media on page - php

A client wants a full page full of PDFs, and an option to be able to assign a PDF to a page automatically.
For example, conveyancing.pdf would appear on downloads.php (along with several others), but also have an option to tick 'yes I want this PDF to also feature on the conveyancing page'. Is this possible, and if so how would you approach it?
If I made a custom post type for the pdfs, is there an option to list all the pages it can appear on, like you'd tick categories but this would be 'pages'?

"a full page full of PDFs"?
Do you mean a page with links to multiple PDFs on the server?
Chrome / firefox and maybe IE have a built in PDF viewer and there is an option to save, download or print.
How to Upload & Link to a PDF file in WordPress

if i get you right, you want to upload pdf files from the admin panel and attach them to pages.
since you didn't specify what you already done, i will start from the beginning.
I've done this before on some project, i needed to let a client upload documents to post type page and custom post types. you can create a new custom fields on your code if you like too but i think if you'r out of time, you can installed for example the WCK plugin because besides of options like create new custom post types or taxonomy easily, it also let you create custom fields with repeater (which is not freely in every other good custom field creator plugin).
create with the plugin a new meta box and then the document field (you will need to do it for each post type). after that, you will see the new custom field on the post type you've been chosen, upload a document for the test and on you theme code call to get the field, check this link to get the detailed instructions.
after it will work for you you will want to add an option to attach some documents to other page by some checkbox right? you can create another custom field (checkbox) under the same meta box so it will Appear with every document field and then get the value on the code theme to check if it checked or not, that way you can control what documents will appear in the template you want to get by the checked checkbox of document ("show this document in other templates").
the problem with this should be how to get the id's of the pages who have the selected checkbox to the current page, i didn't try it but maybe you call all the pages with WP_Query and in the array use the specific post type you like and the custom field parameter to get only the pages with the check box, after that you can run a foreach on the array and use a condition to check for the value of each page checkbox, if it true get the custom field (document) and in the place to insert the post id use the id of the post in the foreach so it need to bring you the specific document. i would love to hear if it worked for you, good luck!

Related

Wordpress - Hide specific fields to certain user role on back end

Is there a way in which I can disable/hide specific fields from the "page form" in the back-end? I have currently test two plugins but none of them meet the requirement that I have, like for example this plugin "User Role Editor by Members – Best User, Role and Capability Management Plugin for WordPress":
I'm sorry that the options are in spanish but the capabilities options are for example: "edit pages", "edit other people's pages", "publish pages", "delete pages"... What I want is to hide certain sections to the "editor" user role from the page form:
Is this even possible?, and if not, what alternatives do I have?, the thing is that I'm afraid that whoever is in charge of editing will end up messing up with the pages...
Use Adminimize plugin It will resolve problem easily.
This plugin changes the administration back-end and gives you the power to assign rights on certain parts.
In most cases, the plugin "Adminimize" that Tech Sourav mentioned will work just fine, but since this page I'm working with is using some annoying custom content editor and other theme tools, the workaround that I ended up doing was:
Create a custom post type with the "Custom Post Type UI" plugin.
In this case I will only and always have 3 pages that have this "modifiable" price field, so once the custom post type is added I added 3 entries to this custom post type (here I will show you just one).
I'm also using the "advanced custom fields pro" plugin in order to create this price field into my entries.
When the custom field has been created there's this option inside the same previous form that allows me to show that specific field just created into specific post types entries, so I made up the rules in order to show this field in the created custom post type entries:
In this example I'm just showing you the rule for one entry, in order to make it appear on the other 2 entries, I would just click in the "agregar grupo de reglas" and select one by one.
Once this custom field and rules are configured correctly, I should see now the custom field "precio" inside my specified entries form:
After saving the entry with the updated custom field value, I will now check the post id and save it for later (we're going to need it):
According to the documentation of Advanced Custom Fields plugin I can show the saved value of certain input within certain post with the shortcode: [acf field="{$field_name}" post_id="{$post_id}"], in this case I will change the values to: [acf field="precio" post_id="1372"] and paste the code into the section of the page that I will show this:
The builder that this page is using has an element called "code block" but you can use it in the equivalent element that allows you to paste code from your theme.
After saving the changes, now the only thing that I have left is to restrict the ability to edit pages to a user with the "editor" role, for this I will use the plugin that I mentioned before in my question called "User Role Editor by Members – Best User, Role and Capability Management Plugin for WordPress":
As you can see, I will not let editor users to mess up with the pages post types, so with this, they will only be able to edit the custom post type that I created, which even if they write something inside the content of that custom post type entry, the website won't be affected at all. This may be a little bit hacky but it works...

Custom Fields, linking to a separate download page?

Afternoon all,
I have some Advanced Custom Fields set up, which allow the user to download files which are appropriate to a certain product.
For example, if the product was 'Product 1', the files would be 'Product 1 size' etc. This works perfectly, using the following:
Brochure
This adds the file which is added on each individual page, as in ACF I have set the location rules as shown in the screenshot
Now, the issue is as follows.
I need to create a whole new page, called downloads.
This page, will list all the products in my page, and then need to have the downloads available (the Custom Field File). Now, because this field is set up to show on the product pages, I am completely unsure as to how to show the downloads on a seperate page, because using
Brochure
is technically not telling me which product this is for.
I hope this makes sense.
EDIT:
I completely forgot to mention, this information will need to be inside a table, and I am currently using TablePress, a plugin.
So it would go like:
Prouduct --- Category --- Download
Thank you all!
After you have edited your question, my first answer does not make sense anymore. So here is what I suggest now:
A. This is the solution to what you actually asked
Install the Reveal IDs Plugin so you can see in the admin panel what post-IDs your products have
Look up the ID for a specific product
In your TablePress table-cell you paste the ACF-shortcode:
Download brochure
post_id="12": this is the ID of your product-post which you can look up with Reveal IDs.
I already tested this right now, so I do know it's working.
B. Another solution that is more a question
Your ACF field 'brochure' obviously contains a URL to a file which might be available in your WP media library too?!
When this is the case you don't need the ACF field for your table. You can just:
click "Advanced Editor" (when working with the table)click into a table cell
click into a table cell
click "Add files" and link to your file directly this way
Maybe that is an option too.
I think I understand what you're trying to do. This should point you in the right direction: http://www.advancedcustomfields.com/resources/query-posts-custom-fields/

Drupal 7 set content type url to custom value

I am using Drupal 7 and have created a custom content type and a view that displays those content types. What I want to do is override the url to the node in the teaser view. My specific use case is this:
I have a support view that displays support content types. When I view that page, I see the teasers for the support content types I have created: Safety, FAQ, Ticketing. Safety and FAQ link to their nodes as expected. What I am trying to accomplish, is have the teaser and image for ticketing there, but have it link to my external ticketing portal. Essentially, I would like to have a checkbox when creating content of this type that allows me to link to external url. I do have the link module installed, but there is no way for me to apply that field to the url of the title.
I have spent a while googling around trying to find the answer, but without much success. If there is nothing available to do this already, I wouldn't mind building a module and submitting it to the community. Just want to make sure I'm not missing anything.
Thanks in advance.
UPDATE
Here are the steps I took using the answer given below:
Install the link module: http://drupal.org/project/link
Create a content type, add a field for link
Add new content of that type and add the url you want to link to in
the link field
Create a view and filter by that content type
Under format, i'm using format: "grid" with show: "fields"
Add a field for the Content: link field you created FIRST* in the list.
Set to Exclude from display and Formatter: URL, as plain text
Add a title field and deselect "Link this field to the original
piece of content" click on "rewrite results" and select "rewrite the
output of this field". Enter [title] in the text field where
[field_link_to] is the name of the link field as described in the
"replacement patterns" dropdown below it.
If you do not have the link field in your list of fields FIRST, the token will not be available to the fields below it.
In your Content Type > Manage Fields > Link (edit) > Wrapper markup, make sure "no markup" is selected
You can alter the display of the view using the rewrite options. Make sure your display type is set to 'fields'. Then include the fields you want to display; title, teaser, image.
In the field configuration of the title field, choose 'rewrite results'. there you can enter the following [title] That should overrule the title.
Also make sure to uncheck 'link the field to it's node'.
UPDATE: You might have to create a second view for this... To prevent editing the other two elements.
Step 7 is different in Drupal 7.22
Title "rewrite results" > select "Output this field as a link" > text field under Link path is only "[field_link_to]" (without <a href=...>... etc.)

Add link in custom post-type - Wordpress

I have a custom posttype in Wordpress 3. I would like to every post of this type to have the option to add a link. Basicly this will be a link that refers to another page/post whatever on the site.
There should be only one link for each post of this type. And i would then need to extract this link in my template files. Basicly im creating a post-type "Slideshow" And each slide-item should be connected to one page or post. So when you click a slide you will be taken to the defined page.
i know i can do this by using a custom-field. But then i would need to enter the whole url every time. I would like a feature similar to that of the wordpress WYSIWYG editor link button. So i can add a link to "existing content" easy.
Anyone know of any tutorials or similar on how to do this?
Thanks!
bit surprised no one has mentioned this plugin "Related Links"
Wordpress plugin Related Links
It adds a metabox to your edit forms. You can link to related content or put in external URL.
It allows links to posts, pages, media AND Custom post type - check its type on the Settings page of the plugin after install. It uses a similar search/browse facility to the normal WYSIWYG link insert feature!
What post-types does it apply to? If you are using on a custom post type, then check all the post-types you want to be able to link to - it still shows the box on this post-type itself.
It can accept multiple links, but one will work of course. Then you use the get_related_link() function in your template to output this and format as you like.
If you just want to make a link between the two posts, rather than insert it in your post content, I'd recommend the Posts 2 Posts plugin. It'll allow you to create links between posts without having to remember the full URL.
Edit:
I haven't used it, but I suspect the cardinality argument should help you limit the number of links - see the wiki.
And you can certainly access the connections in your templates - I have. Once you've registered your connection type, you can just call get_connected:
$venue_details = p2p_type( 'exhibition_to_venues' )->get_connected( $post->ID, array(
'posts_per_page' => -1,
'connected_orderby' => 'order',
'connected_order' => 'ASC' )
);
It seems to me that the best method to accomplish this would be to add a custom meta box to all posts and post types (see here:http://themefoundation.com/wordpress-meta-boxes-guide/). Within this meta box, you can simply query all posts that you would like to include in a dropdown. You can then select the post from that dropdown, obtain the ID of the post selected (use as data attribute in the option field), and then return the permalink for that ID. This will then allow you to simply select the post, rather than having to know the actual URL each time.
Another method would be to attach a piece of unique data to x post (most likely utilizing custom fields), and then also attach it to y post. In this way, you could use a function to automatically append the link to the displayed post. You would do this by querying the posts in the database, match the custom data, and if matched, display the link to that post. This would allow the entire thing to be automated, and you wouldn't even have to select anything. In my opinion, the title field should actually be sufficient for this, since both posts are different post types (you should be able to title them the same), and would likely make your query a bit easier/shorter since you would simply need to find the post that matches the title, and then link to the permalink.
I can elaborate on all of the above further, with code samples as well, but in my opinion, the question is slightly too vague to write a custom script example for this scenario.
I would hope the above would be sufficient to get you going.

How to place multiple content types on a Drupal page?

I've created a new content type called Homepage, which has a number of fields. The fields are node references to the Single Image Promo content type. Single Promo Box has fields for title, text and image. The idea is that I can create multiple copies of a Single Promo Box, each with different field values. I then want to place a few of them on the homepage.
So I can place a specific Single Image Promo on the homepage fine now. But what template file do I need to create to style the way Single Image Promo is shown when it's a node reference on the homepage?
Thanks,
Maria
It sounds like you are over complicating things.
If you want to create some different boxes on your homepage, using node reference is not the right way to go about this. There are some few different ways to do what you want, the easiest i probably to create a block view of the node you want to display. When you turn a node into a block, you get the ability to place it in any of your theme's defined regions.
You could also just create a view and from there get the different Single Image Promo you want without using node reference at all. Views has a lot of different filters, which will enable to you create a view that always displays the right nodes. This solution wont work well, if you want to place the nodes in different regions though.
To answer your question, when nodes are being displayed, they will by default be rendered with the node.tpl.php template file. To make specific templates for each of your node types, you can create a new template named node-nodetype.tpl.php, where nodetype is what you called the node type when you created it.
node-nodetype.tpl.php can work to a certain degree, but in that file you are styling the entire page, with the content type's fields delivered wholesale to the tpl via a single $content variable. Maybe it is enough for you, but if you need finer grained control:
You can edit and style the individual content type's fields with the Content Template (contemplate) module. It provides access to all of a content type's fields within the $content variable (which is delivered wholesale to the node-nodetype.tpl.php. The contemplate is php, so you can add logic and conditional formatting for the node-reference fields (usually clearly labeled in the contemplate).
And don't overlook the simple solution of the content type's 'display fields' tab (next to manage fields tab), where you can control some field outputs right out of the gate.

Categories