WordPress.org

Ready to get started?Download WordPress

Forums

Call one category for post visualization (4 posts)

  1. Francesco Acciai
    Member
    Posted 1 year ago #

    Hi,
    the code below is in my page-home.php

    <!-- INNER content2 -->
    <div id="inner">
    
    <?php $issuesCategory = get_option('tb_home_issues_category'); ?>
    
    <h3>News dalla Regione<span></span></h3>
    
    <?php
    $args = array();
    
    $args['post_type'] = 'post';
    $args['post_status'] = 'publish';
    $args['posts_per_page'] = 5;
    if ($issuesCategory) {
    $excludeCategory = '-' . $issuesCategory;
    $args['cat'] = $excludeCategory;
    }
    
    $tbQuery = new WP_Query($args);
    $latestIndex = 1;
    
    if ($tbQuery->have_posts()) : while ($tbQuery->have_posts()) : $tbQuery->the_post();
    ?>
    
    <?php $postID = get_the_ID(); ?>
    <?php $postTitle = get_the_title($postID); ?>
    <?php $postPermalink = get_permalink($postID); ?>
    
    <?php
    if ($latestIndex == 5) {
    $newsClass = 'news width50 right';
    $dfs = 'small';
    $tSize = 'dfs';
    }
    elseif ($latestIndex == 4) {
    $newsClass = 'news width50 left';
    $dfs = 'small';
    $tSize = 'dfs';
    }
    elseif ($latestIndex == 3) {
    $newsClass = 'news width50 left';
    $dfs = 'small';
    $tSize = 'dfs';
    }
    
    elseif ($latestIndex == 2) {
    $newsClass = 'news width50 left';
    $dfs = 'small';
    $tSize = 'dfs';
    }
    
    else {
    $newsClass = 'news';
    $dfs = 'medium';
    $tSize = 'dfm';
    }
    
    ?>
    
    <div class="<?php echo $newsClass; ?>">
    <div class="doubleFramed <?php echo $dfs; ?> left">
    " title="<?php $postTitle; ?>">
    <?php echo tb_get_thumbnail($postID, $tSize); ?>
    
    </div>
    
    <div class="right">
    <?php
    if ($latestIndex > 1) { ?>
    <div class="newsInfo"><?php echo get_the_date('l j F, Y'); ?></div>
    <?php }	?>
    
    <h4>" title="<?php $postTitle; ?>"><?php echo $postTitle; ?></h4>
    
    <?php
    if ($latestIndex == 1) { ?>
    <div class="newsInfo"><?php echo get_the_date('l j F, Y'); ?></div>
    <?php }	?>
    
    <?php if ($latestIndex == 1) {
    the_excerpt();
    } else {
    echo '<p>' . tb_max_words(get_the_excerpt(), 18) . '...</p>';
    } ?>
    
    " title="<?php $postTitle; ?>" class="tinyButton roundButtonX right">Leggi tutto
    </div>
    </div>
    
    <?php
    if ($latestIndex == 1) { ?>
    <div class="horDashed"></div>
    <?php }	?>
    
    <?php $latestIndex++; ?>
    
    <?php endwhile; endif; ?>
    
    <?php wp_reset_postdata(); ?>
    
    <?php
    if ($issuesCategory) { ?>
    
    <?php
    $args2 = array();
    
    $args2['post_type'] = 'post';
    $args2['post_status'] = 'publish';
    $args2['posts_per_page'] = 3;
    $args2['cat'] = $issuesCategory;
    
    $tbQuery2 = new WP_Query($args2);
    $issuesIndex = 1;
    
    if ($tbQuery2->have_posts()) { ?>
    
    <div class="horDouble"></div>
    
    <h4><span></span></h4>
    
    <?php while ($tbQuery2->have_posts()) : $tbQuery2->the_post(); ?>
    
    <?php $postID = get_the_ID(); ?>
    <?php $postTitle = get_the_title($postID); ?>
    <?php $postPermalink = get_permalink($postID); ?>
    
    <?php if ($issuesIndex == 1) echo '<div class="news width50 left">'; ?>
    <?php if ($issuesIndex == 2) echo '</div><div class="news width50 right">'; ?>
    
    <div class="newsInfo"><?php echo get_the_date('l j F, Y'); ?></div>
    <h4>" title="<?php echo $postTitle; ?>"><?php echo $postTitle; ?></h4>
    
    <?php if ($issuesIndex == 1) {
    the_excerpt(); ?>
    " title="<?php echo $postTitle; ?>" class="tinyButton roundButtonX right">Leggi tutto
    <?php } ?>
    
    <?php if ($issuesIndex > 1 && $issuesIndex < 3) echo '<div class="horDashed"></div>'; ?>
    
    <?php if ($issuesIndex == 3) echo '</div>'; ?>
    
    <?php $issuesIndex++; ?>
    
    <?php endwhile; } ?>
    
    <?php if ($issuesIndex > 1 && $issuesIndex < 3) echo '</div>'; ?>
    
    <?php wp_reset_postdata(); ?>
    
    <?php
    }
    
    $args3 = array();
    
    $args3['post_type'] = 'tb_video';
    $args3['post_status'] = 'publish';
    $args3['posts_per_page'] = 1;
    
    $args3['meta_query'] = array(
    array(
    'key'	 => '_featured',
    'value'	 => 1,
    'compare'	=> '='
    )
    );
    
    $tbQuery3 = new WP_Query($args3);
    
    ?>
    
    <?php if ($tbQuery3->have_posts()) : while ($tbQuery3->have_posts()) : $tbQuery3->the_post(); ?>
    
    <?php $postID = get_the_ID(); $postTitle = get_the_title(); ?>
    <?php $postURL = get_post_meta($postID, '_url', true); ?>
    
    <div class="horDouble"></div>
    
    <h4>Featured <span>Videos</span></h4>
    
    <div class="video">
    <div>
    " title="<?php echo $postTitle; ?>">
    <?php echo get_the_post_thumbnail($postID, 'videoHome', array('alt' => $postTitle, 'title' => $postTitle)); ?>
    
    </div>
    
    <div>
    <h4>"><?php echo $postTitle; ?></h4>
    <div class="newsInfo"><?php echo get_the_date('l j F, Y'); ?></div>
    
    <div class="horDashed"></div>
    
    <?php echo '<p>' . tb_max_words(get_the_excerpt(), 40) . '...</p>'; ?>
    </div>
    </div>
    
    <?php endwhile; endif; ?>
    
    <?php wp_reset_postdata(); ?>
    
    </div>
    <!-- .INNER content2 -->

    This code generate two blocks of article. In the first block there are the articles of all the categories exception for the category of the second article block.

    I wanna change this method to put an explicit category for each block on this php code.

    Can anyone help me?

    thanks
    Francesco

  2. esmi
    Forum Moderator
    Posted 1 year ago #

    What theme is this? It's using its own custom functions in some places.

  3. Francesco Acciai
    Member
    Posted 1 year ago #

    This is the theme:
    http://themeforest.net/item/candidate-political-wordpress-theme/2909293

    if you need some files to check it I'll give you.

  4. esmi
    Forum Moderator
    Posted 1 year ago #

    I'm sorry but as you are using a commercial theme, you need to seek support from the theme's vendors.
    http://themeforest.net/user/themeblossom

Topic Closed

This topic has been closed to new replies.

About this Topic