1

I'm trying to call a template part but I want to change a small detail every time that I call it.

Right now I'm just using:

<?php get_template_part( 'ad-banner' ); ?>

I figure there's got to be something like

<?php get_template_part( 'ad-banner', $variable='variable value' ); ?>

Does anyone have suggestions?

Topher
  • 141
  • 1
  • 2
  • 9
  • 1
    I have answered the question here before : https://stackoverflow.com/questions/31051870/wordpress-doesnt-proces-external-php-file/31052270#31052270. Sort of indirectly since get_template_part doesnt take variable params. – Musk Jul 20 '17 at 16:52

2 Answers2

1

If you use locate_template() instead of get_template_part() you can use all variables in that php file.:

$variable='variable value';
include(locate_template('ad-banner.php'));

Now you can use $variable in your ad-banner.php

reference

Dezefy
  • 2,048
  • 1
  • 14
  • 23
0
function add_video_rewrite12() {

    add_rewrite_tag("%type_bien%", '([^/]*)');
    add_rewrite_rule('^ventes/([^/]*)/?', 'index.php?post_type=page&pagename=ventes&type_bien=$matches[1]', 'top');

  }


add_action( 'init', 'add_video_rewrite12' );
Suraj Rao
  • 29,388
  • 11
  • 94
  • 103
Kishan
  • 1
  • Please don't post only code as answer, but also provide an explanation what your code does and how it solves the problem of the question. Answers with an explanation are usually more helpful and of better quality, and are more likely to attract upvotes. – Mark Rotteveel Feb 21 '21 at 08:21