• Strangely, the page2cat author embedded all the markup that the plugin outputs directly in the plugin, and I can’t find a way to get into contact with him/her to share how to fix this, so here it is in the hopes other users can find it useful.

    This is the basic code snippet that will load a template named page2cat.php and use it to create the output of the page2cat_output() function:

    if (get_query_template('page2cat') != '') {
        load_template(get_query_template('page2cat'));
    }

    To add this to your copy of the plugin, update one of the switch cases in the page2cat_output function in the page2cat.php plugin file. For instance, if you wanted to have this used by default you could replace the ‘getpost’ case in the function (starts line 749) with this:

    case 'getpost':
    ?>
    <div id="category-page-header">
    <?php
    $post = $post_temp;
    $post = get_post($pageid);
    setup_postdata($post);
    
    if($post->post_title!=""){
        if (get_query_template('page2cat') != '') {
            load_template(get_query_template('page2cat'));
        } else {
                ?>
                <div id="p2c-header">
                    <h1><?php echo $post->post_title; ?></h1>
                    <?php the_content(); ?>
                </div>
            <div class="category-page-cleaner"></div>
    <?php
        }
    echo '</div>';
    $post = $post_temp;
    }
    break;

    An example template that would work would be a page in your theme called page2cat.php with the following contents:

    <div id="p2c-header">
        <h1><?php the_title(); ?></h1>
        <?php the_content(); ?>
    </div>

    Hopefully this helps others; I’d love to see all of the markup in the plugin removed and replaced with optional templates, but I can’t find any good way to contact the developer.

    https://www.ads-software.com/extend/plugins/page2cat/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter One Crayon

    (@beckism)

    Further testing has revealed a couple limitations of the original code posted above, and this damn forum doesn’t let me edit posts, so here’s the corrections:

    General snippet:

    if (get_query_template('page2cat') != '') {
        include(get_query_template('page2cat'));
    }

    Plugin page2cat.php file:

    case 'getpost':
    ?>
    <div id="category-page-header">
    <?php
    $post = $post_temp;
    $post = get_post($pageid);
    setup_postdata($post);
    
    if($post->post_title!=""){
        if (get_query_template('page2cat') != '') {
            include(get_query_template('page2cat'));
        } else {
                ?>
                <div id="p2c-header">
                    <h1><?php echo $post->post_title; ?></h1>
                    <?php the_content(); ?>
                </div>
            <div class="category-page-cleaner"></div>
    <?php
        }
    echo '</div>';
    $post = $post_temp;
    }
    break;

    Theme page2cat.php file:

    <div id="p2c-header">
        <h1><?php echo $post->post_title; ?></h1>
        <?php the_content(); ?>
    </div>

    I think what you’ve done here is what I did here, but your code is much shorter. Although the way I re-wrote it, it gives the user the option to output the content via the admin panel.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to: Customizing page2cat markup via a template’ is closed to new replies.