如何在WordPress主题中将按钮重定向到特定模板ONCLICK?

发布于 2025-01-20 18:05:12 字数 561 浏览 4 评论 0原文

所以我在 php 中有这段代码:

add_filter( 'template_include', 'my_callback' );


function my_callback( $original_template ) {
  if ( some_condition() ) {
    return SOME_PATH . '/some-custom-file.php';
  } else {
    return $original_template;
  }
}

并且我想重写这段代码,以便在 元素中使用它,特别是在 onclick="" 元素的属性。总而言之,我的主要目标是在主题文件夹中创建 2 个模板文件,其中一个用于最近的帖子,另一个用于最流行的帖子,并使用上面的代码,但在 < /code> 元素能够分别重定向到每个元素。

有什么建议吗?预先感谢,
贾梅乌

So I have this code in php:

add_filter( 'template_include', 'my_callback' );


function my_callback( $original_template ) {
  if ( some_condition() ) {
    return SOME_PATH . '/some-custom-file.php';
  } else {
    return $original_template;
  }
}

and I want to re-write this code in order to use it inside an <a> element and specifically in an onclick="" attribute of that <a> element. All in all my main goal is to create 2 template files in my theme's folder where one is for most recent posts and the other is for the most popupal posts, and the use the code above but inside the <a> element to be able to redirect to each one respectively.

Any suggestions? Thanks in advance,
Jameu

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

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

发布评论

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

评论(1

み青杉依旧 2025-01-27 18:05:12

创建两个WordPress本机页面(在WP后端内部),使用每个图模板(创建)。
这是模板页面文档:

“ nofollow noreferrer”>模板文件

完成此操作后,只需将它们与常规html链接:&lt; a href =“/page1”&gt; link page1&lt;/a&gt;或(如果需要)

Create two wordpress native pages (inside WP Backend), use the template you want (create it) with each one.
Here is the template pages doc:

TEMPLATE FILES

Once you have done it just link them with regular html: <a href="/page1">LINK PAGE1</a> or with javascript if you want

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