Wordpress, alternative single post template - wordpress

For a project of mine I need to define an alternative template for single posts.
To be more specific I need each post to be displayed as usual when the website is browsed but I need to create different single pages reachable from different URL to create a sort of a mini-website for each post.
(I'm actually using the WooCommerce plugin and what I need to do is to create a mini-website for each product. This needs to be something "outside" from the main website, with a complete different graphic template and is going to be reachable through a QR-code).
Hope it makes a bit of sense.
Thanks for your advices and/or suggestions.
Angelo

I think the easiest way to do that is by registering a custom post type for the special posts that get this special "single.php" template. Then, you can simply write a new single template titled post-[custom post_type].php. Any post you register of this type will use that template.
OR...
If you don't actually need them to be posts, it's even easier if you publish them as pages. By default, pages let you assign a specific page template in the edit screen. So you could make any number of custom templates. Just make sure you add the special header:
/* Template Name: Custom Page */
...so WP knows it's a page template.

Related

How to manage Multiple single page through single.php?

There is Post that have certain data could be viewed in blog nav-menu that is using index.php and for the single post it retrieves data from single.php. I also have another custom post type that is client could be viewed from Our- client nav menu and it is using client template. Now the problem is i also want a custom single page for single client so i am using single-client.php but when i click to any client it leads to single.php not single-client. php.
You can use single.php and both post types will use it, as long as you remove the other two files from your theme.
Then you could fetch different template parts depending on the post type being queried.
However you do it, you're going to need separate files with stuff for the two different post types, unless the to are going to have the exact same design.
EDIT
I think I may have misunderstood.
Is your issue that the single posts are not displaying, but you want to keep using the two separate single templates?
In that case, make sure the post types are called blog and client.
To check, go to each post type's section in the admin panel. On each of these pages check the post_type URL parameter in your address bar.

Separating Content from Design in Wordpress

I'm not a super-experienced Wordpress guy, but I generally know what I'm doing, and have been programming for years.
I'm in the middle of building a fairly simple Wordpress site, but lots of posts will be added in the future by the client.
It suddenly dawned on me that all my posts are static, so if changes in design are needed they will need to be applied manually across many pages.
I've searched Google but to no avail. What I need is a plugin or method that allows me to have templates for my posts, into which the unique content for each page are added. Then, if design changes are needed, I simply edit the template and the design will change instantly across all the pages using this template.
I've found plugins which seem to offer post templates, but all they seem to do is create a new post with a pre-made design, but do not make it possible to make changes to that design which are reflected across all the posts that use that template. Maybe I'm missing something simple here, as I can't be the only WP author who wants to achieve this?
I'm not talking about dynamic content. ie I have no need to pull constantly updated data like weather or prices from an API. The content is hand-written for each page, but I would like to separate it from the design, so if design changes are needed they can be made only once from some kind of post template manager, and not individually on each page.
Actually, I'm already using the simple post-snippets plugin, and I realise that I could use this or something similar to achieve my aim, but I don't think this would be very user-friendly for non-technical authors. Instead, it would be ideal if I had a set of custom fields under each post which the authors filled in, and the content was then taken from there and inserted in the page's template.
In principle you should be able to change the design just using CSS selectors. Of course that may have its limitations but there is never a design that fits it all.
For bigger changes you will need to change the WordPress template.
Ok, after some research and poking around, this is what I've come up with.
Install the 'Advanced Custom Fields' and 'Custom Post Templates' plugins , although neither are strictly necessary.
Create a group of custom fields which defines the unique data (URL, media selector etc) for each post.
Most importantly, create a new custom post template following the instructions for the 'Custom Post Templates' plugin. In this template remove the line that outputs the post content (the_content()), and replace it with code that outputs all the shortcodes or whatever for this page type, with placeholders string replaced with the values of the custom variables for that post. Then (in my case) I do something like do_shortcode($page_template) to correctly output the correct content for that page.
I create a new post, leaving the content field completely empty, and filling in the custom field's values as required. Also, you must choose the post template, so it matches the new custom template you create.
$v=get_post_custom_values("image_url")[0];//gets the id of the post which contains the image
$image_url = wp_get_attachment_image_src($v, 'medium')[0]; //get the image (URL?) from the reference
$page_template='[one_third last="no" spacing="yes" background_color="" background_image="" background_repeat="no-repeat" background_position="left top" border_size="2px" border_color="#eaeaea" border_style="solid" padding="20px" class="" id=""][imageframe lightbox="no" style_type="none" bordercolor="" bordersize="0px" borderradius="0" stylecolor="" align="none" link="" linktarget="_self" animation_type="0" animation_direction="down" animation_speed="0.1" class="" id=""] <img src="#image_url#" alt="" />[/imageframe][fusion_text]Email Me | Website[/fusion_text][/one_third][two_third last="yes" spacing="yes" background_color="" background_image="" background_repeat="no-repeat" background_position="left top" border_size="0px" border_color="" border_style="" padding="" class="" id=""][fusion_text]#main_text_html#[/fusion_text][/two_third]';
$page_template=str_replace ( "#image_url#" , $image_url , $page_template );
echo do_shortcode($page_template);
The code above contains the page template hard-coded into the $page_template variable, but it could also be loaded by referencing the id of the post which is acting as the template.
This code currently only inserts the correct image URL. Once it's finished it will also insert the personal email link, website link, and main text.

Set the permalink to any domain in Wordpress

Is this possible to achieve without too much effort or a plugin? It's simply to instantly redirect to a site I've made in my portfolio if the post doesn't have any content.
Note that I don't want a script in the actual post to redirect since I only use Wordpress as the backend and fetch all the data to be used by a JavaScript backbone app.
EDIT : Added some extra info in a comment
Short Answer: No. You cannot set your Post Permalink to an external asset without directly editing the database.
Long Answer: First off, you need to understand the purpose of the Permalink. It isn't just an arbitrary link to somewhere. It's reserved specifically for storing where that specific post lives within the context of your Wordpress installation.
Your post doesn't live on example.com. It has its own ID, and Wordpress has a specific spot set aside for it where it can be seen on YOUR domain. Leave it as such.
Instead, what you should be doing is employing the tools Wordpress gives you to achieve what you want. A Plugin doesn't exist for what you want because - quite frankly - it's a fairly trivial task when approached CORRECTLY and doesn't warrant the use of an external resource.
So what's the correct way?
Use a Custom Field. Name your Custom Field something like 'externalHref' and fill that in with your link to the website you want to point to in case there's no post content.
Then in whatever templates you're using to generate your posts, just check either for the existence of your Custom Field called 'externalHref' or check for the non-existence of Post Content. In either case, instead of generating a link using The Permalink you can simply build a link that points to wherever you need.

Drupal 7- How to make a custom module for only front page?

so..I created page--front.tpl.php in my theme directory and it works fine.
now, how do I make a variable that can be used in the page--front.tpl.php?
I can write my php codes inside page--front.tpl.php, but I think there is a better way.
added:
on the front page, I am going to query video and news nodes ONLY. That is why I want to make a new module for only front page.
any suggestions?
I'm not sure what you are trying to achieve here, but OK. You have two options: one is what you're doing now. Write your custom PHP in page--front.tpl.php and you'll be fine. The other is ditching the file and working only with page.tpl.php.
The variable $is_front tells you whether you're on the front page. You can write custom PHP in a conditional block: if ($is_front) { ... }.
Also, you can create a custom block (a view, perhaps, depending on your needs) and set its display restrictions to "only on the listed pages" - and list there. You'll have a custom view loaded only on the front page.
All you need to do have a custom front page is configure your front page in the site information settins (admin/settings/site-information in D6).
Creating a module to display that content is then a completely different thing.
What I would really suggest is looking at Views if you don't know it already. That allows you to build lists of things (nodes, users, ...) and expose them as pages, blocks, rss feeds and much more. You can create a list of nodes with types video and news, expose that as a page and then just point your front page to the path of your view.
you might try using the views module to create your list of videos and nodes. You can set a views page to be your homepage in the site settings.

WordPress- have a specific type of "page/post" as "testimony". Possible? If so, how?

I'm implementing our school's website using WordPress as CMS. So far, it works well and I'm 80% done. Our website is basically 11 WordPress pages and a blog.
Now, there is one feature i'm not sure how to resolve. We want to have "testimonies" of past students to be displayed across WordPress pages, in a specific area of the page. They will either be videos or written text with an image.
They will be embedded on regular WordPress pages either a specific video for a specific page, or just random testimony video for a given page.
Is it possible to do that with WordPress? If so, how?
Thanks for any hints.
Alex
There are quite a few Wordpress plugins which handle testimonials gracefully:
http://wordpress.org/extend/plugins/search.php?q=testimony
You should be able to do this with categories. Create a testimony category and and then create a new template called 'testimony-page.php'. In that template, put a separate loop that pulls a random testimony from the database. Voila, page in a page.
If you feel like building this yourself, it can be handled with custom post types. Here is a great guide that will give you a lot of useful information: http://www.smashingmagazine.com/2012/11/complete-guide-custom-post-types/
I like to use this plugin:
http://wordpress.org/extend/plugins/more-types/
To manage my custom post types.
To query posts from a new post type, use something like:
query_posts({
'post_type' => 'testimonials'
});
So, if you wanted to add testimonials to your site, you'd query them like above with whatever parameters you need, and do a simple loop to output the posts.

Resources