Can Shortcodes be used in a Static WordPress Homepage? - wordpress

I have a Static page set as the home page of my wordpress website. It has a custom shortcode to show a woocommerce catalog based on my own meta query.
When I add valid products, it does not show up immediately or even after a while. However, if I publish the static page, then it shows up magically, thus leading to my question.
What are my alternatives, if I want to show my shortcode on a static home page?
I think this is my problem and nothing else, because I tried disabling all plugins and clearing the cache, but still it did not show the latest added products.

You can edit the template of your theme adding the do_shortcode() function where you want the shortcode to be displayed, for example:
<?php echo do_shortcode( '[contact-form-7 id="91" title="quote"]' ); ?>

Related

Woocommerce product archive displays nothing when called from custom Page

I have a woocommerce shop page which shows me all of the products perfectly. This page is also set as the "Shop" page in the settings. Now I want a second page called Home, which should use the same template as the shop page. (basically a second shop page without categories and some news)
home-template.php
<?php /* Template Name: Homepage */
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
wc_get_template( 'archive-product.php' );
?>
I'm using the standard archive-product template from woocommerce's github.
I can see the template being loaded, like the header, but certain woocommerce functions don't return the expected value. woocommerce_before_shop_loop doesn't return anything, even though it should display the orderby dropdown. woocommerce_product_loop() returns true, but wc_get_loop_prop('total') returns zero.
I've also tried renaming the file to front-page.php but that didn't help. The home page is set correctly in the reading settings.
Am i missing a call to a query, or is it something else? Thank you in advance for your help!
When WooCommerce creates the builtin shop page it saves the id of the created page in the wp_options database table with option_name 'woocommerce_shop_page_id'. When WordPress loads a page WooCommerce checks if the page id of the page being loaded is equal to the option_value of option_name 'woocommerce_shop_page_id' and then executes code to generate the HTML of the shop page. If you have looked at the shop page in the page editor you will notice that the content is empty. The magic is being done with hard coded routines that execute for this special id.
Since, your custom page has a different page id none of the custom code for generating the shop page will be execute. So, you need to execute this magic code for your custom page. It can be done but you need a good understanding of WooCommerce.
I suggest you reconsider your design and instead of a new page just customize the existing shop page using actions and filters.

Wordpress post content doesn't show

i developing calvincavalier.com. but post content doesn’t show. When main page post lists click,post content doesn’t show. Theme is wagazine-Magazine Premium WordPress Theme. How to solve the problem? Let me know solutions.
First of all need to check, theme have single.php or not if have then edit this page or add this function
the_content(); or get_the_content(); within wp loop.
There should be a setting in the customizer panel to display posts by category.

WP the_content display plugins attachments only

This might be a silly question since I'm new to wp but i'm trying to create a custom post feed.
Basically i have this loop
while ( have_posts() ){
the_post();
the_title();
the_post_thumbnail('content-thumb');
//and here i have installed facebook share plugin
//so if i put the_content() it would display share button
//the problem is it also display post text and everything else while i only
//need that plugin button or whatever comes with that plugin
}
The Facebook share plugin is most probably hooking the button code to the_content filter hook. The only way to avoid both 'the content' and the 'facebook button' from both displaying at once is to unhook the button from the_content using remove_filter() and then add the button manually to the page.
Read more about WordPress hooks in the Plugin API/Hooks article.
Refs:
http://codex.wordpress.org/Plugin_API/Filter_Reference/the_content
http://codex.wordpress.org/Function_Reference/remove_filter

wordpress : how to add categories and tags on pages?

I have generated pages using a custom template by creating a php file in my theme directory
something like :
<?php
*
* Template Name: Contact Page
*/
?>
<html ..... </html>
and then adding a new page on the dashboard selecting this new template
How can i now associate tags and categories to each pages ?
Is creating posts instead of pages the only solution?
Even better is to add to functions.php in your theme folder:
function myplugin_settings() {
// Add tag metabox to page
register_taxonomy_for_object_type('post_tag', 'page');
// Add category metabox to page
register_taxonomy_for_object_type('category', 'page');
}
// Add to the admin_init hook of your theme functions.php file
add_action( 'init', 'myplugin_settings' );
Tried using the accepted answer but for some reason it only shows the Post types and none of the Pages shows in the category page. E.g. /category/entertainment/
To fix that, I have to do this:
// add tag and category support to pages
function tags_categories_support_all() {
register_taxonomy_for_object_type('post_tag', 'page');
register_taxonomy_for_object_type('category', 'page');
}
// ensure all tags and categories are included in queries
function tags_categories_support_query($wp_query) {
if ($wp_query->get('tag')) $wp_query->set('post_type', 'any');
if ($wp_query->get('category_name')) $wp_query->set('post_type', 'any');
}
// tag and category hooks
add_action('init', 'tags_categories_support_all');
add_action('pre_get_posts', 'tags_categories_support_query');
Try this:
add_action( 'init', 'wpse34528_add_page_cats' );
function wpse34528_add_page_cats(){
register_taxonomy_for_object_type('post_tag', 'page');
register_taxonomy_for_object_type('category', 'page');
}
Not at all helpful to say 'download plugin' for beginners who are most likely not going to have downloaded wordpress and are therefore not able to install said plugin. Here is some short code for those like me that have been scouring the web for something that actually works on regular pages with regular accounts - ie you're not a developer.
First, make sure you have your pages in your menu set up properly.
YOU DO NOT NEED TO MAKE YOUR PAGES 'Categories' or 'Tags'!
This wouldn't give you actual pages to then go and edit, so if you are wanting to add sliders, text, an intro, or anything for that matter, you wouldn't be able to.
Then go to WP Admin > Pages
Select a page to edit and go to the text editor instead of visual editor (far right hand side tab)
Then past the following short code:
[display-posts category="hair,makeup,reviews,beauty" posts_per_page="10" include_date="true" text-decoration: none date_format="F j, Y" order="DESC" include_excerpt="true" wrapper="div" image_size="large"]
<
(The shortcode collects all the posts that you have assigned certain categories in your blog posts i.e. mine was hair and beauty. So obviously change yours to ones that are appropriate. It then allocates how many posts (mine was 10), the date (in descending order,) with a large image and an excerpt of the post)
this plugin sorted me out :
http://wordpress.org/extend/plugins/add-tags-and-category-to-page/
with the standard instructions :
Upload the plugin files to the /wp-content/plugins/ directory
Activate the plugin through the 'Plugins' menu in WordPress
Use the setting page of the plugin from Settings > Add Tags And Category For Page.

Wordpress themeing

I am relatively new to wordpress, I am creating a custom theme, and so far it is going ok.
I currently have index.php, header.php, footer.php and sidebar.php.
I have now hit a bit that has been puzzling me for a couple of days.
My home page has a slightly different layout to other pages, how do I theme for that change?
My website is essentially made up, of 'static' pages and 2 posts pages, what can I do so that the homepage looks different to the other pages?
Create a page template called home.php. WordPress will use it automatically for the start page.
Example:
<?php
/**
* Template Name: Home
*/
get_header();
// Do your regular page.php stuff
get_footer();
See also the codex page an Conditional Tags.
Go into your dashboard, settings>reading, check what the setting is for your home page display. You may need to change it from the default "list of latest posts" to a static page of your choosing.
You need a front-page.php
Please see the template hierarchy
You need to use the built-in functions from wordpress such as is_home() and is_front_page().
Conditional Tags
If you have a front-page.php that will take precedence over home.php or page.php. Whether or not home.php or page.php are defaulted to (assuming you have both) can be controlled in Settings → Reading. If you do not have a front-page.php, home.php, or page.php, then index.php would be defaulted to.
One difference between home.php and front-page.php is that home.php defaults to being a blog index page. Though both home and front-page may be used to display static or blog index pages.
More info may be found Wordpress' Template Heirarchy page.

Resources