WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Adding shortcode each time php loops (3 posts)

  1. DA2206
    Member
    Posted 1 year ago #

    Hi,

    I am currently trying to display a shortcode box each time a php loop runs. This box will contain various images and text selected by the query.

    Extremely new to WP and looking for some advice.

    Current code:

    [php]
    $imageQuery = "SELECT * FROM X WHERE City LIKE 'City' ORDER BY CityCode";
    $result = mysql_query($imageQuery) or die(mysql_error());
    
    while( $row=mysql_fetch_row($result) )
    {
    echo do_shortcode[styledbox type="general shaded"  ].$row[1].[/styledbox];
    
    }
    [/php]

    Essentially a query that i am looking to create a new box each time it runs, with field information displayed relating to the row the loop is on, forming a list of boxes.

    Any help much appreciated,

    Many thanks

  2. alchymyth
    The Sweeper & Moderator
    Posted 1 year ago #

    please check the syntax of do_shortcode()

    http://codex.wordpress.org/Function_Reference/do_shortcode

    for example, try:

    echo do_shortcode('[styledbox type="general shaded"  ]'.$row[1].'[/styledbox]');
  3. DA2206
    Member
    Posted 1 year ago #

    Works perfectly, thank you for your help.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags