PHP hulp gezocht voor php code om (wordpress) shortcode aan te roepen
Maak voor mijn hobby websites, maak ze nu vooral in Joomla.
Ik ben bezig met een WP website voor een vriendin. dit is mijn 2e WP website die ik maak.
Ik heb een woocommerce (wp plugin) winkelmandje toegevoegd en op de homepage (met veel moeite) met behulp van php (en google) een section "beste verkochte producten" toegevoegd
eiegenlijk wil ik gewoon een wp shortcode ([products limit="6" columns="3" best_selling="true"]) via php toevoegen aan de pagina maar dit kreeg ik niet voor elkaar.
maar als ik de homepage op mijn mobiel bekijk staan die producten niet netjes onder elkaar zoals ik graag zou willen.
Hebben jullie een goede tip waardoor ik dit voor elkaar kan krijgen?
hier is mijn code (Waarschuwing:is dus beetje knutsel werk;-)
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?php
/**
* Courses Section
*
* @package Rara Academic Pro
*/
$section_title = get_theme_mod( 'rara_academic_courses_section_title' );
$section_content = get_theme_mod( 'rara_academic_courses_section_description' );
$post_one = get_theme_mod( 'popular_course_course_one' );
$post_two = get_theme_mod( 'popular_course_course_two' );
$post_three = get_theme_mod( 'popular_course_course_three' );
$post_four = get_theme_mod( 'popular_course_course_four' );
$post_five = get_theme_mod( 'popular_course_course_five' );
$post_six = get_theme_mod( 'popular_course_course_six' );
$view_all = get_theme_mod( 'courses_viewall_label', __( 'View All Courses', 'rara-academic-pro' ) );
$link = get_theme_mod( 'courses_viewall_link' );
$course_posts = array( $post_one, $post_two, $post_three, $post_four, $post_five, $post_six );
$course_posts = array_diff( array_unique( $course_posts ), array('') );
if( $section_title || $section_content || $course_posts ){
?>
<section id="courses-section" class="popular-courses">
<div class="container">
<?php
if( $section_title ) echo '<h2 class="section-title">' . esc_html( $section_title ) . '</h2>';
?>
<article >
<a href="<?php the_permalink(); ?>" class="post-thumbnail">
<?php
if ( ! function_exists( 'wc_get_products' ) ) {
return;
}
echo '<div class="woocommerce">'; // needed for default styles
$top_selling_products = wc_get_products( array(
'meta_key' => 'total_sales', // our custom query meta_key
'return' => 'ids', // needed to pass to $post_object
'orderby' => array( 'meta_value_num' => 'DESC', 'title' => 'ASC' ), // order from highest to lowest of top sellers
) );
if ( $top_selling_products ) {
do_action( 'woocommerce_before_shop_loop' );
woocommerce_product_loop_start();
foreach ( $top_selling_products as $top_selling_product ) {
$post_object = get_post( $top_selling_product );
setup_postdata( $GLOBALS['post'] =& $post_object );
do_action( 'woocommerce_shop_loop' );
wc_get_template_part( 'content', 'product' );
}
wp_reset_postdata();
woocommerce_product_loop_end();
do_action( 'woocommerce_after_shop_loop' );
} else {
do_action( 'woocommerce_no_products_found' );
}
echo '</div><!-- .woocommerce -->';
do_action( 'woocommerce_after_main_content' );
do_action( 'woocommerce_sidebar' );
?>
<div class="btn-holder"><a href="https://rarathemesdemo.com/rara-academic-pro/courses/" class="btn">Bekijk alle trainingen</a></div>
</div>
</a>
<header class="entry-header">
</a>
</h3>
</header>
<div class="entry-content">
</div>
</article>
</div>
<?php
}
wp_reset_postdata(); ?>
</div>
<?php
?>
</div>
</section>
<?php
[/code]
/**
* Courses Section
*
* @package Rara Academic Pro
*/
$section_title = get_theme_mod( 'rara_academic_courses_section_title' );
$section_content = get_theme_mod( 'rara_academic_courses_section_description' );
$post_one = get_theme_mod( 'popular_course_course_one' );
$post_two = get_theme_mod( 'popular_course_course_two' );
$post_three = get_theme_mod( 'popular_course_course_three' );
$post_four = get_theme_mod( 'popular_course_course_four' );
$post_five = get_theme_mod( 'popular_course_course_five' );
$post_six = get_theme_mod( 'popular_course_course_six' );
$view_all = get_theme_mod( 'courses_viewall_label', __( 'View All Courses', 'rara-academic-pro' ) );
$link = get_theme_mod( 'courses_viewall_link' );
$course_posts = array( $post_one, $post_two, $post_three, $post_four, $post_five, $post_six );
$course_posts = array_diff( array_unique( $course_posts ), array('') );
if( $section_title || $section_content || $course_posts ){
?>
<section id="courses-section" class="popular-courses">
<div class="container">
<?php
if( $section_title ) echo '<h2 class="section-title">' . esc_html( $section_title ) . '</h2>';
?>
<article >
<a href="<?php the_permalink(); ?>" class="post-thumbnail">
<?php
if ( ! function_exists( 'wc_get_products' ) ) {
return;
}
echo '<div class="woocommerce">'; // needed for default styles
$top_selling_products = wc_get_products( array(
'meta_key' => 'total_sales', // our custom query meta_key
'return' => 'ids', // needed to pass to $post_object
'orderby' => array( 'meta_value_num' => 'DESC', 'title' => 'ASC' ), // order from highest to lowest of top sellers
) );
if ( $top_selling_products ) {
do_action( 'woocommerce_before_shop_loop' );
woocommerce_product_loop_start();
foreach ( $top_selling_products as $top_selling_product ) {
$post_object = get_post( $top_selling_product );
setup_postdata( $GLOBALS['post'] =& $post_object );
do_action( 'woocommerce_shop_loop' );
wc_get_template_part( 'content', 'product' );
}
wp_reset_postdata();
woocommerce_product_loop_end();
do_action( 'woocommerce_after_shop_loop' );
} else {
do_action( 'woocommerce_no_products_found' );
}
echo '</div><!-- .woocommerce -->';
do_action( 'woocommerce_after_main_content' );
do_action( 'woocommerce_sidebar' );
?>
<div class="btn-holder"><a href="https://rarathemesdemo.com/rara-academic-pro/courses/" class="btn">Bekijk alle trainingen</a></div>
</div>
</a>
<header class="entry-header">
</a>
</h3>
</header>
<div class="entry-content">
</div>
</article>
</div>
<?php
}
wp_reset_postdata(); ?>
</div>
<?php
?>
</div>
</section>
<?php
[/code]
Gewijzigd op 09/08/2020 13:52:42 door Patricia Wijk
Welkom op PHPhulp.
Zou je graag even een nieuwe topictitel willen bedenken die jouw probleem en of vraagstelling aangeeft? Ook kan je jouw code tussen [code] en [/code] plaatsen voor betere leesbaarheid.
Alvast bedankt!
Toevoeging op 09/08/2020 13:24:14:
Hoe ziet het er nu dan uit? Kan je een link delen? Misschien kan je eens kijken naar de 'flexbox' in CSS. Die is erg krachtig voor wat je wilt.
Gewijzigd op 09/08/2020 13:25:29 door - Ariën -
Gewijzigd op 09/08/2020 15:16:56 door Patricia Wijk
Alvast bedankt!