在 SEO 的页脚中显示带有标题的所有 woocommerce 产品点赞 - Wordpress PHP
Displaying all woocommerce product liks with title in Footer for SEO - Wordpress PHP
我想在链接顶部显示所有带有 woocommerce 标题链接的 woocommerce 产品,这有助于我的 SEO。我设法在下面找到了一些获取产品类别的代码,但似乎无法获取代码来显示链接上带有标题的所有产品。
如果有人知道任何可以帮助我的代码,我将非常感谢获得所有带有链接和标题的产品! p.s如果有比我用过的更好的获取数据的方法,请告诉我!
<?php
$taxonomy = 'product_cat';
$orderby = 'name';
$show_count = 0; // 1 for yes, 0 for no
$pad_counts = 0; // 1 for yes, 0 for no
$hierarchical = 1; // 1 for yes, 0 for no
$title = '';
$empty = 0;
$args = array(
'taxonomy' => $taxonomy,
'orderby' => $orderby,
'show_count' => $show_count,
'pad_counts' => $pad_counts,
'hierarchical' => $hierarchical,
'title_li' => $title,
'hide_empty' => $empty
);
?>
<?php $all_categories = get_categories( $args );
//print_r($all_categories);
foreach ($all_categories as $cat) {
//print_r($cat);
if($cat->category_parent == 0) {
$category_id = $cat->term_id;
?>
<?php
echo '<a href="'. get_term_link($cat->slug, 'product_cat') .'">' . $cat->name .'</a>'; ?> |
<?php }
}
?>
这是你想要的吗?
//you can remove post_status=>publish if you want unpublished product also
$loop = new WP_Query( array( 'post_type' => 'product','post_status' => 'publish', 'posts_per_page' => '-1' ) );
while ( $loop->have_posts() ) : $loop->the_post();
echo "<a href='".get_post_permalink()."'>".$loop->post->post_title."</a><br>";
endwhile;
已编辑
像这样更改查询:
$loop = new WP_Query( array( 'post_type' => 'product','post_status' => 'publish', 'posts_per_page' => '-1', 'orderby' => 'title', 'order' => 'ASC' ) );
我想在链接顶部显示所有带有 woocommerce 标题链接的 woocommerce 产品,这有助于我的 SEO。我设法在下面找到了一些获取产品类别的代码,但似乎无法获取代码来显示链接上带有标题的所有产品。
如果有人知道任何可以帮助我的代码,我将非常感谢获得所有带有链接和标题的产品! p.s如果有比我用过的更好的获取数据的方法,请告诉我!
<?php
$taxonomy = 'product_cat';
$orderby = 'name';
$show_count = 0; // 1 for yes, 0 for no
$pad_counts = 0; // 1 for yes, 0 for no
$hierarchical = 1; // 1 for yes, 0 for no
$title = '';
$empty = 0;
$args = array(
'taxonomy' => $taxonomy,
'orderby' => $orderby,
'show_count' => $show_count,
'pad_counts' => $pad_counts,
'hierarchical' => $hierarchical,
'title_li' => $title,
'hide_empty' => $empty
);
?>
<?php $all_categories = get_categories( $args );
//print_r($all_categories);
foreach ($all_categories as $cat) {
//print_r($cat);
if($cat->category_parent == 0) {
$category_id = $cat->term_id;
?>
<?php
echo '<a href="'. get_term_link($cat->slug, 'product_cat') .'">' . $cat->name .'</a>'; ?> |
<?php }
}
?>
这是你想要的吗?
//you can remove post_status=>publish if you want unpublished product also
$loop = new WP_Query( array( 'post_type' => 'product','post_status' => 'publish', 'posts_per_page' => '-1' ) );
while ( $loop->have_posts() ) : $loop->the_post();
echo "<a href='".get_post_permalink()."'>".$loop->post->post_title."</a><br>";
endwhile;
已编辑
像这样更改查询:
$loop = new WP_Query( array( 'post_type' => 'product','post_status' => 'publish', 'posts_per_page' => '-1', 'orderby' => 'title', 'order' => 'ASC' ) );