如何从静态页面链接到帖子?

发布于 2025-01-25 10:14:39 字数 118 浏览 2 评论 0原文

我正在开发WordPress主题,我想知道...

如何从静态页面链接到单个博客文章?

我的想法是拥有一个主页(静态),我以特定方式显示文章的卡片,并带有幻灯片,网格等...

谢谢。

I am developing a wordpress theme and I was wondering...

How can I link to a single blog post from a static page?

My idea is to have a home page (static) where I display the cards of the articles in specific ways with slides, grids, etc...

thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

五里雾 2025-02-01 10:14:39

您可以尝试此

//将此代码放在function.php

 add_shortcode('custom_post', 'grid_post')
 
 function grid_post(){
   $args = array(  
        'post_type' => 'posts',
        'post_status' => 'publish',
        'posts_per_page' => 8, 
    );

    $loop = new WP_Query( $args ); 
        
    while ( $loop->have_posts() ) : $loop->the_post(); 
          ?>
            <a href='<?php the_permalink() ?>'><?php the_title() ?></a>
        <?php
    endwhile;

    wp_reset_postdata(); 
}

,然后将此代码放在要显示的位置

echo do_shortcode(['custom_post'])

You can try this

// put this code on function.php

 add_shortcode('custom_post', 'grid_post')
 
 function grid_post(){
   $args = array(  
        'post_type' => 'posts',
        'post_status' => 'publish',
        'posts_per_page' => 8, 
    );

    $loop = new WP_Query( $args ); 
        
    while ( $loop->have_posts() ) : $loop->the_post(); 
          ?>
            <a href='<?php the_permalink() ?>'><?php the_title() ?></a>
        <?php
    endwhile;

    wp_reset_postdata(); 
}

then put this code where you want to show

echo do_shortcode(['custom_post'])
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文