Embed Woocommerce Product details page info into another page - php

I simply want to embed my woocommerce product details info into my "Classes" page. I can best explain what I want with images, so am including 3.
The Classes page as it is now - http://prnt.sc/c9requ
The product details page - http://prnt.sc/c9rfa7
(the rest is in my comment below)

You can fetch product category from woocommerce by using this code:
$args = array( 'post_type' => 'product', 'category' => 34 );
$products = get_posts( $args );
Once you have the products, you can loop through and display them using your existing HTML code.

Related

Custom Post Type Inside Regular Post Type

I am working on a website in Wordpress where I need to use custom posts (which I already created with the help of a plugin).
The problem is that the theme that I use allows me to display the post on the page organized according to categories, but when I create a custom post and put it into a category it is not displayed on the web (as if I had never created the post) but if I create the same post from the normal page of Wordpress entries (a standard Wordpress post type) and I put it in the same category this is shown on the page. Also, when I enter the custom post page the entry I created appears but when I enter the normal entries page it does not appear.
I went to a portal where they said how to add the custom post to the Wordpress categories by writing some lines of code in the functions.php file but this did not work, now I see the custom post within the category page but I still do not see them inside of the Wordpress entries page and also still not shown on the web.
You need to create a custom query. This page has good explanations and examples: https://codex.wordpress.org/Class_Reference/WP_Query
The most important thing in your case is to include this in your arguments array, which selects posts and your CPT:
'post_type' => array('post', 'your-custom-posttype'),
and also this which filters by category:
'category_name' => 'your_category_name'
So a typical simple custom query would look like this:
$args = array(
'post_type' => array('post', 'your-custom-posttype'),
'category_name' => 'your_category_name',
'post_status' => 'publish',
'posts_per_page' => 12
);
$query1 = new WP_Query( $args );
if ( $query1->have_posts() ) {
while ( $query1->have_posts() ) {
$query1->the_post();
echo '<li>' . get_the_title() . '</li>';
// Other stuff echoing content etc. to be added here.....
}
wp_reset_postdata();
}

Creating a dynamic URL in WordPress

I am making an e-commerce site with WordPress, Woocommerce, and BuddyPress. We allow members to upload images of their products. The product category name is the same as the member's username. So if exampleUser1 uploads a product image, that product is given the category 'exampleUser1'.
This is a temporary method that my team and I are using so members can see all of their products on one page (product-category page).
I want to create a dynamic URL that I can display via a button that links to the product-category page of the logged in user. I have researched how to do this using functions.php and passing variables to the URL but am having no luck getting anything to work.
Thank you for your help!
You should change the category to a constant value for all users like productImage or something. Then no need for a dynamic URL, the same URL will work for all users. Just create a page template and use WP_Query in the loop like this:
$author = get_current_user_id();
$args = array(
'author' => $author,
'post_status' => 'any',
'category_name' => 'productImage',
'post_type' => 'attachment'
);
$query = new WP_Query( $args );

Create custom menu in php based on pagenames

im trying to make a custom hardcoded menu in a wordpress page-template. The site has 3 pages (1, 2, 3) and at page 1 i wish to loop trough all pages that has page1 as pagetemplate and 2 for 2 etc.
How can i loop trough and get the names of all pages so i can put them in a menu?
if for example you visit page 1 and the pages that has page1 as template (parent) are "visit us" and "read more" the menu would look like this:
-visit us
-read more
but if i go to page 2 the menu might look like this:
-funpark
-foobar
Now if I add a new page with "1" as parent and name the page "about" the new menu will now show
-visit us
-read more
-about
Cheers,
Emil
You can query for pages and their template value. The codex says:
The filename of a Page's assigned custom template is stored as the value of a Custom Field named '_wp_page_template' (in the wp_postmeta database table). (Custom fields starting with an underscore do not display in the Edit screen's Custom Fields module.)
This means you can build a page query like this:
$args = array(
'post_type' => 'page',
'meta_query' => array(
array(
'key' => '_wp_page_template',
'value' => '[Your template goes here]'
)
)
);
All you have to do is loop through the pages, get the permalink and build your menu.

advanced custom fields for page templates

Wordpress ACF -> querying page templates instead of posts.
So basically I have setup advanced custom fields and I want to structure my website so that when I create a page with a page template of, say, 'topic-page' I would like ACF to add the custom fields to all pages that have a page template of 'topic-page'.
In the past I would use the $args array to query the post_type = 'slug'; however, how do I query a page template?
Existing code for querying post types:
$args = array( 'post_type' = 'the name of the post type' ); $args = new WP_Query( $args );
So I would like to modify it to be able to reference fields from a page template.
Thanks.
To query pages you can set the post_type to 'page':
'post_type' => 'page'

wordpress multiple pages on one page

i am developing a CMS site in wordpress ...
the final web page should some what look like :
Website
I want just one page (front page) and on that i want to display subpages titles in it. (About,Home,People)...
So when the subpage title is clicked it should expand and display the the page content in the panel,on same page and at same place.
any ideas regarding same?
Thanks in advance...:)
EDIT1
[accordions]
[accordion title="Accordion 1"]
Accordion 1 Content here
[/accordion]
[accordion title="Accordion 2"]
Accordion 2 Content here
[/accordion]
[accordion title="Accordion 3" last="last"]
Accordion 3 Content here
[/accordion]
[/accordions]
after puting the above code in the page content looks like this:
but on click of ACCORDION 1 its not getting expanded..
You can write your own template, which does a query (checks for a subpage), and adds its content between div tags.
When it's done, then it's time for JS/jQuery . Search for tab jQuery scripts, so you get some information.
Anyway, you will mostly need to use hide() / show() functions to reach something like that.
Also, did you made that template, and are you familiar with programming in WP?
<?php
$args = array(
'numberposts' => -1,
'post_parent' => $post->ID,
'post_type' => 'page',
'post_status' => 'publish',
'orderby' => 'menu_order,title',
'order' => 'ASC'
);
$my_pagelist = get_children($args);
?>
Above is code for displaying subpage content, below is the jQuery tutorial for tabs.
http://jqueryui.com/demos/tabs/
EDIT:
Also, check this site - http://www.learningjquery.com/2006/09/slicker-show-and-hide it will show you some info about show/hide functions. Also more information about WP get_children function is found here - http://codex.wordpress.org/Function_Reference/get_children
If I understand your question correctly, in the latest version of WordPress.
Login to your admin panel.
Click on the 'Settings' tab, then the 'Reading' sub-tab.
Change the 'Front page displays' option to 'A static page'.

Categories