Jump to content

Recommended Posts

Hi All,

Im new here and not much of a coder so I am hoping someone can help me figure out a simple problem. I have a wordpress site that I want to control what category shows up on the front page. The theme is custom so standard wordpress code is not being used. The code that I think controls this is:

<?php if (Themehave_random_posts()) : ?>
		<?php while (Themehave_random_posts()) : $theme_queryRandom->the_post();
			if(!@in_array(get_the_ID(), $showedPosts)){?>

 

In the functions.php I have this code:

function Themehave_random_posts(){
global $wp_query, $shortname, $theme_queryRandom, $wpdb, $cx, $showedPosts, $ids;
if(!$theme_queryRandom){
$show = (int)get_settings($shortname."_randomCategoryPosts");
if(!in_array($show, $ids))
$ids[] = $show;
$theme_queryRandom = new WP_Query('category_name='.get_cat_name($show).'&orderby=rand&showposts=1');
}
$aux = $theme_queryRandom->have_posts();
if(get_the_ID())
$showedPosts[] = get_the_ID();
return $aux;
}

 

 

Any help is greatly appreciated. Thanks !

Link to comment
https://forums.phpfreaks.com/topic/146122-coding-question-in-wordpress/
Share on other sites

  • 2 weeks later...

no... it's not necessarily complicated, but it's not so easy either. at least it is for me, because i haven't use wordpress.

 

i don't know how this works entirely, but you should try this:

 

function Themehave_random_posts(){
global $wp_query, $shortname, $theme_queryRandom, $wpdb, $cx, $showedPosts, $ids;
if(!$theme_queryRandom){
$show = (int)get_settings($shortname."_randomCategoryPosts");
if(!in_array($show, $ids))
$ids[] = $show;
$catiwant = 'my category'; // put your category in the apostraphies...
$theme_queryRandom = new WP_Query('category_name='.$catiwant.'&orderby=rand&showposts=1');
}
$aux = $theme_queryRandom->have_posts();
if(get_the_ID())
$showedPosts[] = get_the_ID();
return $aux;
}

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.