• Folks,

    I want to put the current post’s title in a variable and i want to call this variable in the sidebar.

    I tries using:

    $post_title_test = post_title();

    but it does not work.

    Another thing, if i define a variable in Single.php, to call this variabel in Sidebar, do i have to define it as Gobal variable like:

    global $post_title_test;

    If not then How?

    Thanks all

Viewing 4 replies - 1 through 4 (of 4 total)
  • http://codex.wordpress.org/Template_Tags/get_the_title

    if called in the loop, it will get the title of the cuurent post

    $post_title_test = get_the_title();

    seems to need the global – in sidebar:
    global $post_title_test; echo $post_title_test;

    Thread Starter soulgeek

    (@soulgeek)

    Many Thanks Brother!!!

    I’m trying to get information from a data table that I have inside my WP database onto a page. I use this on other sites, but I’m not getting it to work on this one. The datatable/database query works on another file, and I obviously swapped out the actual names.

    In this case, page titles are names of basketball players. I’m getting the following error:

    Fatal error: Call to undefined function get_the_title() in /home/jwrbloom/public_html/spieceselect.org/resources/2011/profile.php on line 3

    Here is the code:

    <?php
    
    $playerName = get_the_title($post->post_title );  
    
    $con = mysql_connect("localhost","username","pa$$word");
    
     mysql_select_db("name-of-database", $con);	
    
    $query = 'SELECT * FROM team2011 ORDER BY uniform ASC';
    $results = mysql_query($query);
    
    while($line = mysql_fetch_assoc($results)) {
    
    	if ($playerName == $line['nameFirst'].'-'.$line['nameLast']) {
    
    	echo '<div>' . $line['nameFirst'].' '.$line['nameLast'] . '</div>';
    
    	}
    }
    ?>

    Keep in mind, the echo is just a test output.

    🙂

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘how to put Post title in a variable and call in Sidebar?’ is closed to new replies.